PDA

View Full Version : Check Starting Position



djnacht
12-30-2015, 06:04 AM
Hello!

I'm a day old to Tibia, XenoBot and Lua, but my vacation time has allowed me to invest most of my day into understanding all this stuff.

For the moment I plan on staying in Dawnport to practice some scripting, and I'm curious if other users check their bots' position before doing anything else in their script.

My code checks to see my characters position and verifies that it is within specific boundaries before starting. It seems to work, but I feel like it is a crude piece of code written by a caveman. Would anyone else care to improve on this, or suggest how I may do so?



registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")
print("Registered Event Listener, Welcome")
wait(3000)

function onWalkerSelectLabel(LabelName)
if(LabelName == "Start") then
print("Checking Position, Make sure you are in the starting area")
if(Self.Position().z == 5) and (Self.Position().x >= 32054) and (Self.Position().x <= 32075) and (Self.Position().y <= 31901) and (Self.Position().y >= 31880) then
print("Script Starting")
else
print("Go to Starting Position")
Walker.Stop()
end
end
end

Aristeus
12-30-2015, 07:02 AM
Hello!

I'm a day old to Tibia, XenoBot and Lua, but my vacation time has allowed me to invest most of my day into understanding all this stuff.

For the moment I plan on staying in Dawnport to practice some scripting, and I'm curious if other users check their bots' position before doing anything else in their script.

My code checks to see my characters position and verifies that it is within specific boundaries before starting. It seems to work, but I feel like it is a crude piece of code written by a caveman. Would anyone else care to improve on this, or suggest how I may do so?



registerEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")
print("Registered Event Listener, Welcome")
wait(3000)

function onWalkerSelectLabel(LabelName)
if(LabelName == "Start") then
print("Checking Position, Make sure you are in the starting area")
if(Self.Position().z == 5) and (Self.Position().x >= 32054) and (Self.Position().x <= 32075) and (Self.Position().y <= 31901) and (Self.Position().y >= 31880) then
print("Script Starting")
else
print("Go to Starting Position")
Walker.Stop()
end
end
end



You're better off checking the distance from a certain position than what you're doing now. It's just much smoother.

Use this function:


Self.DistanceFromPosition(x, y, z)

A lot of people check their position when they start their scripts. I do it in mine to determine if I'm at the depot or at the offline trainer (two locations where my scripts can startup automatically).

shadowart
12-30-2015, 09:56 AM
This is what I do:

local sLabel, sDist = nil, 9999
for label, pos in pairs(startingLocations) do
local dist = Self.DistanceFromPosition(pos.x, pos.y, pos.z)
if dist < sDist and Self.Position().z == pos.z then
sLabel = label
sDist = dist
end
end
if sLabel and sDist < 40 then
Walker.Goto(sLabel)
end

startingLocations is a table that's written by the built script which creates it by analyzing the corresponding xbst file, but you could just create it by hand if you want.

djnacht
12-31-2015, 11:06 PM
Thanks for the replies! I have another question, but I'll start a new post for it.