Sscanf Shared function

From Gothic 2 Online: Wiki
Jump to navigation Jump to search

This function was added in version: 0.0.0

The function splits the specified text, interprets it according to format and stores the results into array.

Syntax

array sscanf(string format, string text)

Required Arguments

  • format: The format by which the text will be splitted.

Each letter in the format represents one argument in the text.
If the number of letters in the format will be greater than the number of arguments in the text, then function will fail.
Currently supported data formats:

d: integer value. Example 123532.
f: float value. Example 56.2353.
s: string. Example "Gothic 2 Online :)".
  • text: The string which will be splited into arguments.

Returns

  • array: The function returns array which contains splitted texts.

Example

Server-side:

local function commandHandler(pid, cmd, params)
{
	if (cmd == "time")
		local args = sscanf("dd",params);
		if (args)
		{
			setTime(args[0], args[1]);
			sendMessageToPlayer(pid, 255, 255, 255, "The current time: " + args[0] + ":" + args[1]);
		}
		else
			sendMessageToPlayer(pid, 255, 0, 0, "Type: /time (hour) (min)");
}

addEventHandler("onPlayerCommand", commandHandler);

Client-side:

local function commandHandler(cmd, params)
{
	if (cmd == "face")
		local args = sscanf("d",params);
		if (args)
		{
			local vis = getPlayerVisual(heroId);
			setPlayerVisual(heroId,bodyModel,bodyTxt,headModel,args[0]);
			print("Now you are Mr. Two-Faced");
		}
		else
			print("Type: /face (number of face [0-164])");

}

addEventHandler("onCommand", commandHandler);

Related functions