Shikken Posted July 19, 2009 Share Posted July 19, 2009 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
Gamesnert Posted July 19, 2009 Share Posted July 19, 2009 triggerServerEvent ( "privateevent", targetplayerelementrightoverhere, sendstring ) Seeing from the variable names, it seems like it should be: triggerServerEvent ( "privateevent", getPlayerFromNick(playerName), sendstring ) Link to comment
Shikken Posted July 19, 2009 Author Share Posted July 19, 2009 I tried GetPlayerFromNick and GetPlayerName, but still it gives me an error, or it's visible to evrybody, any new ideas? Link to comment
Shikken Posted July 19, 2009 Author Share Posted July 19, 2009 Cmon does someone know how to do it? Link to comment
50p Posted July 19, 2009 Share Posted July 19, 2009 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
Shikken Posted July 19, 2009 Author Share Posted July 19, 2009 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
50p Posted July 19, 2009 Share Posted July 19, 2009 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
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