Chopper Posted September 28, 2013 Posted September 28, 2013 Hello Everyone. I recently figured out i have to use multiple files for my login system, and for that, my question is, how can i only execute the script from another file, only if the one before that is executed? For example, i have a gui window named test, in test.lua, and have a gui window named test2, in test2.lua. How is it possible to execute both, but only if test.lua has been executed? Thanks.
glowdemon1 Posted September 28, 2013 Posted September 28, 2013 https://wiki.multitheftauto.com/wiki/AddEvent https://wiki.multitheftauto.com/wiki/TriggerEvent https://wiki.multitheftauto.com/wiki/TriggerClientEvent That should do, addEvent and triggerEvent/triggerClientEvent, then use addEventHandler.
bandi94 Posted September 28, 2013 Posted September 28, 2013 If both are the same side : client / server. And you don't put in front of them "local" then you can use it like it was in the same file. Functions are shared in resource files so only call it from test.lua "test( argument)" if they are both the same side. If they are not then use. triggerClientEvent
Chopper Posted September 29, 2013 Author Posted September 29, 2013 Thanks. Does Events act like $_SESSION-s in PHP? because all i want to do, is a register system, and a skin system. i have these both, but i want the skin system to only execute, after the registration was successful. Any way how to do that? if its a dumb question, sorry. Im kinda new in lua.
glowdemon1 Posted September 29, 2013 Posted September 29, 2013 No clue about your first question. https://wiki.multitheftauto.com/wiki/SetTimer What I would do is create a function dedicated to the skin change, then setTimer(yourFunction, 5000,1) yourFunction = the function you want to execute 5000 = the time in miliseconds that the timer has to do before it executes yourFunction 1 = howmany times you want yourFunction to be executed, in this case only once.
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 PHP provides the session functions for storing, identifying and accessing data related to a user, across pages. Using HTTP, you tell the requested server who you are, and what you want. The server will respond with data based on your request, but from that point on, and to your next query, the server doesn't know whether you left the website. Sessions is a technique where you "build a bridge" between these two or more visits from the same client to the server. The server stores the related variables in a file or database, and reinitialises them each time the client is identified. In MTA, the client and server communicates all the time. That's why the server is able to determine when the client left the server. In which case all references to the player are nulled and the event onPlayerQuit is fired. Global variables, or local variables initialised in a global context, exist in memory from the resource start to the resource stop. Each resource is run as it's own "instance", within it's own Lua virtual machine. There are numerous ways to share data across resources, for example element data, resource exports or events. Creating and triggering an event triggers it across all resources. What you would do is, in your skin system, create and attach your functions to an event, "onPlayerRegistered" In your registration, once completed, trigger the event "onPlayerRegistered"
Chopper Posted September 29, 2013 Author Posted September 29, 2013 Thanks, got through that part. I have another question tho, is it possible to get the skin of a clientside ped in serverside? Because im trying to insert it into my mysql db, and i cant get the skin from client, to server. Also same with getPlayerName.
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 Peds created clientside - the referring element and all associated data such as skin are only available clientside. You would have to call getElementModel on the clientside and transfer the value to the server. Players aren't "client" or "server" -side. Players and related metadata is available to remote clients and server.
Chopper Posted September 29, 2013 Author Posted September 29, 2013 I know. Is there any way i can send the Skin ID with getPedSkin to server?
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 Events can also be used to transfer data between the server and the client. Read on addEvent (allowRemoteTrigger) It's better practice to use getElementModel versus getPedSkin. In the future most of those functions won't exist and will be replaced by more generic ones.
Chopper Posted September 29, 2013 Author Posted September 29, 2013 Still cant figure out, even tho you helped me, which im thankful for. What im trying to do is, getElementModel of a Ped thats created in clientside, get that data to serverside, and UPDATE the skin value, with the skin id. If i create an Event, in clientside, with getElementModel, how will i be able to return it to server, and insert it into the db?
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 The place where you add your event and handle it, is the "listener". Triggering the event transfers the data to the function. Serverside: addEvent ('server_GetSkinData', true) addEventHandler ('server_GetSkinData', root, function (skinID) -- source refers to the player element who invoked this event -- update SQL end ) Clientside: function sendPedSkinToServer (ped) local int_skin = getElementModel (ped) if not int_skin then return end triggerServerEvent ('server_GetSkinData', localPlayer, int_skin) end Any arguments parsed to triggerServerEvent, after the first two, go as arguments to the handler function. What are you using the ped model for, on the server?
Chopper Posted September 29, 2013 Author Posted September 29, 2013 Thanks. And im using it for login, which is already completed, it sents the players skin from the db.
Discord Moderators Zango Posted September 29, 2013 Discord Moderators Posted September 29, 2013 You might as well retrieve a player skin serverside. You only need to do this if you create a ped clientside. (and for whatever reason need it's model serverside)
Chopper Posted September 29, 2013 Author Posted September 29, 2013 I explained it wrong. My skin selection system is based on a ped, and it changes the skins on it. So i need to get that skin, and insert it into the db, as the players skin. ill try out the solution you posted.
Chopper Posted September 29, 2013 Author Posted September 29, 2013 I have a problem tho, as the resource starts, it automatically posts the skin ID, and not after i hit the button.
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