'LinKin Posted April 7, 2014 Share Posted April 7, 2014 Hello, I want to make a function server-side, so that it can be used by any resource I give access to without having to copy the function's implementation inside each resource. How can I do that? Also, When I do triggerServerEvent, is the event heard in other scripts? Or just in the script where the event was fired. Thanks. Link to comment
Driggero Posted April 7, 2014 Share Posted April 7, 2014 You have to export it inside the original resources' meta file, then use the exports function (call) to use it from other resources. As far as I know there is no way to actually hard-code it so you can just use it like the built in MTA functions though. Link to comment
Saml1er Posted April 7, 2014 Share Posted April 7, 2014 https://wiki.multitheftauto.com/wiki/Call Link to comment
'LinKin Posted April 7, 2014 Author Share Posted April 7, 2014 Thank you. Now "When I do triggerServerEvent, is the event heard in other scripts? Or just in the script where the event was fired." I ask this because I'm having a problem (like a small bug) with a script. Server-side Client-side * Lua tag wasn't working. And using code tag made it hard to read. The problem with that script is that sometimes, when the players are ready and are playing, the text is not removed from their screen. Link to comment
Saml1er Posted April 7, 2014 Share Posted April 7, 2014 Thank you.Now "When I do triggerServerEvent, is the event heard in other scripts? Or just in the script where the event was fired." I ask this because I'm having a problem (like a small bug) with a script. Server-side Client-side * Lua tag wasn't working. And using code tag made it hard to read. The problem with that script is that sometimes, when the players are ready and are playing, the text is not removed from their screen. TriggerEvent functions works inside a resource. You can't trigger events in other resources so for this purpose we use exports or this call function. Link to comment
'LinKin Posted April 7, 2014 Author Share Posted April 7, 2014 Hmm.. So what do you think the reason of this 'bug' is? Link to comment
Saml1er Posted April 7, 2014 Share Posted April 7, 2014 Hmm.. So what do you think the reason of this 'bug' is? This is not a bug. This is how lua works. When you download lua program for windows. We make resource in its root folder just like in mta and the main purpose for a resource is that the data doesn't mess up together. Link to comment
'LinKin Posted April 7, 2014 Author Share Posted April 7, 2014 The problem with that script is that sometimes, when the players are ready and are playing, the text is not removed from their screen. That's what I'm talking about. Is like if the client didn't fire the event.. I'm not sure about what's happening there Link to comment
arezu Posted April 8, 2014 Share Posted April 8, 2014 You are overriding waitDisplay, waitText1, waitText2, waitText3 and waitText4 everytime, so if a player joins and another player joins before the previous player has finished downloading, then the player that joined previously wont have his text destroyed. A table should've been used, but in this case, there is no need to create new text items and display for each player. local waitDisplay = textCreateDisplay() local waitText = {} waitText[1] = --textCreateTextItem(blablabla) waitText[2] = --textCreateTextItem(blablabla) waitText[3] = --textCreateTextItem(blablabla) waitText[4] = --textCreateTextItem(blablabla) for k, v in ipairs(waitText) do textDisplayAddText(waitDisplay, v) end addEventHandler("onPlayerJoin", root, function() showChat(source, false) textDisplayAddObserver(waitDisplay, source) end) addEvent("onClientReady", true) addEventHandler("onClientReady", root, function() textDisplayRemoveObserver(waitDisplay, source) end) Also, Use outputDebugString to see the flow of your script, so you can see if an event was really triggered or not. Link to comment
'LinKin Posted April 8, 2014 Author Share Posted April 8, 2014 Ahh yes arezu. I hadn't noticed that! Thank you Link to comment
Bonsai Posted April 8, 2014 Share Posted April 8, 2014 TriggerEvent functions works inside a resource. You can't trigger events in other resources so for this purpose we use exports or this call function. Actually you can Link to comment
Saml1er Posted April 8, 2014 Share Posted April 8, 2014 TriggerEvent functions works inside a resource. You can't trigger events in other resources so for this purpose we use exports or this call function. Actually you can Really? I've never even tested it but if thats true then why do we even use exports? 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