raynner Posted February 16, 2018 Share Posted February 16, 2018 Hello everyone Good friends I have a little doubt I do scripts for mta 3 years ago is from the beginning I wonder one thing about the server side. let's start, we all know that variables used on the server side have their value shared with the whole server. so I can dribble this problem I always create a table for each player so that I can set a variable with a separate value for each player plus the times I feel I do not need to do this anymore I'm not sure, keep reading. I know that Moon performs functions in an ordered way eg if two players call an execution of the same function according to my knowledge on the moon it should run the function twice, once for each right player? and here comes my doubt if I need to make a local variable that loses its value at the end of the function I can simply define a variable or I have to define it inside a table for each player. because although he gave to know how it works, I'm not sure if this gives me my doubts. the function is actually executed 1 time and as soon as it finishes it is executed again for the next player or it is performed doubly at the same time . I know this seems like an unnecessary question more is how I said my fear is by the value of the variables. Thanks Friends excuse me for English evil Link to comment
DNL291 Posted February 16, 2018 Share Posted February 16, 2018 I don't know exactly what you mean by "the variable is shared with the whole server", but just to clarify: A local variable is limited only to the script whereas a global variable is limited to the resource itself. I read the other part of your post like 5 times but unfortunately I didn't understand what you meant. I suggest you illustrate your question using a code. PS: When translating something to English, be careful about the Portuguese word "Lua" which is moon in English. Link to comment
raynner Posted February 16, 2018 Author Share Posted February 16, 2018 (edited) addEventHandler("onPlayerLogin", root, function() local Verific = true for i,v in ipairs(dbPoll(dbQuery(dbPlayer, "SELECT account FROM player"), -1)) do if tostring(v["account"]) == getAccountName(getPlayerAccount(source)) then Verific = false break end end if Verific then dbExec(dbPlayer, "INSERT INTO player DEFAULT VALUES") dbExec(dbPlayer, "UPDATE player SET account = ? WHERE ID = ?", getAccountName(getPlayerAccount(source)), getPlayerID()) end Verific = true UpdateData(source) end) see the variable "Verific" what I'm wondering is that every variable created on the server side has its equal value for all players. what I'm wondering is see this function if two players trigger the "onPlayerLogin" event at the same time. this function would be executed twice at the same time or it would run two times one after the other, you see? I know that Moon works the second way more despite mta using the language Lua I believe it does not work the same way! ie if this function is executed twice at the same time my variable (let's say with global value since the value is the same for all players) would not work as I planned and would have to do otherwise. all I want to know is if the client side functions are executed multiple times at the same time or one after the other (assuming it is called several times consecutively) this is my only question. Edited February 16, 2018 by raynner Link to comment
DNL291 Posted February 17, 2018 Share Posted February 17, 2018 (edited) onPlayerLogin is triggered when each player logs in and it gets executed for all players. About the variable, it's accessible only inside the event and this code looks fine from what I can see. 59 minutes ago, raynner said: all I want to know is if the client side functions are executed multiple times at the same time or one after the other (assuming it is called several times consecutively) this is my only question. Client-side functions works individually while the Server-side functions works globally, ie for all players at the same time. Edited February 17, 2018 by DNL291 Link to comment
raynner Posted February 17, 2018 Author Share Posted February 17, 2018 Do not you understand, you answered what I already know! I am talking about how the function is executed if it is called 2 times then it will be executed twice at the same time or it will be executed once and when it reaches the end of the block it will be executed again Link to comment
DNL291 Posted February 17, 2018 Share Posted February 17, 2018 7 minutes ago, raynner said: Do not you understand, you answered what I already know! I am talking about how the function is executed if it is called 2 times then it will be executed twice at the same time or it will be executed once and when it reaches the end of the block it will be executed again Relax, no need to act like a mentally unbalanced person. I'm sure I got what you said. I think you weren't able to understand how everything works. If you read carefully what I have explained, you will know that it should be executed like in the second way: 14 minutes ago, raynner said: it will be executed once and when it reaches the end of the block it will be executed again Link to comment
Captain Cody Posted February 17, 2018 Share Posted February 17, 2018 The scripts are executed in a priory fashion, if two scripts call it the first to call it runs first then the second. But even if they ran at the same time you defining 'local varliable = true' at the beginning of the function sets that variable local thus it doesn't leave the function. Link to comment
DNL291 Posted February 17, 2018 Share Posted February 17, 2018 (edited) Here's an example if you haven't understand yet: addEvent( "onPlayerWasted2" ) addEventHandler( "onPlayerWasted", root, function ( totalAmmo, killer ) triggerEvent( "onPlayerWasted2", source, killer ) end ) addEventHandler( "onPlayerWasted2", root, function ( killer ) outputChatBox( "hasKiller: "..tostring(hasKiller) ) -- output: "hasKiller: nil" local hasKiller = false if killer and isElement(killer) then hasKiller = true end end ) I've used a custom event so you can undestand with more ease how the event is called. Note that "onPlayerWasted2" won't get called at the same funcion for two players, so the variable "resets" each time the event is called. Edited February 17, 2018 by DNL291 Link to comment
raynner Posted February 18, 2018 Author Share Posted February 18, 2018 3 hours ago, DNL291 said: Here's an example if you haven't understand yet: addEvent( "onPlayerWasted2" ) addEventHandler( "onPlayerWasted", root, function ( totalAmmo, killer ) triggerEvent( "onPlayerWasted2", source, killer ) end ) addEventHandler( "onPlayerWasted2", root, function ( killer ) outputChatBox( "hasKiller: "..tostring(hasKiller) ) -- output: "hasKiller: nil" local hasKiller = false if killer and isElement(killer) then hasKiller = true end end ) I've used a custom event so you can undestand with more ease how the event is called. Note that "onPlayerWasted2" won't get called at the same funcion for two players, so the variable "resets" each time the event is called. Friend I know how it works I just had doubts about how the machine performed the function! Link to comment
NeXuS™ Posted February 19, 2018 Share Posted February 19, 2018 @raynner can you goddamn stop using my signature? Like you didn't even ask if you could use it. I made that GIF, if you want to use it, at least ASK. Link to comment
DNL291 Posted February 19, 2018 Share Posted February 19, 2018 (edited) raynner, I think you're contradicting yourself and so far you haven't been able to formulate your question correctly. On 16/02/2018 at 21:52, raynner said: see the variable "Verific" what I'm wondering is that every variable created on the server side has its equal value for all players. what I'm wondering is see this function if two players trigger the "onPlayerLogin" event at the same time. this function would be executed twice at the same time or it would run two times one after the other, you see? I know that Moon Lua works the second way Why the hell did you ask that question if you answered it yourself? On 16/02/2018 at 21:52, raynner said: despite mta using the language Lua I believe it does not work the same way! ie if this function is executed twice at the same time my variable (let's say with global value since the value is the same for all players) would not work as I planned and would have to do otherwise. If by "executed twice at the same time" you mean the function being called 2 times then you can see the example I posted above. If you think you're having some kind of problem with the variable, then show us how it's happening so we can help you fix that. On 17/02/2018 at 22:06, raynner said: Friend I know how it works I just had doubts about how the machine performed the function! Explain what exactly you want to know about the function execution process. Edited February 19, 2018 by DNL291 Link to comment
raynner Posted February 20, 2018 Author Share Posted February 20, 2018 On 18/02/2018 at 22:38, NeXuS™ said: @raynner can you goddamn stop using my signature? Like you didn't even ask if you could use it. I made that GIF, if you want to use it, at least ASK. What men ? right in image ? I got this gif on the internet! drop it Link to comment
NeXuS™ Posted February 20, 2018 Share Posted February 20, 2018 You didnt get that GIF on the internet. It is exactly mine, and is redirected onto my UPLOAD. Link to comment
raynner Posted February 21, 2018 Author Share Posted February 21, 2018 17 hours ago, NeXuS™ said: You didnt get that GIF on the internet. It is exactly mine, and is redirected onto my UPLOAD. Ok friend, I do not think this show is necessary, I'll remove it. 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