Jump to content

onClientElementDataChange vs setTimer updateData which one is more optimize?


Recommended Posts


addEventHandler("onClientElementDataChange", localPlayer,
    function (dataName, oldValue)
        if source == localPlayer then

            elseif dataName == "Hunger" then
                settings.currentHunger = getElementData(localPlayer, "Hunger")            
                elseif dataName == "Panic" then
                settings.currentPanic = getElementData(localPlayer, "Panic")
            elseif dataName == "Thirsty" then
                settings.currentThirst = getElementData(localPlayer, "Thirsty")
            -- elseif dataName == "Level Element Data" then
                -- renderData.currentLevel = getElementData(localPlayer, "Level Element Data")
            elseif dataName == "money" then
                settings.currentMoney = getElementData(localPlayer, "money")            
                elseif dataName == "RedMoney" then
                settings.currentRedMoney = getElementData(localPlayer, "RedMoney")
            end
        end
    end
)

and
 


local function updatePlayerStats()
    settings.isLoggedIn = getElementData(localPlayer, "username")
    settings.currentMoney = getElementData(localPlayer, "money") or 0
    settings.currentRedMoney = getElementData(localPlayer, "RedMoney") or 0
    settings.currentHunger = getElementData(localPlayer, "Hunger") or 0
    settings.currentThirst = getElementData(localPlayer, "Thirsty") or 0
    settings.currentPanic = getElementData(localPlayer, "Panic") or 0
    settings.currentHealth = math_ceil(getElementHealth(localPlayer))

end

    setTimer(updatePlayerStats, 1000, 0)

whice one is more than optimize?

Link to comment
  • Moderators
14 hours ago, darkenpra said:

whice one is more than optimize?

onClientElementDataChange, that is if you do not mis use elementdata. For example setting element data every frame.

If the event onClientElementDataChange is triggered more than ~5x each second (9 func calls x 1s vs ~2 func calls each update, 9 / 2 = ~5). The timer will be more optimised than the event. (9x with different element data key) But in general the timer has a slower update timing, which should also taken in consideration.

  • Thanks 1
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...