Galactix Posted June 30, 2018 Share Posted June 30, 2018 Hello, I'm trying to get my GUI to trigger a server event but I can't manage to find how to send the actual player element needed by the function to work. --HEROIN DRUG EFFECT ON function heroinDrugOn(player) local oldHeroinCount = getElementData ( player, "Heroin" ) local heroinStatus = getElementData (player, "heroinStatus") if heroinStatus ~= true then if oldHeroinCount ~= false then setElementData(player, "heroinStatus", true) setElementData ( player, "Heroin", oldHeroinCount-1 ) setPedStat ( player, 24, 1000) setElementHealth(player, 200) setTimer(heroinDrugOff, 60000, 1, player) triggerClientEvent ( player, "heroinOnMessage", root) else triggerClientEvent ( player, "heroinNotEnough", root) return end else triggerClientEvent (player, "heroinCooldownMessage", root) end end addCommandHandler("useheroin", heroinDrugOn) addEvent("useHeroin", true) addEventHandler("useHeroin", root, heroinDrugOn) And I use: triggerServerEvent ( "useHeroin", localPlayer) Link to comment
Mr.Loki Posted June 30, 2018 Share Posted June 30, 2018 You set the localPlayer as the source of the event. Link to comment
Galactix Posted June 30, 2018 Author Share Posted June 30, 2018 3 hours ago, Mr.Loki said: You set the localPlayer as the source of the event. Yes, that's pretty obvious thanks, but then what do I put instead? Link to comment
Discord Moderators Pirulax Posted July 1, 2018 Discord Moderators Share Posted July 1, 2018 Hello. In MTA you have some predefined variables, but for security reasons, if you want to apply something to the player who triggered the event(actually, to that client) then just use the variable 'client'. These are variables that are 'hiddenly' defined, but you can use them. To fix your problem just remove the 'player' argument from the function, and replace every other 'player' argument to 'client' And use debugscript Link to comment
Galactix Posted July 1, 2018 Author Share Posted July 1, 2018 Thanks Pirulax, but now it says at line 6 that I am trying to compare a boolean with a number, so why isn't the oldHeroinCount variable acquired properly? Link to comment
Mr.Loki Posted July 1, 2018 Share Posted July 1, 2018 That's because the elementData for "Heroin" is a number and you are checking if it's true or false. You should just use: if oldHeroinCount > 0 then Link to comment
Galactix Posted July 1, 2018 Author Share Posted July 1, 2018 7 hours ago, Mr.Loki said: That's because the elementData for "Heroin" is a number and you are checking if it's true or false. You should just use: if oldHeroinCount > 0 then Yeah, I managed to solve that myself but thanks 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