OnPlayerChat: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(fixed syntax)
No edit summary
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onPlayerChat( string message, bool teamchat )           
void onPlayerChat ( string message, int type )           
</syntaxhighlight>  
</syntaxhighlight>  


Line 11: Line 11:
*'''player''': A player element refering to the player who is chatting the message
*'''player''': A player element refering to the player who is chatting the message
*'''message''': A string representing the message typed into the chat
*'''message''': A string representing the message typed into the chat
*'''type''': An integer value representing the chat type:
*''0'': normal
*''1'': action (/me)
*''2'': team


===Canceling===
===Canceling===

Revision as of 13:56, 4 May 2007


This event is triggered when a player chats inside the chat box.

Syntax

void onPlayerChat ( string message, int type )          

Variables

  • player: A player element refering to the player who is chatting the message
  • message: A string representing the message typed into the chat
  • type: An integer value representing the chat type:
  • 0: normal
  • 1: action (/me)
  • 2: team

Canceling

If this event is canceled, the game's chatsystem won't deliver the posts. Use outputChatBox to send the messages then.

Example

This example adds the /me command into the script. For example, if a player called Bob types "me likes pie" in console, it will display "* Bob likes pie" in the chatbox.

addEventHandler ( "onPlayerChat ", getRootElement(), "onPlayerChat" ) -- add an event handler for onPlayerChat
function onPlayerChat ( player, message )
  if ( strtok ( message , 1, 32 ) == "!createhydra" ) then
    x, y, z = getElementPosition ( player )
    createVehicle ( 520, x + 5, y, z )
    outputChatBox("You got a hydra",player)
  end
end

See Also