Jump to content

Wrong getElementData


igthomas

Recommended Posts

Hi I made an afk script , player gets moved to a specified interior and when he writes back it gets him back where he left being afk, but for some reason it gets the position of the interior not the one where he left. Oh and do you suggest doing setTimer every 1 seconds or is it bad for the server?

function onIdle (thePlayer) 
    for index, thePlayer in ipairs(getElementsByType("player"))do 
        if (getPlayerIdleTime(thePlayer) > 5000) then --120000 
            local oldPos = getElementPosition (thePlayer) 
            setElementData(thePlayer,"away",oldPos) 
            setElementInterior ( thePlayer, 1, 681.5, -455.46, -25.6 ) 
        end 
    end 
end 
setTimer(onIdle, 1000, 0) 
  
function onBack (thePlayer) 
    if getElementData(thePlayer,"away") then 
        local oldPos = tonumber(getElementData(thePlayer,"away")) 
        setElementInterior ( thePlayer, 0, oldPos ) 
    end 
end 
addCommandHandler("back", onBack) 

Link to comment

try this:

function onIdle (thePlayer) 
    for index, thePlayer in ipairs(getElementsByType("player"))do 
        if (getPlayerIdleTime(thePlayer) > 5000) then --120000 
            local x,y,z = getElementPosition (thePlayer) 
            setElementData(thePlayer,"away-x",x) 
            setElementData(thePlayer,"away-y",y) 
            setElementData(thePlayer,"away-z",z) 
            setElementInterior ( thePlayer, 1, 681.5, -455.46, -25.6 ) 
        end 
    end 
end 
setTimer(onIdle, 1000, 0) 
  
function onBack (thePlayer) 
    if getElementData(thePlayer,"away") then 
        local x = tonumber(getElementData(thePlayer,"away-x")) 
        local y = tonumber(getElementData(thePlayer,"away-y")) 
        local z = tonumber(getElementData(thePlayer,"away-z")) 
        setElementInterior ( thePlayer, 0, x, y, z ) 
    end 
end 
addCommandHandler("back", onBack) 

Link to comment

okee let me test the code than, hang on a sec!

edit: okee I made 2 commands out of it, it works now. The thing is, he didn't add the elementData to the player, so it couldn't go back. right now I've saved them in your account data, and it works. All you've to do it create the functions around it again. if you got a minute I'll do it for you:

addCommandHandler("afk", 
function (source) 
    local x,y,z = getElementPosition (source) 
    setAccountData(getPlayerAccount(source),"away-x",x) 
    setAccountData(getPlayerAccount(source),"away-y",y) 
    setAccountData(getPlayerAccount(source),"away-z",z) 
    setElementInterior ( source, 1, 681.5, -455.46, -25.6 ) 
end) 
  
addCommandHandler("back",  
function (source) 
    if getAccountData(getPlayerAccount(source),"away-x") then 
        local x = getAccountData(getPlayerAccount(source),"away-x") 
        local y = getAccountData(getPlayerAccount(source),"away-y") 
        local z = getAccountData(getPlayerAccount(source),"away-z") 
        setElementInterior ( source, 0, x, y, z ) 
    end 
end) 

Edited by Guest
Link to comment
function onIdle (thePlayer) 
    for index, thePlayer in ipairs(getElementsByType("player"))do 
        if (getPlayerIdleTime(thePlayer) > 5000) then --120000 
            local oldX, oldY, oldZ = getElementPosition (thePlayer) 
            setElementData(thePlayer,"away",{oldX, oldY, oldZ}) 
            setElementInterior ( thePlayer, 1, 681.5, -455.46, -25.6 ) 
        end 
    end 
end 
setTimer(onIdle, 5000, 0) 
  
function onBack (thePlayer) 
    if getElementData(thePlayer,"away") then 
        local oldPos = getElementData(thePlayer,"away") 
        setElementInterior ( thePlayer, 0, oldPos[1], oldPos[2], oldPos[3] ) 
    end 
end 
addCommandHandler("back", onBack) 

setElementPosition returns 3 values not just one! And checking every player every second is not a good idea I think... :)

Link to comment
function onIdle (thePlayer) 
    for index, thePlayer in ipairs(getElementsByType("player"))do 
        if (getPlayerIdleTime(thePlayer) > 5000) then --120000 
            local oldX, oldY, oldZ = getElementPosition (thePlayer) 
            setElementData(thePlayer,"away",{oldX, oldY, oldZ}) 
            setElementInterior ( thePlayer, 1, 681.5, -455.46, -25.6 ) 
        end 
    end 
end 
setTimer(onIdle, 5000, 0) 
  
function onBack (thePlayer) 
    if getElementData(thePlayer,"away") then 
        local oldPos = getElementData(thePlayer,"away") 
        setElementInterior ( thePlayer, 0, oldPos[1], oldPos[2], oldPos[3] ) 
    end 
end 
addCommandHandler("back", onBack) 

setElementPosition returns 3 values not just one! And checking every player every second is not a good idea I think... :)

use his code. xD

Link to comment

Thanks for your help guys :D csiguusz your script worked just one thing how could I stop the checking if the player is still afk? Because I have a feeling that if the player stays afk and it check everytime and save the position, it will save the new one where he's in the interior right?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...