Preliminary disclaimer: I am working from memory and lazily ripped code snippets from my local Stone Soup directory. In addition to adding the Lua to activate your staff, you may also need to slightly modify what I have written below to get it working.
Reference
elliptic's qw.rc for implementation details. Here's a link to an old post that covers general rcfile Lua info:
viewtopic.php?p=313397#p313397Fingolfin wrote:I don't know how to execute a function whenever I press 5,
To do this, you will need to create an Lua function yourfunctionname() in your .rcfile or init.txt, then bind that function to a macro (either in-game or by editing macro.txt) by creating and saving a macro that executes ===yourfunctionname . In this case, you'd want to bind it to 5.
Fingolfin wrote:how to check that the situation is safe in lua. I'd like to know ... if someone could give me some pointers on how to do it with lua.
To do this, you'll need to write the necessary Lua to check your line of sight for threats and add it to your .rcfile or init.txt. Here is some skeleton Lua you can adapt, originally adapted from the ttt() function in qw.rc:
- Code:
#####################################
# enum values :/
: LOS = 7
: if you.race() == "Barachi" then
: LOS = 8
: end
#####################################
{
-- simple checks for a few easy and probably-dangerous things
-- proper threat assessment is a topic for a whole bot
function is_threatening(m)
if m:attitude() > ATT_NEUTRAL then
return false
end
if m:is_firewood() then
if not string.find(m:name(), "ballistomycete") then
return false
end
end
if m:name() == "butterfly" then
return false
end
if m:threat() > 1 then
return true
end
if string.find(m:speed_description(), "fast") then
return true
end
if m:is_unique() then
return true
end
if string.find(m:name(), "'s ghost") or string.find(m:name(), "' ghost") then
return true
end
return false
end
function not_quite_ttt()
local safe_los = true
for i = -LOS,LOS do
for j = -LOS,LOS do
m = monster.get_monster_at(i,j)
-- if m then
if m and is_threatening(m) then -- comment this out and uncomment above if you want to fire on every monster to come into view; this will include things like plants
safe_los = false
end
end
end
if safe_los then
-- put your staff activation Lua here
end
end
}
My code here is probably shit, so just assume that if my sample code is broken then it's my fault and there's a working version of the same thing you can adapt to accomplish what you want in qw.rc.
I hope you get this working, good luck.