Thanks. The book was a tremendous help, and I bookmarked it for later reference.
Here's what I got so far. I haven't made the triggers that change the global variables and I've already encountered a problem. I'm not sure how to implement the wait function.
--- Coded by Eloni --!>
---AlmostLua v1.0 --!>
require "wait"
--- VARIABLES ---!>
ready = false --(determined by health/mana/movement trigger, how to link the trigger to this script?)
fighting = false --(determined by multiple triggers that all indicate you're in combat)
currentPath = "none"
currentPathLocation = 1
recallWasSucessful = true --(determined by the string that displays when the spell is sucessful)
--- END VARIABLES ---!>
--- ARRAYS ---!>
--- paths ---!>
gardenPath = { "n", "w", "n", "down", "open door", "e" }
cityPath = { "w", "w", "w", "w", "n", "n" }
dungeonPath = { "s", "s", "open door", "down", "down", "s" }
listOfPaths = { gardenPath, cityPath, dungeonPath, }
--- end paths ---!>
basicCombat = { "kick", "b_bs", "cast fireball", "cast slow" }
--- END ARRAYS ---!>
--- METHODS ---!>
function pickRandomPath () --Picks a random area to go to when the method is called and sets it to currentPath
currentPath = listOfPaths[rand(3)]
print ("Current destination: " + currentPath)
end -- pickRandomPath
function moveOnPath ()
send "currentPath[currentPathLocation]"
currentPathLocation = currentPathLocation + 1
end -- moveOnPath
--Selects a random attack from the array when the method is called
function basicCombatEngine ()
-- (commented this out because I don't know the random function for lua)
send "cry" -- basicCombat[rand(4)]
end -- combatEngine
--Makes you sleep when the loop deems it necessary,
--and resets the path to "none" so you're not walking around while you sleep
function regen ()
currentPath = "none"
Send ("sleep")
require "wait"
--wait function doesn't fire at all (instintaneously prints both "sleep" and "wake"
--pretty sure it's implemented wrong
wait.make (function ()
wait.time(180)
end)
Send ("wake")
ready = true
end -- regen
function sleepTimer() --tried using this in regen(), didn't work
wait.make (function ()
wait.time(180)
end)
end
---large if/else loop that determines your actions based on ready == true, and other variables ---!>
--somehow set it on a timer that's short enough not to get my character killed, and long enough so that
--it can attack mobs it sees in the room (with a trigger)?
--will the "wait" function PAUSE THE ENTIRE SCRIPT and
--keep the timer from checking to see if I need to escape from combat?
--ready = false(low hp and mana) and fighting = true,
--so need to get out of combat quick & reset the bot
if ready == false and fighting == true and recallWasSucessful == false then
send "flee"
send "cast recall"
--need to regen, not fighting, so: go back to start & regen
elseif ready == false and fighting == false and recallWasSucessful == true then
--also sets currentPath to none, so the loop can continue after the "wait" is over
regen()
--if hp and mana are up, not fighting, and not on a path
elseif ready == true and fighting == false and currentPath == "none" then
pickRandomPath()
currentPathLocation = 1
--if hp and mana are up, not fighting, and ON A PATH
elseif ready == true and fighting == false and currentPath ~= "none" then
moveOnPath()
elseif ready == true and fighting == true then
basicCombatEngine()
end
--- END METHODS ---!>
The code compiles error free, but there is no pause between sleeping and resting.
I think a wait function is ideal in the regen() function, but I can't tell until I test it. I might be wrong, but: It bothers me that the bot could get attacked while sleeping, and it wouldn't be able to respond because the 'wait' function has paused the script.
Maybe a timer that runs separately from the 'waited' code that constantly checks to see if fighting = true, and if so 'unwaits' the code... somehow. I haven't experimented with timers yet, so I'm not sure how they work, but I assume they're ran from the mud, and not from inside the lua script.
Are there help files for the wait function? All I have are examples from this post:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4956&page=1 |