Jump to content

Sync element data faster and accurately.


Noki

Recommended Posts

function dataChange() 
if getElementType(source) == "player" then 
local px, py, pz = getElementPosition(source) 
setElementData(source, "Money", getPlayerMoney(source)) 
setElementData(source, "City", getZoneName(px, py, pz, true)) 
end 
end 
addEventHandler("onElementDataChange", getRootElement(), changeData) 

I tried using a timer, but I just get debug spam. I did put 'source' in the timer function argument bracket.

I just want to make it sync faster, as there is currently a 5 second delay. Also, when using getZoneName, it only works when the ped is touching the ground, but I want it compatible with planes etc. Is there any way to fix my problem?

Thanks.

Edit: I'd like to keep it server side, but I'm happy to do otherwise.

Link to comment
setTimer(function() 
    for index, players in pairs(getElementsByType("player")) do 
        local x, y, z = getElementPosition(players) 
        setElementData(players, "Money", "$"..getPlayerMoney(players)) 
        setElementData(players, "City", ""..getZoneName(x, y, z, true).."") 
    end 
end, 1000, 0) 

Link to comment
  • Moderators
setTimer(function() 
    for index, players in pairs(getElementsByType("player")) do 
        local x, y, z = getElementPosition(players) 
        setElementData(players, "Money", "$"..getPlayerMoney(players)) 
        setElementData(players, "City", ""..getZoneName(x, y, z, true).."") 
    end 
end, 1000, 0) 

That will lagg. If you set the value again don't expect it won't use bandwidth. (because elementdata can also be set on client side without syncronisation, so it will set it again and again)

    setTimer(function() 
        for index, players in pairs(getElementsByType("player")) do 
            local playerMoney = "$"..getPlayerMoney(players) 
            local lastPlayerMoney = getElementData(players,"Money") 
            if not lastPlayerMoney or lastPlayerMoney ~= playerMoney then 
                setElementData(players, "Money",playerMoney) 
            end 
            local x, y, z = getElementPosition(players) 
            local playerZoneName = getZoneName(x, y, z, true) 
            local lastPlayerZoneName = getElementData(players,"City") 
            if not lastPlayerZoneName or lastPlayerZoneName ~= playerZoneName then 
                setElementData(players, "City",playerZoneName) 
            end 
        end 
    end, 1000, 0) 

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...