Jump to content

[HELP] Clientside outputChatBox


Galactix

Recommended Posts

Posted (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 by Galactix
Posted
  1. 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
Posted (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 by maximumdrive
Posted

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.

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

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