• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Help learning Lua

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?



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


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.

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)

oviously the names of the creatures are changed so there is a script for each.
 
Last edited:

Malcolm

Administrator
Administrator
Verified
Hello, Welcome to Code Forum!

Although we don't have an option for Lua, please make sure to add all your code within our BBCode feature (</>). Please view more here.

Gaming, watching videos, reading those are just a few of many ways that can help you learn to code. I'm happy you came to Code Forum for help! :)

Let's figure this out together. But first, what are you trying to do? What's your clear objective. @James & @CLONED have some knowledge of Lua. They may be of help!
 

eammonwright

New Coder
Hey, thanks for the reply. I will go back and edit my post, sorry about that.

So this is how I learn new languages, I write scripts on muds primarily to have a little fun while learning.
So essentially this loop is an array map of a beach on a mud game that im messing around with.

Full 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

The idea is to have my character walk the beach, when he sees one of the few creatures on the beach, the loop pauses, checks his stats, if their good, he attacks, once the creature is head he waits until his stats are at 100% then resumes the array loop. The combat script is:

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)

The combat script sees the creature, checks stats, if their above a certain level he attacks, if not he waits 60 seconds, then sends a look command so he sees the creature again and reruns the combat script.

I have a hard time trying to convey whats in my head so please let me know if it doesnt make any sense. Thanks for looking at it though.
 
Top Bottom