Jump to content

[HELP] GUI triggering server event


Galactix

Recommended Posts

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
  • Discord Moderators

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

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...