Jump to content

Question about Multiple Files


Chopper

Recommended Posts

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.

Link to comment

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 

Link to comment

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.

Link to comment

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.

Link to comment
  • Discord Moderators

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"

Link to comment
  • Discord Moderators

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.

Link to comment
  • Discord Moderators

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.

Link to comment

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?

Link to comment
  • Discord Moderators

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?

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...