Slime Squisher
Posts: 344
Joined: Tuesday, 14th April 2015, 19:56
Location: France
Auto use staff of energy
4 runes : DDFi^Makhleb
5 runes : GrEE^Vehumet
15 runes : MiFi^Ru, NaWz^Sif Muna, GrWz^Sif Muna
I mostly play offline or online on CXC
Ask fellow adventurers how to stay alive in the deep, dark, dangerous dungeon below, or share your own accumulated wisdom.
Slime Squisher
Posts: 344
Joined: Tuesday, 14th April 2015, 19:56
Location: France
Slime Squisher
Posts: 368
Joined: Thursday, 11th April 2013, 21:07
Fingolfin wrote:I don't know how to execute a function whenever I press 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.
#####################################
# 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
}
Slime Squisher
Posts: 344
Joined: Tuesday, 14th April 2015, 19:56
Location: France
#####################################
# 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 then
if m:attitude() > ATT_NEUTRAL then -- the error triggers at this line
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
end
return false
end
function auto_channel()
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
local mp, mmp = you.mp()
if safe_los then
if mp < mmp then
-- put your staff activation Lua here
crawl.process_keys("v" .. string.char(27) .. string.char(27) .. string.char(27))
end
end
end
}
Slime Squisher
Posts: 368
Joined: Thursday, 11th April 2013, 21:07
#####################################
# enum values :/
: ATT_FRIENDLY = 4
: ATT_NEUTRAL = 1
: ATT_HOSTILE = 0
: LOS = 7
: if you.race() == "Barachi" then
: LOS = 8
: end
#####################################
{
-- just a few outs for nondamaging things
-- proper threat assessment is a topic for a whole bot
function is_threatening(m)
if m then
if m:attitude() > ATT_NEUTRAL then -- the error triggers at this line
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
return true
end
end
function auto_channel()
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
local mp, mmp = you.mp()
if safe_los then
if mp < mmp then
-- put your staff activation Lua here
crawl.process_keys("v" .. string.char(27) .. string.char(27) .. string.char(27))
end
end
end
}
Slime Squisher
Posts: 344
Joined: Tuesday, 14th April 2015, 19:56
Location: France
Implojin wrote:Yup, in my lazy copy-pasting I removed a bunch of extraneous stuff from my local ini, one of them was the attitude enums [oops!] which are necessary for the m:attitude() comparison. (Crawl's ATT_HOSTILE etc. enums aren't available from within its cLua binds so you have to define them yourself...)
Here's a slightly more cleaned up version that should work, I've also fixed up that threat function a bit since what I had originally pasted there would have gotten your character killed sooner or later.
- Code:
#####################################
# enum values :/
: ATT_FRIENDLY = 4
: ATT_NEUTRAL = 1
: ATT_HOSTILE = 0
: LOS = 7
: if you.race() == "Barachi" then
: LOS = 8
: end
#####################################
{
-- just a few outs for nondamaging things
-- proper threat assessment is a topic for a whole bot
function is_threatening(m)
if m then
if m:attitude() > ATT_NEUTRAL then -- the error triggers at this line
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
return true
end
end
function auto_channel()
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
local mp, mmp = you.mp()
if safe_los then
if mp < mmp then
-- put your staff activation Lua here
crawl.process_keys("v" .. string.char(27) .. string.char(27) .. string.char(27))
end
end
end
}
#####################################
# enum values :/
: ATT_FRIENDLY = 4
: ATT_NEUTRAL = 1
: ATT_HOSTILE = 0
: LOS = 7
: if you.race() == "Barachi" then
: LOS = 8
: end
#####################################
{
-- just a few outs for nondamaging things
-- proper threat assessment is a topic for a whole bot
function is_threatening(m)
if m then
if m:attitude() > ATT_NEUTRAL then -- the error triggers at this line
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
return true
end
end
function check_los()
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
return safe_los
end
function auto_channel()
local safe_los = check_los()
local mp, mmp = you.mp()
while mp < mmp and safe_los do
crawl.process_keys("v")
crawl.flush_input()
crawl.more_autoclear(true)
mp, mmp = you.mp()
safe_los = check_los()
end
end
}
Slime Squisher
Posts: 368
Joined: Thursday, 11th April 2013, 21:07
Fingolfin wrote:crawl.process_keys() doesn't seem to tell the game to end the turn so I am probably missing a single instruction to pass on to the next turn but I can't seem to find it. I tried searching in l-crawl.cc but with no result. Otherwise it should work.
Slime Squisher
Posts: 344
Joined: Tuesday, 14th April 2015, 19:56
Location: France
Implojin wrote:There's a clua hook in the input handler that you can use to run custom Lua each time a player turn becomes available, function ready() .
If that function exists in your rcfile, it will be called once per turn, prior to checking for any manual player input.
Rewrite your logic a little bit to use that and make your macro a state toggle and it should probably work.
#####################################
# enum values :/
: ATT_FRIENDLY = 4
: ATT_NEUTRAL = 1
: ATT_HOSTILE = 0
: LOS = 7
: if you.race() == "Barachi" then
: LOS = 8
: end
#####################################
{
-- just a few outs for nondamaging things
-- proper threat assessment is a topic for a whole bot
function is_threatening(m)
if m then
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
return true
end
end
function check_los()
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
return safe_los
end
local auto_channel = false
function ready()
if auto_channel then
local safe_los = check_los()
local weap = items.equipped_at("Weapon")
local is_wielding_energy_staff = false
if weap then
is_wielding_energy_staff = weap.name():find("staff of energy")
end
local safe_player_square = view.is_safe_square(0,0) and view.cloud_at(0,0) == nil
local mp, mmp = you.mp()
if mp < mmp and safe_los and safe_player_square and is_wielding_energy_staff then
crawl.process_keys("v")
crawl.flush_input()
crawl.more_autoclear(true)
else
auto_channel = false
end
end
end
function launch_auto_channel()
auto_channel = true
end
}
Return to Dungeon Crawling Advice
Users browsing this forum: No registered users and 41 guests