• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

isInRange

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
Error:
Code:
[26/2/2014 16:28:10] [Error - CreatureScript Interface]
[26/2/2014 16:28:10] data/creaturescripts/scripts/quest login.lua:onLogin
[26/2/2014 16:28:10] Description:
[26/2/2014 16:28:10] data/lib/032-position.lua:3: attempt to index local 'toPosition' (a nil value)
[26/2/2014 16:28:10] stack traceback:
[26/2/2014 16:28:10]    data/lib/032-position.lua:3: in function 'isInRange'
[26/2/2014 16:28:10]    data/creaturescripts/scripts/quest login.lua:2: in function <data/creaturescripts/scripts/quest login.lua:1>

Script:
Code:
function onLogin(cid)
    if isInRange(getCreaturePosition(cid), HEYTON_REST_PB) then
      doTeleportThing(cid, CEMITERY)
    elseif isInRange(getCreaturePosition(cid), HEYTON_REST_PVT1) then
      doTeleportThing(cid, CEMITERY)
    elseif isInRange(getCreaturePosition(cid), HEYTON_REST_PVT2) then
      doTeleportThing(cid, CEMITERY)
    end
  return true
end

000-constant:
Code:
HEYTON_REST = 666001
HEYTON_REST_PB = {x=7427, y=7516, z=8}, {x=7519, y=7434, z=8}
HEYTON_REST_PVT1 = {x=7310, y=7517, z=8}, {x=7402, y=7435, z=8}
HEYTON_REST_PVT2 = {x=7186, y=7517,z=8}, {x=7278, y=7435, z=8}
CEMITERY = {x=7498, y=7502, z=7}
 
Do you have isInRange function?
check in ur global.lua file if you have this
Code:
function isInRange(pos, fromPos, toPos)
return pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z
end
if not, add it
 
Now the error is:
Code:
[26/2/2014 17:44:50] [Error - CreatureScript Interface]
[26/2/2014 17:44:50] data/creaturescripts/scripts/quest login.lua:onLogin
[26/2/2014 17:44:50] Description:
[26/2/2014 17:44:50] data/lib/050-function.lua:465: attempt to index local 'toPos' (a nil value)
[26/2/2014 17:44:50] stack traceback:
[26/2/2014 17:44:50]    data/lib/050-function.lua:465: in function 'isInRange'
[26/2/2014 17:44:50]    data/creaturescripts/scripts/quest login.lua:2: in function <data/creaturescripts/scripts/quest login.lua:1>
[26/2/2014 17:44:50] Mago Insano has logged out.

Function:
Code:
function isInRange(pos, fromPos, toPos)
  return pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z
end

Constant:
Code:
HEYTON_REST = 666001
HEYTON_REST_PB = {x=7427, y=7516, z=8}, {x=7519, y=7434, z=8}
HEYTON_REST_PVT1 = {x=7310, y=7517, z=8}, {x=7402, y=7435, z=8}
HEYTON_REST_PVT2 = {x=7186, y=7517,z=8}, {x=7278, y=7435, z=8}
CEMITERY = {x=7498, y=7502, z=7}
 
Now the constant is:
Code:
HEYTON_REST = 666001
HEYTON_REST_PB_FROM = {x=7427, y=7516, z=8}
HEYTON_REST_PB_TO = {x=7519, y=7434, z=8}
HEYTON_REST_PVT1_FROM = {x=7310, y=7517, z=8}
HEYTON_REST_PVT1_TO = {x=7402, y=7435, z=8}
HEYTON_REST_PVT2_FROM = {x=7186, y=7517,z=8}
HEYTON_REST_PVT2_TO = {x=7278, y=7435, z=8}
CEMITERY = {x=7498, y=7502, z=7}

Edit: Now don't appear an error, but after I login I don't teleport. Why?
The script:
Code:
function onLogin(cid)
    if isInRange(getCreaturePosition(cid), HEYTON_REST_PB_FROM, HEYTON_REST_PB_TO) then
      doTeleportThing(cid, CEMITERY)
    elseif isInRange(getCreaturePosition(cid), HEYTON_REST_PVT1_FROM, HEYTON_REST_PVT1_TO) then
      doTeleportThing(cid, CEMITERY)
    elseif isInRange(getCreaturePosition(cid), HEYTON_REST_PVT2_FROM, HEYTON_REST_PVT2_TO) then
      doTeleportThing(cid, CEMITERY)
    end
  return true
end
 
Last edited:
It wasn't a table. You forgot { }
Code:
myTable = {{thing1a, thing1b}, thing3, {thing4a, thing4b}}
Code:
HEYTON_REST_PB = {{x=7427, y=7516, z=8}, {x=7519, y=7434, z=8}}
HEYTON_REST_PVT1 = {{x=7310, y=7517, z=8}, {x=7402, y=7435, z=8}}
HEYTON_REST_PVT2 = {{x=7186, y=7517,z=8}, {x=7278, y=7435, z=8}}

Your first script is good and will work corectly.
 
Last edited:
Now the script is:
Code:
function onLogin(cid)
    if ((isInRange(getCreaturePosition(cid), mission.HEYTON_REST_PB_FROM, mission.HEYTON_REST_PB_TO) == true) or (isInRange(getCreaturePosition(cid), mission.HEYTON_REST_PVT1_FROM, mission.HEYTON_REST_PVT1_TO) == true) or (isInRange(getCreaturePosition(cid), mission.HEYTON_REST_PVT2_FROM, mission.HEYTON_REST_PVT2_TO) == true)) then
      doTeleportThing(cid, mission.CEMITERY)
    end
  return true
end

Code:
mission = {
HEYTON_REST = 666001,
HEYTON_REST_PB_FROM = {x=7427, y=7516, z=8},
HEYTON_REST_PB_TO = {x=7519, y=7434, z=8},
HEYTON_REST_PVT1_FROM = {x=7310, y=7517, z=8},
HEYTON_REST_PVT1_TO = {x=7402, y=7435, z=8},
HEYTON_REST_PVT2_FROM = {x=7186, y=7517,z=8},
HEYTON_REST_PVT2_TO = {x=7278, y=7435, z=8},
CEMITERY = {x=7498, y=7502, z=7}
}

But don't work! :(
 
Back
Top