FuriouZ Posted March 9, 2014 Share Posted March 9, 2014 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 ? Link to comment
Dealman Posted March 9, 2014 Share Posted March 9, 2014 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 Link to comment
ixjf Posted March 9, 2014 Share Posted March 9, 2014 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. Link to comment
Moderators Citizen Posted March 9, 2014 Moderators Share Posted March 9, 2014 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. Link to comment
Moderators Citizen Posted March 9, 2014 Moderators Share Posted March 9, 2014 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. Link to comment
ixjf Posted March 9, 2014 Share Posted March 9, 2014 You misunderstood it - "call it once" as in call it whenever needed, not every frame. Link to comment
FuriouZ Posted March 9, 2014 Author Share Posted March 9, 2014 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 ! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now