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

getPlayerPosition don't work

  • Thread starter Thread starter Deleted member 141899
  • Start date Start date
D

Deleted member 141899

Guest
Hello guys,

Im using TFS 1.0
I'm trying to make the player just teleport to the boss if the tile face the pedestal, but is not working, are going straight to the doPlayerCancel and ignore the function If getPlayerPosition

Script:


Code:
local positions = {
    [1] = {x = 33603, y = 32394, z = 11}, -- home position
    [2] = {x = 33614, y = 32415, z = 12}   -- boss room position
       
}


local coords = {
    [1] = 33600, -- upper left corner of room
    [2] = 33615, -- upper right corner "
    [3] = 32414, -- upper left corner "
    [4] = 32429, -- bottom left corner "
    [5] = 12    -- z position
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = { {x = 33603, y = 32394, z = 11}, }

   if(itemEx.itemid == 22634) and getPlayerPosition(cid) == pos then
        
                  doPlayerSendTextMessage(cid, 19, "You have entered an ancient demon prision cell!") -- mensagem que sairá quando ele for teleportado
                  doPlayerSendTextMessage(cid, 19, "You have fifteen minutes to kill and loot this boss, else you will lose that chance.") -- mensagem que sairá quando ele for teleportado
                  doTeleportThing(cid, positions[2])
                  addEvent(bossTimer, 60*1000, cid)
                  doPlayerRemoveItem(cid, 22605, 1)
                  doSendMagicEffect(positions[2], CONST_ME_TELEPORT)
                else
       doPlayerSendCancel(cid, "Use this key in the correct place.")
         end
    return true
end

I dont posted the function bosstimer here, the script works 100% if i dont place the function (if getplayerposition) but i want it.

Help !

 
Afaik you cannot compare a position like that because it is a table. e.g. {x=x, y=y, z=z}

You will need to use a function similar to
Code:
function doComparePositions(pos1, pos2)
    return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z
end

An example usage would be:

Code:
if(doComparePositions(pos1, pos2)) then
    print("we are the same!")
else
    print("we are different :(")
end
 
Sorry i dont understand, i need to add the function doComparePosition in lib/customfunctions?

and i dont understand how to edit the script, can you help me? thanks
 
i need to add the function doComparePosition in lib/customfunctions?
Yes.

and i dont understand how to edit the script, can you help me? thanks
No because that would cause you to not know how to edit the script next time. Try to play around with it so you can learn, I did give you an example on how to use the function.
 
u are br??

Code:
local positions = {
    [1] = {x = 33603, y = 32394, z = 11}, -- home position
    [2] = {x = 33614, y = 32415, z = 12}   -- boss room position
       
}
local coords = {
    [1] = 33600, -- upper left corner of room
    [2] = 33615, -- upper right corner "
    [3] = 32414, -- upper left corner "
    [4] = 32429, -- bottom left corner "
    [5] = 12    -- z position
}
function isInPosition(pos1,pos2)
return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z and true or false
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {x = 33603, y = 32394, z = 11}
if(itemEx.itemid == 22634) and isInPosition(getPlayerPosition(cid), pos) then
                  doPlayerSendTextMessage(cid, 19, "You have entered an ancient demon prision cell!") -- mensagem que sairá quando ele for teleportado
                  doPlayerSendTextMessage(cid, 19, "You have fifteen minutes to kill and loot this boss, else you will lose that chance.") -- mensagem que sairá quando ele for teleportado
                  doTeleportThing(cid, positions[2])
                  addEvent(bossTimer, 60*1000, cid)
                  doPlayerRemoveItem(cid, 22605, 1)
                  doSendMagicEffect(positions[2], CONST_ME_TELEPORT)
                else
       doPlayerSendCancel(cid, "Use this key in the correct place.")
         end
    return true
end
 
Last edited:
I agree with Xagul, you should play around with the script to understand it so that you can edit it yourself next time and become better at LUA. :)

If you're totally stuck, here is what Xagul thought you could do after adding the doComparePositions function to somewhere.

Code:
local positions = {
    [1] = {x = 33603, y = 32394, z = 11}, -- home position
    [2] = {x = 33614, y = 32415, z = 12}   -- boss room position
      
}


local coords = {
    [1] = 33600, -- upper left corner of room
    [2] = 33615, -- upper right corner "
    [3] = 32414, -- upper left corner "
    [4] = 32429, -- bottom left corner "
    [5] = 12    -- z position
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = { {x = 33603, y = 32394, z = 11}, }

   if(itemEx.itemid == 22634) and doComparePositions(pos, getPlayerPosition(cid)) then
       
                  doPlayerSendTextMessage(cid, 19, "You have entered an ancient demon prision cell!") -- mensagem que sairá quando ele for teleportado
                  doPlayerSendTextMessage(cid, 19, "You have fifteen minutes to kill and loot this boss, else you will lose that chance.") -- mensagem que sairá quando ele for teleportado
                  doTeleportThing(cid, positions[2])
                  addEvent(bossTimer, 60*1000, cid)
                  doPlayerRemoveItem(cid, 22605, 1)
                  doSendMagicEffect(positions[2], CONST_ME_TELEPORT)
                else
       doPlayerSendCancel(cid, "Use this key in the correct place.")
         end
    return true
end
 
Just make it simple lol
Code:
if(Player(cid):getPosition() == Position(33603, 32394, 11)) then
 
Are we just going to ignore the fact that in the original script, he was comparing the player's position to pos. pos is a table with a table inside it, he would need to compare to pos[1], why did nobody else catch that o.o
 
Are we just going to ignore the fact that in the original script, he was comparing the player's position to pos. pos is a table with a table inside it, he would need to compare to pos[1], why did nobody else catch that o.o
I did notice that actually xD but as with most scripts on this forum, I figured it was just copy/pasted from a script that had multiple positions so I didn't say anything. The main lesson he needed to learn is that you cannot compare 2 positions in such a way.

But since we are getting picky now, that position should also have been defined outside of the function because it is pointless to redefine it each time the script is ran since the position never changes.
Also the () around itemEx.itemid == 22634 serves no purpose.
And
Code:
local positions = {
[1] = {x = 33603, y = 32394, z = 11}, -- home position
[2] = {x = 33614, y = 32415, z = 12} -- boss room position
}
Could just as easily be
Code:
local positions = {
{x = 33603, y = 32394, z = 11}, -- home position
{x = 33614, y = 32415, z = 12} -- boss room position
}

Oh and almost forgot... the tabbing is horrendous.


tfs 1.x is so amazing, you should try it
I plan to eventually... just need to get around to it. /plswantmodalwindows
 
Back
Top