Jump to content

What event should i use ?


FuriouZ

Recommended Posts

Posted

Hello :)

I have question

What event should i use to check player data ?

I think theese are wrong ? I mean, will they lag ?

onClientRender

onClientPreRender

For example i got this function:

  
-- addEventHandler("onClientRender", root, 
addEventHandler("onClientPreRender", root, 
    function() 
        local Arena = getElementData(player,"Arena"); 
        if (Arena == "Stuntage" ) then 
            setPedCanBeKnockedOffBike(localPlayer, false) 
        else             
            setPedCanBeKnockedOffBike(localPlayer, true) 
        end 
    end) 

I found another way setTimer

But i thing it will lag, or not ?

or:

setTimer( 
    function() 
        local Arena = getElementData(player,"Arena"); 
        if (Arena == "Stuntage" ) then 
            setPedCanBeKnockedOffBike(localPlayer, false) 
        else             
            setPedCanBeKnockedOffBike(localPlayer, true) 
        end 
    end,5000,0) 

Wich one will be better ? Or should i use someting else ?

Posted

No, using a timer would be much more efficient. onClientRender and onClientPreRender both trigger their attached function with every frame.

So unless you need the function to be run 30-60 times per second, don't use those. Should read the Warning I added to those events in the wiki, to prevent wrong usage of those :)

Posted
Hello :)

I have question

What event should i use to check player data ?

I think theese are wrong ? I mean, will they lag ?

onClientRender

onClientPreRender

For example i got this function:

  
-- addEventHandler("onClientRender", root, 
addEventHandler("onClientPreRender", root, 
    function() 
        local Arena = getElementData(player,"Arena"); 
        if (Arena == "Stuntage" ) then 
            setPedCanBeKnockedOffBike(localPlayer, false) 
        else             
            setPedCanBeKnockedOffBike(localPlayer, true) 
        end 
    end) 

I found another way setTimer

But i thing it will lag, or not ?

or:

setTimer( 
    function() 
        local Arena = getElementData(player,"Arena"); 
        if (Arena == "Stuntage" ) then 
            setPedCanBeKnockedOffBike(localPlayer, false) 
        else             
            setPedCanBeKnockedOffBike(localPlayer, true) 
        end 
    end,5000,0) 

Wich one will be better ? Or should i use someting else ?

This is very inefficient - You only need to call setPedCanBeKnockedOffBike once.

  • Moderators
Posted
This is very inefficient - You only need to call setPedCanBeKnockedOffBike once.

No. Because the player can switch between arenas. So put this code in a function and call it everytime the player choose/select an arena:

function updateCanBeKnockedOffBike() 
    local arena = getElementData(localPlayer, "Arena") 
    if arena == "Stuntage"  then 
        setPedCanBeKnockedOffBike(localPlayer, false) 
    else 
        setPedCanBeKnockedOffBike(localPlayer, true) 
    end 
end 

Has to be on the client side ofc.

  • Moderators
Posted
You just repeated what I said.?

Not at all, you wanted him to do this code only once (then with onClientResourceStart) but in fact, he surely want it to be executed as many times the player will select a first/new arena.

Posted
This is very inefficient - You only need to call setPedCanBeKnockedOffBike once.

No. Because the player can switch between arenas. So put this code in a function and call it everytime the player choose/select an arena:

function updateCanBeKnockedOffBike() 
    local arena = getElementData(localPlayer, "Arena") 
    if arena == "Stuntage"  then 
        setPedCanBeKnockedOffBike(localPlayer, false) 
    else 
        setPedCanBeKnockedOffBike(localPlayer, true) 
    end 
end 

Has to be on the client side ofc.

Thank you ! :)

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