Log in

View Full Version : Need help creating a script



duggle
05-07-2012, 10:05 PM
Hey as I'm totally new to Lua scripting I'm just trying stuff out without really knowing what everything does, so bear with me.

I'm trying to create a script that would pause the Walker for 8-9 seconds if a monster goes invisible. So looking at some random scripts to get a clue about formatting and such I came up with this:


--Invisible monster wait timer


function check()
if(Creature:isVisible() == false) then
setWalkerEnabled(false)
wait(8000,9000)
setWalkerEnabled(true)
else
SetWalkerEnabled(true)
end
wait(500,900)
end


How could I get this to work, and am I even somewhere close to what I'm trying to achieve here?

Also, relevant
http://cdn.head-fi.org/6/6a/6a4d386f_I_Have_No_Idea_What_I_m_Doing.jpeg

Spectrus
05-07-2012, 10:17 PM
Right... so:

1: You need to specify which monster you are talking about. The example assumes we're discussing the current target.
2: You wrote what is called a function. It is something that you can now use (but haven't, yet).
3: Your current script will result in an error. You have closed your if statement with an "end" but not your function.
4: There's more that I could explain, but it's easier if I write an example. Each line of the example is commented on, explaining what it does.

With comments:


while true do -- This is an infinite loop. It's checking if true is true, which is always going to be true.
local Target = Creature.GetByID(Self.TargetID()) -- Here we are creating a variable called "Target", it's a monster, and that monster is retrieved by ID. The ID of the monster we want is the one we are attacking, ergo we use Self.TargetID() which returns the ID of the monster we are attacking.
if not Target:isVisible() then -- If the target is not visible, do the following.
delayWalker(math.random(8000,9000)) -- Delay the walker by a random number of milliseconds between 8000 and 9000.
end -- This end closes the if statement.
sleep(50) -- It's always a good idea to sleep for a bit when you're in an infinite loop, otherwise it will lag your computer.
end -- This end closes the loop.

Without comments:


while true do
local Target = Creature.GetByID(Self.TargetID())
if not Target:isVisible() then
delayWalker(math.random(8000,9000))
end
sleep(50)
end

duggle
05-07-2012, 10:25 PM
Thanks very much Spectrus for the Dummy proof answer.

duggle
05-07-2012, 10:31 PM
Oh and also, how would I go about adding Creature:isAlive () to that, cause else it would just stop everytime the monster died right?

Spectrus
05-07-2012, 10:34 PM
Mmmh, perhaps.

So in the if statement:


if not Target:isVisible() then


Add:


if Target:isAlive() and not Target:isVisible() then


I'm not sure if the logic on this entire concept pans out, however... One of those things you'd have to test. :p

duggle
05-07-2012, 10:47 PM
Works like a charm now. I understand everything you say it's just that I'm close to clueless on the formatting as the only programming I've read is some basic c++ years ago.

Thanks again for the help Spectrus.

Also for anyone wanting this script (I'm using it on Yalahar cults), here it is:


while true do
local Target = Creature.GetByID(Self.TargetID())
if Target:isAlive() and not Target:isVisible() then
delayWalker(math.random(8000,9000))
end
sleep(50)
end