
aintaro
Members-
Posts
135 -
Joined
-
Last visited
Everything posted by aintaro
-
Hello, Today I will be explaining why you should stop use setElementData and how to stop using it. Why should you stop using setElementData? As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. How to stop using setElementData? Example : Lets say you want to save the total time of a player most people will do it like this : local timePlayed = 0 --declare a variable timePlayed for every player function initPlayer() setElementData(thePlayer, "player_time", timePlayed) --we set the elementData player_time to timePlayed end THATS WRONG! This is how you should do it : local playerData = { --declare playerData for all the players data timePlayed = {} --first dataType = timePlayed } function initPlayer() playerData.timePlayed[thePlayer] = 0 --set timePlayed of "thePlayer" to 0 end playerData.timePlayed[thePlayer] = 0 --set timePlayed of "thePlayer" to 0 this will set timePlayed only to thePlayer userdata PROOF : for i = 1, 10000 do setElementData(thePlayer, "test"..tostring(i), 1000) end execute time : 47 ticks for i = 1, 10000 do setElementData(thePlayer, "test"..tostring(i), 1000,false) end execute time : 40 ticks for i = 1, 10000 do playerData[thePlayer][i] = 1000 end execute time : 1 tick thanks for reading, any questions can be posted under!
-
Just use cancelEvent () on the event : onClientWeaponFire ()
-
thanks man, this is what I needed Stop lying Arezu...
-
setPlayerNametagColor ( thePlayer, 0, 102, 204) should be : setPlayerNametagColor ( source, 0, 102, 204)
-
Did you even test it? I tested it and it works. Here's my test (ran server-side): local timer = nil timer = setTimer(function() outputDebugString("update!") killTimer(timer) end, 1000, 0) Closures in lua uses reference to outside variables, and if the scope ends before closure is called, then the variable is saved until the closures have been "free'd" from memory.. I guess that is kinda how closures work in lua. As a test, I made a script like this: local timer = nil local count = 0 timer = setTimer(function() outputDebugString(tostring(count)) count = 2 end, 1000, 1) count = 1 setTimer(function() outputDebugString("second timer: "..tostring(count)) count = 3 end, 3000, 1) The output was: 1 second timer: 2 I was talking about this code : function test() local timer = 10 local theTimer = setTimer(function( selfTimer ) -- receive theTimer as selfTimer if (timer > 0) then timer = timer - 1 else killTimer(selfTimer) end end, 1000, 0, theTimer) --give theTimer as function parameter end try that and tell me it works..
-
thanks man, this is what I needed This is dirty !!! + it will produce bugs if you are on the server side (since the exact same global will be used by every players and possibly at the exact same time for 2 of them). This is what you should do (as myonlake sugested): function test() local timer = 10 local theTimer = setTimer(function( selfTimer ) -- receive theTimer as selfTimer if (timer > 0) then timer = timer - 1 else killTimer(selfTimer) end end, 1000, 0, theTimer) --give theTimer as function parameter end local Timer = nil; Timer = setTimer(function() killTimer(Timer); end,1000,1); this is not dirty at all, Whenever the function gets called, local Timer gets a new slot in the memory, so it's never the same timer, even if multiple players execute the function. So please test code before you comment
-
Back online!
-
let's say you want a certain value to be higher than 0 to keep executing the the timer something like this : setTimer(function() if (health > 0 and health < 50) then --execute code here else -- kill timer here end end, 1000, 0) Somethimes you need to kill a timer within it's function as you do not know how many times the timer has to tick
-
Try different name then int when declaring it in the array
-
Just use sqlLite, I find it alot easier with executeSQLQuery (query)
-
Root executes faster than getrootelement () so thats why I was wondering if it could make a difference
-
That is not going to work unless you declare the Timer variable one line before. local Timer = nil; Timer = setTimer(function(self) outputChatBox(self); --> userdata; end,1000,1,Timer); local Timer = setTimer(function(self) outputChatBox(self); --> nil; end,1000,1,Timer); Dude, did you even test your code? it's not working at all. stop posting code that you didn't even bother to test. Thanks
-
Code not working
-
Hello, What is the most efficient code : EXAMPLE 1 triggerClientEvent("eventName", getResourceRootElement(getThisResource()), afunction) triggerClientEvent("eventName", getRootElement(), afunction) thanks in advance, Greetz, Aintaro!
-
thanks man, this is what I needed
-
When you kill a timer within it's function it does not work.
-
Hello, How can I stop a timer within a timer, here is an example to make it clear : function test() local timer = 10 local theTimer = setTimer(function() if (timer > 0) then timer = timer - 1 else --KILLTIMER HERE (already tried killTimer within the function, did not work) end end, 1000, 0) end
-
Streamed for about 5-6 hours today, thanks for watching for the people who were watching my progress!
-
back online
-
Back Online
-
just log the player out when he disconnects for more than a second or something
-
to loop through all the players is like this : local players = getElementsByType ( "player" ) -- Get every player for k, player in ipairs ( players ) do -- For every player do the following... account = getPlayerAccount ( player ) -- Get every player's account if ( not isGuestAccount ( account ) ) then -- For every player that's logged in.... outputChatBox("this is a message to all the players", player) end end
-
when I use this element on a vehicle, my vehicle just floats in the air... That function is bugged on the server side, you have to use the function I posted. Thanks man, I used yours, going to test it soon