eammonwright
New Coder
Hello everyone. I'm new here and very new to Lua. I have been learning it by making small scripts for a mud that I play. I am trying to take the next step in my learning by combining a few scripts together to make a functional bot. I dont care about the cheating aspect of it as I wont be running it. But gaming is the easiest way for me to learn new languages. Is this the right place to get help for something like that?
[CODE title="Main Loop"]require "wait"
wait.make (function () --- coroutine below here
time_to_stop = false -- make true elsewhere to make the loop stop
local ArrayBeach = ArrayBeach = {w,w,w,w,w,n,e,e,e,e,e,n,w,w,w,w,w,n,e,e,e,e,e,n,w,w,w,w,w,n,e,e,e,e,e,s,s,s,s,s,s,s} -- and so on
local current_pos = 1 -- start at start of array
repeat
local direction = ArrayBeach [current_pos] -- get direction
-- next item in array for next time around loop
current_pos = current_pos + 1
-- wrap at end of array
if current_pos > #ArrayBeach then
current_pos = 1
end
Send (direction) -- go that way
-- ---------------------------------------------
-- Wait for room change (wait.match)
-- Find your HP etc. (wait.match)
-- Find what monsters are here (wait.match)
-- Decide to attack or not (Send "attack")
-- ---------------------------------------------
wait.time (5) -- allow 5 seconds before looping
until time_to_stop
end) -- end of coroutine[/CODE]
This is the array and what I am trying to accomplish. I have it laid out of what I want to do, and have the array set up. The mobs on the beach are Lobsters, Crabs, and Gulls. I have the following script written to check stats and attack when I see them.
[CODE title="Combat Script"]require "wait"
wait.make (function ()
Send("hp")
local line, wildcards = wait.match("* HP [ */* ] SP [ */* ] EP [ */* ]")
if tonumber(wildcards[2]) > 250 and tonumber(wildcards[4]) > 250 and tonumber(wildcards [6]) > 90 then
DoAfter (2,"attack lobster")
else
wait.time (60)
Send ("look")
end -- if
end)[/CODE]
oviously the names of the creatures are changed so there is a script for each.
[CODE title="Main Loop"]require "wait"
wait.make (function () --- coroutine below here
time_to_stop = false -- make true elsewhere to make the loop stop
local ArrayBeach = ArrayBeach = {w,w,w,w,w,n,e,e,e,e,e,n,w,w,w,w,w,n,e,e,e,e,e,n,w,w,w,w,w,n,e,e,e,e,e,s,s,s,s,s,s,s} -- and so on
local current_pos = 1 -- start at start of array
repeat
local direction = ArrayBeach [current_pos] -- get direction
-- next item in array for next time around loop
current_pos = current_pos + 1
-- wrap at end of array
if current_pos > #ArrayBeach then
current_pos = 1
end
Send (direction) -- go that way
-- ---------------------------------------------
-- Wait for room change (wait.match)
-- Find your HP etc. (wait.match)
-- Find what monsters are here (wait.match)
-- Decide to attack or not (Send "attack")
-- ---------------------------------------------
wait.time (5) -- allow 5 seconds before looping
until time_to_stop
end) -- end of coroutine[/CODE]
This is the array and what I am trying to accomplish. I have it laid out of what I want to do, and have the array set up. The mobs on the beach are Lobsters, Crabs, and Gulls. I have the following script written to check stats and attack when I see them.
[CODE title="Combat Script"]require "wait"
wait.make (function ()
Send("hp")
local line, wildcards = wait.match("* HP [ */* ] SP [ */* ] EP [ */* ]")
if tonumber(wildcards[2]) > 250 and tonumber(wildcards[4]) > 250 and tonumber(wildcards [6]) > 90 then
DoAfter (2,"attack lobster")
else
wait.time (60)
Send ("look")
end -- if
end)[/CODE]
oviously the names of the creatures are changed so there is a script for each.
Last edited: