Gettok: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
Line 11: Line 11:


==Example==
==Example==
  function onPlayerChat ( player, chat )
  function [[onPlayerChat]] ( player, chat )
   if (gettok (chat, 1, " ")) == "!createhydra")
   if ([[gettok]] (chat, 1, " ")) == "!createhydra")
     x, y, z = getPlayerPosition ( player )
     x, y, z = [[getPlayerPosition]] ( player )
     createVehicle ( 520, x + 5, y, z )
     [[createVehicle]] ( 520, x + 5, y, z )
     playerPM ( player, "You got a hydra" )
     [[playerPM]] ( player, "You got a hydra" )
   end
   end
  end
  end

Revision as of 05:15, 31 March 2006

Description

This function splits a string into sub-strings. You specify a character that will act as a separating character; this will determine where to split the sub-strings.

For example, you could split up the string "This is a sentence", using spaces as separators. This would return "This","is","a","sentence". Each sub-string is assigned an ID number ascending from 1. In this example, ID 2 would return "is".

This function is commonly used to check the first word against a list of known commands. If the command is found, all subsequent words will be used as arguments.

Syntax

string Gettok ( string string, int index, string separatingchar)

Example

function onPlayerChat ( player, chat )
 if (gettok (chat, 1, " ")) == "!createhydra")
   x, y, z = getPlayerPosition ( player )
   createVehicle ( 520, x + 5, y, z )
   playerPM ( player, "You got a hydra" )
 end
end