Log in

View Full Version : Help with modules



Eion
04-18-2013, 05:46 PM
Ok so I am trying to create a module within my main .lua that will check to see if my positioning has changed within a certain period of time, and if not, it will call my custom CheckLocation() function. I cannot seem to get this to work right... As far as I know this below should make the module run at a 200ms interval. Thanks for any help.


standtimemax = 240 -- Seconds to stand before alerting
oldposition = 0 -- Declare the variable for oldposition as we need to compare it before it is used.


function StuckCheck()
local position = Self.Position()


if (oldposition ~= 0) then
if (position == oldposition) then
stood = stood + 1
else
stood = 0
end
if (stood > standtimemax) then
CheckLocation()
end
end
oldposition = Self.Position()
end
local FixLocation = Module.New("Location Fixer", StuckCheck(), True)

Hendy
04-18-2013, 05:56 PM
Eion, I do my modules like this and it works so try below :]

Module.New("Location Fix", function(module)
local position = Self.Position()
if (oldposition ~= 0) then
if (position == oldposition) then
stood = stood + 1
else
stood = 0
end
if (stood > standtimemax) then
CheckLocation()
end
end
oldposition = Self.Position()
end)

Eion
04-18-2013, 06:09 PM
Thanks. Although this still is not working for me, It's not throwing any errors either. :(

I don't have a clue.

Hendy
04-18-2013, 06:28 PM
Thanks. Although this still is not working for me, It's not throwing any errors either. :(

I don't have a clue.

"Location Fix" there was a missing " if you didnt spot it on mine. You trying to check if your in the same position?

Spectrus
04-18-2013, 06:32 PM
You can't compare positions that way.

Best way would be Self.DistanceFromPosition(x,y,z) which returns a number.

Also what is going on with the logic for your timing?

Eion
04-18-2013, 06:32 PM
I saw that, and thank you very much for your help. It ended up being something to do with how I was comparing the two positions, nothing was wrong with your code. It works fine this way.


Module.New("Location Fixer", function(module)
local position = Self.Position()
if (oldposition ~= 0) then
if (position.x == oldposition.x) and (position.y == oldposition.y) and (position.z == oldposition.z) then
stood = stood + 1
else
stood = 0
end
if (stood > standtimemax) then
CheckLocation()
end
end
oldposition = position
end)


In case you are wondering... My CheckLocation() function looks like this, It stops the scripts from getting stuck and also makes it so all I have to do to start the bot is just load the settings, no matter where the character is.


function isLocation(posx, posy, posz, range, allfloors)
local spos = Self.Position()
if (math.abs(posx - spos.x) <= range) and (math.abs(posy - spos.y) <= range) then
if (math.abs(posz - spos.z) == 0) or (allfloors == true) then
return true
end
end
return false
end


function CheckLocation()
checkifatdepot = isLocation(33018, 32051, 7, 12, true)
checkhole1 = isLocation(32948, 32180, 9, 3, false)
checkhole2 = isLocation(32948, 32193, 9, 12, false)
checkhole3 = isLocation(32953, 32178, 9, 3, false)
checkhole4 = isLocation(32947, 32172, 9, 4, false)
checkhole5 = isLocation(32941, 32177, 9, 4, false)
checkhole6 = isLocation(32922, 32178, 9, 30, false)
checkhole7 = isLocation(32938, 32217, 7, 10, true)
checkifintown = isLocation(32936, 32091, 6, 80, false)
if checkifatdepot then
gotoLabel("Deposit")
elseif checkhole1 or checkhole2 then
gotoLabel("Fix1")
elseif checkhole3 then
gotoLabel("NextLadder3")
elseif checkhole4 then
gotoLabel("NextLadder2")
elseif checkhole5 then
gotoLabel("NextLadder1")
elseif checkhole6 then
gotoLabel("BackDown2")
elseif checkhole7 then
gotoLabel("Fix2")
elseif checkifintown then
gotoLabel("refill")
end
end

Spectrus
04-18-2013, 06:36 PM
Why are you using _G?

Eion
04-18-2013, 06:50 PM
Lol slow down, I copied and pasted the wrong thing and was editing it while you were reading it. :p

And my form of logic on the time? The module runs 5 times per second. Correct?

If you look at the xeno lib lua you will notice that the function "Self.DistanceFromPosition(x,y,z)" does not actually account for the z coord. This is why I created the "isLocation(posx, posy, posz, range, allfloors)" function above.

Nakuu
04-30-2013, 09:00 AM
Is there any way to create an module that accepts parameters and can be started with them?
I mean something like that:

function Smth(module, par1, par2, par3)
print(par1+par2+par3)
module:Delay(1000)
end


and then
local xxx = Module.New('x-x-x', Smth)
moduleName:Start(par1, par2, par3)

So basically I want to make single module that can be used with different variables.