• 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!

Solved Teleport player from Pos

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am attempting to use a teleport lever to teleport a player from the "fromPos" on that specific tile. the lever works without standing on the pos. what am I missing? cryingdamson 0.3.6 (8.60) is the distro.

Code:
local function reset(p)
doTransformItem(getTileItemById(p, 1946).uid, 1945)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
local toPos = {x=1059, y=911, z=6}
local fromPos = {x=1057, y=917, z=6}
    if getPlayerLevel(cid) >=80 then
    if item.itemid == 1945 then
        doTeleportThing(cid, toPos, true)
        doPlayerSendTextMessage(cid, 22, "Phrase goes here!")
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
        doTransformItem(item.uid, item.itemid + 1)
        addEvent(reset, 10 * 1000, toPosition) --Timer
    elseif item.itemid == 1946 then
        doPlayerSendTextMessage(cid, 22, "Wait for switch to reset.")
    end
else
stopEvent(event)
reset(toPosition)
doPlayerSendCancel(cid, "You don't have the required level.")
end
return TRUE
    end
 
Last edited:
You need to check if cids position is the same as the position you want them to stand on.
(Realistically this would be more obvious to the player if you simply mapped it so they have to stand on a specific tile to use the lever.. but whatever.
You'll want to learn how to tab as well.. (so that everything lines up and it's easier to read later..)
(Just think of it this way.. you'll spend 80% of your time reading code.. and maybe 20% writing it. Make it readable from the start and you'll save yourself loads of time later on.)

Untested.
Code:
local function reset(p)
   doTransformItem(getTileItemById(p, 1946).uid, 1945)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   local endPos = {x = 1059, y = 911, z = 6} -- formerly toPos
   local startPos = {x = 1057, y = 917, z = 6} -- formerly fromPos
   -- I changed them.. so they aren't confused with the pre-made functions..
   
   -- check if player has required level.
   if getPlayerLevel(cid) < 80 then
     return doPlayerSendCancel(cid, "You don't have the required level.")
   end
   
   -- check if player is standing on correct square
   if getCreaturePosition(cid) ~= startPos then
     return doPlayerSendCancel(cid, "You are required to stand on the pressure plate to use this lever.")
   end
   
   -- check if lever is currently used
   if item.itemid == 1946 then
     return doPlayerSendTextMessage(cid, 22, "Wait for switch to reset.")
   end
   
   -- if everything checks out fine..
   
   -- transform lever, and add reset
   doTransformItem(item.uid, item.itemid + 1)
   addEvent(reset, 10 * 1000, toPosition)
   
   -- teleport player, send message and effect
   doTeleportThing(cid, endPos, true)
   doPlayerSendTextMessage(cid, 22, "Phrase goes here!")
   doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)

   return true
end

-- edit
Edited the bottom part of the code to my 'standards'. 5:17am
 
Last edited by a moderator:
thank you for you assistance, however I am still having issues with this section:

Code:
-- check if player is standing on correct square
   if getCreaturePosition(cid) ~= startPos then
     return doPlayerSendCancel(cid, "You are required to stand on the pressure plate to use this lever.")
   end

The switch will not work at all with ~=, no matter if I am standing on plate or not.
 
thank you for you assistance, however I am still having issues with this section:

Code:
-- check if player is standing on correct square
   if getCreaturePosition(cid) ~= startPos then
     return doPlayerSendCancel(cid, "You are required to stand on the pressure plate to use this lever.")
   end

The switch will not work at all with ~=, no matter if I am standing on plate or not.

That only works with 1.x since you use the userdata values and compare them.
What you have to do is compare all 3 indexes;
Code:
if (xA ~= xB or yA ~= yB or zA ~= zB) then
 
Have to be honest, I have no idea what to do with that


have to be honest, I have no idea what to do with this.
My bad. I forgot about this.
Updated. Untested. :p
Code:
local function reset(p)
   doTransformItem(getTileItemById(p, 1946).uid, 1945)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   local endPos = {x = 1059, y = 911, z = 6} -- formerly toPos
   local startPos = {x = 1057, y = 917, z = 6} -- formerly fromPos
   -- I changed them.. so they aren't confused with the pre-made functions..

   -- check if player has required level.
   if getPlayerLevel(cid) < 80 then
     return doPlayerSendCancel(cid, "You don't have the required level.")
   end

   -- check if player is standing on correct square
   local standPos = getCreaturePosition(cid)
   if (x.standPos ~= x.startPos or y.standPos ~= y.startPos or z.standPos ~= z.startPos) then
     return doPlayerSendCancel(cid, "You are required to stand on the pressure plate to use this lever.")
   end

   -- check if lever is currently used
   if item.itemid == 1946 then
     return doPlayerSendTextMessage(cid, 22, "Wait for switch to reset.")
   end

   -- if everything checks out fine..

   -- transform lever, and add reset
   doTransformItem(item.uid, item.itemid + 1)
   addEvent(reset, 10 * 1000, toPosition)

   -- teleport player, send message and effect
   doTeleportThing(cid, endPos, true)
   doPlayerSendTextMessage(cid, 22, "Phrase goes here!")
   doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)

   return true
end

edit --
Just realised this line is wrong.
Were comparing somethings x against another thing's x.. not x's something vs another x's something. :p

Update this line..
Code:
if (x.standPos ~= x.startPos or y.standPos ~= y.startPos or z.standPos ~= z.startPos) then
To this..
Code:
if (standPos.x ~= startPos.x or standPos.y ~= startPos.y or standPos.z ~= startPos.z) then
-- quick explanation
If characters current position (standPos) x, y, z is not equal to the startPos x, y, z then tell player they need to stand on the tile or square or pressure plate.

Cheers,

Xikini
 
Last edited by a moderator:
Back
Top