Jump to content

Private Message


Shikken

Recommended Posts

Hi i want to send private message to chosen player by gui.

Here is the code of button click in gui:

addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
function ( )
if (source == GUIEditor_Button[1]) then
local playerName = guiGridListGetItemText ( GUIEditor_Grid[1], guiGridListGetSelectedItem ( GUIEditor_Grid[1] ), 1 )
local text = guiGetText ( GUIEditor_Edit[1] )
local localPlayerName = getPlayerName(getLocalPlayer())
local sendstring = ("PM " .. localPlayerName .. " : " .. text)
triggerServerEvent ( "privateevent", getRootElement( playerName ), sendstring ) 
end
 
end
end
)

Here is the code on server-side:

function sendprivatemessage ( message )
outputChatBox ( message, source, 255, 255, 0, true )
end
addEvent( "privateevent", true )
addEventHandler( "privateevent", getRootElement( playerName ), sendprivatemessage )

outputChatBox is visible to all players, how i can make it visible only for the chosen player?

Link to comment

Just send the player name to the server and let the server take care of getting player element from his name.

You say you get an error but you didn't say what is the message of the error. What is it?

EDIT:

Do NOT double post unless you have good reason. Be patient and someone will reply. It's not a chat channel... it's forum.

Link to comment
Just send the player name to the server and let the server take care of getting player element from his name.

You say you get an error but you didn't say what is the message of the error. What is it?

EDIT:

Do NOT double post unless you have good reason. Be patient and someone will reply. It's not a chat channel... it's forum.

It work's now, thanks everyone for help.

Sorry for double post.

Link to comment
function sendprivatemessage ( playername, message )
local playerToSendTo = getPlayerFronNick( playername );
if( playerToSendTo ) then
outputChatBox ( "PM "..getPlayerName( client ) .. ": ".. message, playerToSendTo, 255, 255, 0, true );
end
end
addEvent( "privateevent", true );
addEventHandler( "privateevent", getRootElement(), sendprivatemessage );

and also,

triggerServerEvent( "privateevent", getRootElement(), playerName, text )

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