Zuher Laith Posted October 31, 2017 Share Posted October 31, 2017 Hi .. I'm wondering about the server side and the client side, what's the difference between them in code ? for my case, I am using bone_attach mod and attached a case to the localPlayer, whats the difference if I wrote it in client side, or server side ? will it show up to the people If I attached it in the client side ?, Please provide me with information as much as possible. Thanks in Advance Link to comment
Moderators IIYAMA Posted October 31, 2017 Moderators Share Posted October 31, 2017 Serverside is running on the 'server' computer and clientside is running on the pc you use to play mta. If you use a local server. They both run on the same computer but in a different environment. Summary Serverside = server computer (or on your game pc in a different environment) Clientside = game pc They play their own roll and have to communicate between each other, in order to move information from one computer to another. The rest speaks for itself. 1 Link to comment
Zuher Laith Posted October 31, 2017 Author Share Posted October 31, 2017 51 minutes ago, IIYAMA said: They play their own roll and have to communicate between each other, in order to move information from one computer to another. I guess I get it now, but still I had a problem in the server side, thePlayer or source doesn't work but client did, let me explain it in code: -- Client side triggerServerEvent ( "takeCash", resourceRoot, 2 ) -- takes $2 of the player -- Server side function takeCashHandler ( thePlayer, amount ) takePlayerMoney ( thePlayer, tonumber(amount) ) end addEvent( "takeCash", true ) addEventHandler( "takeCash", resourceRoot, takeCashHandler ) Whats the problem in this?, and could you please clarify thePlayer, source, client and how to use them right in both sides ? Appreciate your help . Link to comment
Moderators IIYAMA Posted October 31, 2017 Moderators Share Posted October 31, 2017 (edited) Lets start with the basics example -- < this is a variable thisPlayer -- < this too hi -- < and this, etc. First of all, variables CAN CONTAIN any value. The name does not define what value it contains, unless it is predefined. So the variable thePlayer does not have to contain a player value. It can be anything, it is just a name where you can assign a value to. example = "nice" -- it can contain a string example = false -- or a boolean example = 12345 -- or a number example = {} -- a table -- and more! Here you have a list with predefined variables: This is the list of the predefined variables from MTA(written down by Kenix) Spoiler MTA predefined variables. Hide contents Shared exports -- returns a table of resource names containing all export functions resource -- returns a resource element of the resource the snippet was executed in resourceRoot -- returns a resource root element of the resource the snippet was executed in root -- returns the all elements Client only guiRoot -- returns the root element all GUI elements. localPlayer -- returns the player element of the local player. List hidden local variables, that can be in functions-handlers: Shared source -- The player or element the event was attached to this -- Element, which was attached function-handler. eventName -- the name of the event ("onResourceStart", "onPlayerWasted" etc.) Server only client -- the client that called the event sourceResourceRoot -- the root of the resource that called the event sourceResource -- the resource that called the event Those variables contain the values that are declared before your script is loaded. Yet some of them do only contain values under special conditions. You can find those conditions in the comments behind the variables. SO PLEASE, there is NO thePlayer. It does not exist by itself. Now to get back to your issue. There is a predefined variable localPlayer, please check the list again. It is YOU and your adorable ped element. (clientside only) If we visit this page: https://wiki.multitheftauto.com/wiki/TriggerServerEvent You can see the required arguments: Required Arguments event: The name of the event to trigger server-side. You should register this event with addEvent and add at least one event handler using addEventHandler. theElement: The element that is the source of the event. The event: "takeCash" And the source element: resourceRoot The source element is a predefined variable, which will be come active after triggering an addEventHandler. function takeCashHandler ( thePlayer, amount ) iprint(source) -- resourceRoot end `source` is NOT a parameter. Parameters are the variables that be found here: takeCashHandler (<parameter>, <AND parameter>, <ETC.>) The special thing about parameters is that they contain the values that are given from the place where the function is called from. (see example below) For the ones that are using the `source` as parameter, they are not consistent and will confuse other people if they share their code. Using source as parameter will overwrite it's value if already set. If I call your function with a normal call, it would looks like this: function takeCashHandler ( thePlayer, amount ) takePlayerMoney ( thePlayer, tonumber(amount) ) end local randomPlayer = getRandomPlayer() takeCashHandler (randomPlayer , 2 ) -- calling the function takeCashHandler The first parameter receives the first value <just a random player in the server>. The second parameter receives the second number value 2. Order matters, name does NOT! In this code we give two parameters a value. The value of the predefined variable `localPlayer` and a number value 2. -- Client side triggerServerEvent ( "takeCash", resourceRoot, localPlayer, 2 ) -- takes $2 of the player -- Server side function takeCashHandler ( thePlayer, amount ) takePlayerMoney ( thePlayer, tonumber(amount) ) end addEvent( "takeCash", true ) addEventHandler( "takeCash", resourceRoot, takeCashHandler ) There is also the predefined variable `client` which you could use. Which represents the player (element) that has called the server. But only is defined when an addEventHandler exist and has been used. Edited October 31, 2017 by IIYAMA 2 Link to comment
Zuher Laith Posted October 31, 2017 Author Share Posted October 31, 2017 @IIYAMA Too much good information!, I've looked at every thing you said and its really helpful to me, I'm gonna favorite this to be honest . you are awesome .. Thank you so much for help & time . 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