Galactix Posted June 16, 2018 Share Posted June 16, 2018 (edited) Hello, I tried using the outputChatBox function on clientside using a triggerClientEvent but it outputs the messages to all online players. Client function heroinDrugOnMessage(theDrugPlayer) outputChatBox("You used heroin.", theDrugPlayer) end addEvent("heroinOnMessage", true) addEventHandler("heroinOnMessage", root, heroinDrugOnMessage) function heroinDrugOffMessage(theDrugPlayer) outputChatBox("The heroin effect has worn off.", theDrugPlayer) end addEvent("heroinOffMessage", true) addEventHandler("heroinOffMessage", root, heroinDrugOffMessage) Server function heroinDrugOn(player) theDrugPlayer = player setPlayerStat ( player, 24, 999) setTimer(heroinDrugOff, 60000,1) setElementHealth(player, 200) triggerClientEvent("heroinOnMessage", player) end addCommandHandler("useheroin", heroinDrugOn) --HEROIN DRUG EFFECT GOING OFF function heroinDrugOff(source,player) local playerHealth = getElementHealth(theDrugPlayer) setPlayerStat (theDrugPlayer, 24, 590) if (playerHealth > 100) then setElementHealth(theDrugPlayer, 100) else setElementHealth(theDrugPlayer, playerHealth) end triggerClientEvent("heroinOffMessage", theDrugPlayer) end Edited June 16, 2018 by Galactix Link to comment
itHyperoX Posted June 16, 2018 Share Posted June 16, 2018 function heroinDrugOff(source,player) local playerHealth = getElementHealth(theDrugPlayer) setPlayerStat (theDrugPlayer, 24, 590) if (playerHealth > 100) then setElementHealth(theDrugPlayer, 100) else setElementHealth(theDrugPlayer, playerHealth) end outputChatBox("yourmessages") end Link to comment
maximumdrive Posted June 16, 2018 Share Posted June 16, 2018 (edited) Hi Galactix, try triggering client events with your argument's places changed, e.g. triggerClientEvent(theDrugPlayer, heroinOffMessage) As the Wiki says, trigger-target should be written at first in the args list. Edited June 16, 2018 by maximumdrive Link to comment
Galactix Posted June 16, 2018 Author Share Posted June 16, 2018 I think I solved my problem, thanks for help! @TheMOG I don't understand what you did there… You just put the function on the serverside part which just does the same as I'm trying to avoid... @maximumdrive Oh, you're right, thanks for that, but on the wiki it was shown like this in the explanation: bool triggerClientEvent ( [table/element sendTo=getRootElement()], string name, element sourceElement, [arguments...] ) Required Arguments name: The name of the event to trigger client side. You should register this event with addEvent and add at least one event handler using addEventHandler. sourceElement: The element that is the source of the event. Event, then element targeted, but on the provided example it is actually how you say, so that's probably a mistake from whom made the page. Link to comment
Bonsai Posted June 17, 2018 Share Posted June 17, 2018 15 hours ago, Galactix said: I think I solved my problem, thanks for help! @TheMOG I don't understand what you did there… You just put the function on the serverside part which just does the same as I'm trying to avoid... @maximumdrive Oh, you're right, thanks for that, but on the wiki it was shown like this in the explanation: bool triggerClientEvent ( [table/element sendTo=getRootElement()], string name, element sourceElement, [arguments...] ) Required Arguments name: The name of the event to trigger client side. You should register this event with addEvent and add at least one event handler using addEventHandler. sourceElement: The element that is the source of the event. Event, then element targeted, but on the provided example it is actually how you say, so that's probably a mistake from whom made the page. That's indeed a little confusing, but it's because of the "sendTo" argument being optional (notice the [ ] brackets). You don't need to provide it, then root will be used. Link to comment
Galactix Posted June 17, 2018 Author Share Posted June 17, 2018 (edited) Thanks, that's good to know! Edited June 17, 2018 by Galactix 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