• 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 Why wont this work? Lever teleport

highclick

New Member
Joined
Mar 21, 2011
Messages
80
Reaction score
4
.lua script:


PHP:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.actionid = 102 then
doTeleportThing(cid, {x=1283, y=1084, z=8})
end
return true
end

.xml script:

PHP:
    <action actionid="102" event="script" value="other/dungeonleverking.lua" />


It's a lever with actionID 102, it's supposte too teleport you when you click on it.
 
Remove
Code:
if item.actionid = 102 then
And the end above return true.
If you compare numbers to see if it's the same/equal, use == instead of =
http://otland.net/threads/scripting-guide.74030/#post-758251
But checking for actionid while it's already in actions.xml is just useless so this whole line isn't needed.

Next time, post the errors (and your server version, so people don't have to look at your other threads).
 
It's already added with actionid 102 in actions.xml so it will only execute the script if the item has actionid 102. So if you add such a line it will be just useless code, since it will only be executed if the actionid is 102.

If it should check for actionid in the Lua script (for example when there are more ids used for the same script), then the line should look like this.
Code:
if item.actionid == 102 then
 
Ah i see, thanks alot man!

One more question, if i may.

I tried too add another condition, so that the lever teleport only works if the player stands on a specific tile. I added this into my code and it won't work:


PHP:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getCreaturePosition(cid) == {x=1277, y=1084, z=8} then
    doTeleportThing(cid, {x=1282, y=1084, z=8})
return true
end

Care too help? @Limos
 
You can't compare tables like that.
You can add this function (data/lib/050-function.lua).
Code:
function comparePos(poss, pos)
     return pos.x == poss.x and pos.y == poss.y and pos.z == poss.z
end

Then in that script
Code:
if comparePos(getCreaturePosition(cid), {x=1277, y=1084, z=8}) then
Don't forget to close if statements with end.
 
Okay i added the function into data/lib/050-function.lua

and this is my .lua script:


PHP:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if comparePos(getCreaturePosition(cid), {x=1277, y=1084, z=8}) then
        doTeleportThing(cid, {x=1282, y=1084, z=8})
    end
return true
end

Still won't work. It feels like I'm missing a vital undertanding of some logic here. @Limos
 
Look if you get errors or if you get this message ingame.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
     if comparePos(getCreaturePosition(cid), {x=1277, y=1084, z=8}) then
         doTeleportThing(cid, {x=1282, y=1084, z=8})
     else
         doPlayerSendCancel(cid, "You have to stand on the right position.")
     end
     return true
end
 
Look if you get errors or if you get this message ingame.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
     if comparePos(getCreaturePosition(cid), {x=1277, y=1084, z=8}) then
         doTeleportThing(cid, {x=1282, y=1084, z=8})
     else
         doPlayerSendCancel(cid, "You have to stand on the right position.")
     end
     return true
end

No messages in game and no errors in console
 
Look if you get errors or if you get this message ingame.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
     if comparePos(getCreaturePosition(cid), {x=1277, y=1084, z=8}) then
         doTeleportThing(cid, {x=1282, y=1084, z=8})
     else
         doPlayerSendCancel(cid, "You have to stand on the right position.")
     end
     return true
end
Should we be using return false, after the doplayersendcancel?
 
Back
Top