OnPlayerChat: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 3: Line 3:
This event is triggered when a player chats inside the chat box.
This event is triggered when a player chats inside the chat box.


==Supplied Variables==
==Syntax==  
'''[[player]]''': The player who typed the text.<br>
<syntaxhighlight lang="lua">
'''message''': The text that was typed.
void onPlayerChat( player tmpplayer, string message )         
</syntaxhighlight>


==Example==
==Variables==
  function [[onPlayerChat]] ( player, chat )
*'''player''': A player element refering to the player who used the pickup
  if ( [[strtok]] ( chat, 1, 32 ) == "!createhydra" ) then
*'''message''': A string representing the message typed into the chat
    x, y, z = [[getPlayerPosition]] ( player )
 
    [[createVehicle]] ( 520, x + 5, y, z )
===Canceling===
    [[playerPM]] ( player, "You got a hydra" )
If this event is [[Events#Canceling|canceled]], the game's chatsystem won't deliver the posts. Use [[outputChatBox]] to send the messages then.
  end
 
end
==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.
<syntaxhighlight lang="lua">
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
</syntaxhighlight>
 
==See Also==
{{Event_functions}}
* [[Gettok]]
* [[Split]]

Revision as of 17:11, 4 December 2006


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

Syntax

void onPlayerChat( player tmpplayer, string message )          

Variables

  • player: A player element refering to the player who used the pickup
  • message: A string representing the message typed into the chat

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