samp.directory
← Scripts y librerías

Y-Less/sscanf

SA:MP sscanf plugin originally made by @Y-Less

Plugin★ 144actualizado ene 2024OtherCsampctl
Abrir en GitHub

Instalar con sampctl

sampctl package install Y-Less/sscanf

Ejecútalo en la carpeta de tu proyecto. sampctl descarga el paquete y sus dependencias.

README.md

sscanf 2.15.1

Introduction

This is the sscanf plugin, which provides the sscanf function to extract basic structured data from strings. This is slightly different to regular expressions, but both have their place. A regular expression gives you total control over the exact structure of data down to the character level; however, extracting structured data like numbers using it is tricky. Conversely this gives slightly higher-level "specifiers" which can easily extract data types, at the expense of fine-grained control. To convert a string in to two numbers would look like:

new num1, num2;
sscanf("45 100", "ii", num1, num2);

ii is the specifier string, which here means "integer integer"; stating that the input string should be two whole numbers in a row (which is - "45 100"). num1 and num2 are the destination variables to store the found numbers in (after conversion from strings). You can check if the conversion failed by looking for a non-naught return value:

new num1, num2;
if (sscanf("hello 100", "ii", num1, num2))
{
	printf("The input was not two numbers.");
}

This will fail because "hello" is not a whole number (or indeed any type of number at all). For more information on using the function refer to the tutorials or the reference documentation below:

Contents

Downloads

GitHub repo:

https://github.com/Y-Less/sscanf/

Use

Scripting

This behaves exactly as the old sscanf did, just MUCH faster and much more flexibly. To use it add:

#include <sscanf2>

To your modes and remove the old sscanf (the new include will detect the old version and throw an error if it is detected).

The basic code looks like:

if (sscanf(params, "ui", giveplayerid, amount))
{
    return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash <playerid/name> <amount>");
}

However it should be noted that sscanf can be used for any text processing you like. For example an ini processor could look like (don't worry about what the bits mean at this stage):

if (sscanf(szFileLine, "p<=>s[8]s[32]", szIniName, szIniValue))
{
    printf("Invalid INI format line");
}

There is also an alternate function name to avoid confusion with the C standard sscanf:

if (unformat(params, "ui", giveplayerid, amount))
{
    return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash <playerid/name> <amount>");
}

open.mp

The sscanf binary (sscanf.dll on Windows, or sscanf.so on Linux) works as both a legacy (SA:MP) plugin or an open.mp component. The recommended method is to use it as a component - just place the file in the components directory in the server root and open.mp will load it automatically.

If you wish to use it as a legacy plugin for some reason (there is no need if you are on version 2.12.1 or higher) place it in the plugins directory in the open.mp server root and either follow the SA:MP-specific instructions for server.cfg on your platform or add "sscanf" to "pawn.legacy_plugins" in config.json:

{
	"pawn":
	{
		"legacy_plugins":
		[
			"sscanf"
		]
	}
}

SA:MP Windows

Add sscanf to the start of the plugins line in server.cfg. For example:

plugins sscanf streamer crashdetect

If there isn't a plugins line already, add one:

plugins sscanf

You must also place sscanf.dll in the plugins subdirectory of the server. If there isn't a plugins directory, create one.

SA:MP Linux

Add sscanf.so to the start of the plugins line in server.cfg. For example:

Leer el resto en GitHub

cppsa-mpsscanf

Esta página se genera con lo que GitHub publica sobre el repositorio. samp.directory no aloja el código. Informar de un problema con esta ficha

Y-Less/sscanf: Plugin de SA-MP | samp.directory