Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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.

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.
 
Last edited:
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!
 
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.

[CODE title="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
[/CODE]

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:

[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]

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.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom