Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 647 online users. » 0 Member(s) | 645 Guest(s) Bing, Google
|
Latest Threads |
Command does not work in-...
Forum: Pawn Scripting
Last Post: PANZEHIR_
10 hours ago
» Replies: 0
» Views: 22
|
White Screen
Forum: Support
Last Post: Phat202146_real
2024-11-21, 02:50 PM
» Replies: 0
» Views: 30
|
I get error 021 using y_h...
Forum: Pawn Scripting
Last Post: daniscript18
2024-11-18, 11:34 PM
» Replies: 0
» Views: 49
|
Il reste des français sur...
Forum: French/Fran?ais
Last Post: tysanio
2024-11-18, 05:39 AM
» Replies: 2
» Views: 450
|
Object creation issues
Forum: Programming
Last Post: K1271
2024-11-15, 11:51 PM
» Replies: 0
» Views: 48
|
Is the SAMP Hosting the s...
Forum: General Discussions
Last Post: OperaGX
2024-11-14, 09:33 PM
» Replies: 0
» Views: 64
|
Run time error 19: "File ...
Forum: Pawn Scripting
Last Post: Rexey
2024-11-14, 03:50 AM
» Replies: 0
» Views: 59
|
How to Compile Your Gamem...
Forum: Tutorials
Last Post: thelante
2024-11-13, 08:50 AM
» Replies: 3
» Views: 452
|
Modeller wanted
Forum: Development Updates
Last Post: acc.gangbeni
2024-11-11, 05:10 PM
» Replies: 9
» Views: 16,458
|
SA:MP forum offline
Forum: Portuguese/Portugu?s
Last Post: weslley_script
2024-11-09, 05:27 PM
» Replies: 7
» Views: 9,900
|
|
|
sscanf |
Posted by: Y_Less - 2019-04-21, 11:34 PM - Forum: Plugins
- Replies (8)
|
|
sscanf 2.8.2
NPC modes
To use sscanf in an NPC mode, download this file:
http://dl.dropbox.com/u/21683085/npcdll.rar
And extract it to your root server directory (so "amxsscanf.dll" is in the same directory as "samp-npc.exe"). Then use as normal. The only tiny difference is that "u", "r", and "q" don't know if a user is a bot or not, so just assume they are all players - use accordingly.
Downloads
GitHub repo (for sscanf 3):
https://github.com/maddinat0r/sscanf/releases
Source, Windows .dll, Linux .so and include:
https://dl.dropboxusercontent.com/u/1025...-2.8.2.zip
Use
This behaves exactly as the old sscanf did, just MUCH faster and much more flexibly. To use it add:
To your modes and remove the old sscanf (the new include will detect the old version and throw an error if it is detected). On windows add:
To server.cfg. On Linux add:
The basic code looks like:
PHP Code: 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):
PHP Code: 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:
PHP Code: if (unformat(params, "ui", giveplayerid, amount)) { ? ?return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash <playerid/name> <amount>"); }
Specifiers
The available specifiers (the letters "u", "i" and "s" in the codes above) are below.
? ?
Code: Specifier(s) ? ? ? ? ? ? ? Name ? ? ? ? ? ? ? ? ? Example values
? ?i, d ? ? ? ? Integer ? ? ? ? ? ? ? ? ? ? ? ? ? ?1, 42, -10
? ?c ? ? ? ? ? ?Character ? ? ? ? ? ? ? ? ? ? ? ? ?a, o, *
? ?l ? ? ? ? ? ?Logical ? ? ? ? ? ? ? ? ? ? ? ? ? ?true, false
? ?b ? ? ? ? ? ?Binary ? ? ? ? ? ? ? ? ? ? ? ? ? ? 01001, 0b1100
? ?h, x ? ? ? ? Hex ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1A, 0x23
? ?o ? ? ? ? ? ?Octal ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?045 12
? ?n ? ? ? ? ? ?Number ? ? ? ? ? ? ? ? ? ? ? ? ? ? 42, 0b010, 0xAC, 045
? ?f ? ? ? ? ? ?Float ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0.7, -99.5
? ?g ? ? ? ? ? ?IEEE Float ? ? ? ? ? ? ? ? ? ? ? ? 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E
? ?u ? ? ? ? ? ?User name/id (bots and players) ? ?Y_Less, 0
? ?q ? ? ? ? ? ?Bot name/id ? ? ? ? ? ? ? ? ? ? ? ?ShopBot, 27
? ?r ? ? ? ? ? ?Player name/id ? ? ? ? ? ? ? ? ? ? Y_Less, 42
? ?
The specifier "s" is used, as before, for strings - but they are now more advanced. As before they support collection, so doing:
PHP Code: sscanf("hello 27", "si", str, val);
Will give:
Doing:
PHP Code: sscanf("hello there 27", "si", str, val);
Will fail as "there" is not a number. However doing:
PHP Code: sscanf("hello there", "s", str);
Will give:
Because there is nothing after "s" in the specifier, the string gets everything. To stop this simply add a space:
PHP Code: sscanf("hello there", "s ", str);
Will give:
You can also escape parts of strings with "\\" - note that it is two backslashes as 1 is used by the compiler:
PHP Code: sscanf("hello\\ there 27", "si", str, val);
Will give:
All these examples however will give warnings in the server as the new version has array sizes. The above code should be:
PHP Code: new ? ?str[32], ? ?val; sscanf("hello\\ there 27", "s[32]i", str, val);
As you can see - the format specifier now contains the length of the target string, ensuring that you can never have your strings overflow and cause problems. This can be combined with the SA:MP compiler's stringizing:
PHP Code: #define STR_SIZE 32 new ? ?str[STR_SIZE], ? ?val; sscanf("hello\\ there 27", "s[" #STR_SIZE "]i", str, val);
So when you change your string size you don't need to change your specifiers.
What happened to "z", the optional string? z has been removed (you can still use it but will get a server warning) to make way for the new optional parameter system described later on.
? ?
One of the advanced new specifiers is "a", which creates an array, obviously. The syntax is similar to that of strings and, as you will see later, the delimiter code:
PHP Code: new ? ?arr[5]; sscanf("1 2 3 4 5", "a<i>[5]", arr);
The "a" specifier is immediately followed by a single type enclosed in angle brackets - this type can be any of the basic types listed above. It is the followed, as with strings now, by an array size. The code above will put the numbers 1 to 5 into the 5 indexes of the "arr" array variable.
Arrays can now also be combined with strings (see below), specifying the string size in the array type:
This will produce an array of 12 strings, each up to 10 characters long (9 NULL). Optional string arrays still follow the optional array syntax:
However, unlike numbers you can't specify a progression and have it fill up. This code:
Will by default produce:
However, this code:
Code: A<s[10]>(hi, there)[4]
Will by default produce:
Code: "hi, there", "hi, there", "hi, there", "hi, there"
As normal, you can add brackets in to the default string value with "\)":
Code: A<s[10]>(hi (code\))[4]
It should also be noted that there is NO length checking on default strings. If you do:
Code: A<s[10]>(This is longer than 10 characters)[4]
You will probably just corrupt the PAWN stack. The length checking is to ensure no users enter malicious data; however, in this case it is up to the scripter to ensure that the data is correct as they are the only one affecting it and shouldn't be trying to crash their own server. Interestingly, arrays of strings actually also work with jagged arrays and arrays that have been shuffled by Slice's quicksort function (this isn't a side-effect, I specifically wrote them to do so).
? ?
This is possibly the most powerful addition to sscanf ever. This gives you the ability to define the structure of an enum within your specifier string and read any data straight into it. The format takes after that of arrays, but with more types - and you can include strings in enums (but not other enums or arrays):
PHP Code: enum ? ?E_DATA { ? ?E_DATA_C, ? ?Float:E_DATA_X, ? ?E_DATA_NAME[32], ? ?E_DATA_Z }
main { ? ?new ? ? ? ?var[E_DATA]; ? ?sscanf("1 12.0 Bob c", "e<ifs[32]c>", var); }
Now I'll be impressed if you can read that code straight off, so I'll explain it slowly:
PHP Code: e - Start of the "enum" type < - Starts the specification of the structure of the enum i - An integer, corresponds with E_DATA_C f - A float, corresponds with E_DATA_X s[32] - A 32 cell string, corresponds with E_DATA_NAME c - A character, corresponds with E_DATA_Z > - End of the enum specification
Note that an enum doesn't require a size like arrays and strings - it's size is determined by the number and size of the types. Most, but not all, specifiers can be used inside enums (notably arrays and other enums can't be).
? ?
The two new specifiers "{" and "}" are used for what are known as "quiet" strings. These are strings which are read and checked, but not saved. For example:
PHP Code: sscanf("42 -100", "{i}i", var);
Clearly there are two numbers and two "i", but only one return variable. This is because the first "i" is quiet so is not saved, but affects the return value. The code above makes "var" "-100". The code below will fail in an if check:
PHP Code: sscanf("hi -100", "{i}i", var);
Although the first integer is not saved it is still read - and "hi" is not an integer. Quiet zones can be as long as you like, even for the whole string if you only want to check values are right, not save them:
PHP Code: sscanf("1 2 3", "i{ii}", var); sscanf("1 2 3", "{iii}"); sscanf("1 2 3", "i{a<i>[2]}", var);
You can also embed quiet sections inside enum specifications:
PHP Code: sscanf("1 12.0 Bob 42 INFINITY c", "e<ifs[32]{ig}c>", var);
Quiet sections cannot contain other quiet sections, however they can include enums which contain quiet sections.
? ?
Searches were in the last version of sscanf too, but I'm explaining them again anyway. Strings enclosed in single quotes (') are scanned for in the main string and the position moved on. Note that to search for a single quote you escape it as above using "\\":
PHP Code: sscanf("10 11 woo 12", "i'woo'i", var0, var1);
Gives:
You could achieve the same effect with:
PHP Code: sscanf("10 11 woo 12", "i{is[1000]}i", var0, var1);
But that wouldn't check that the string was "woo". Also note the use of "1000" for the string size. Quiet strings must still have a length, but as they aren't saved anywhere you can make this number as large as you like to cover any eventuality. Enum specifications can include search strings.
? ?
This is a feature similar to quiet sections, which allows you to skip overwriting certain parts of an enum:
Here the "-" is a "minus", and tells sscanf that there is an enum element there, but not to do anything, so if you had:
PHP Code: enum E { ? ?E_A, ? ?E_B, ? ?E_C, ? ?E_D, ? ?E_E }
And you only wanted to update the first two and the last fields and leave all others untouched you could use that specifier above. This way sscanf knows how to skip over the memory, and how much memory to skip. Note that this doesn't read anything, so you could also combine this with quiet sections:
That will read two values and save them, skip over two memory locations, read two values and NOT save them, then read and save a last value. In this way you can have written down all the values for every slot in the enum, but have only used 3 of them. Note that this is the same with "E" - if you do:
You should ONLY specify THREE defaults, not all five:
Code: E<ii-i-ii>(11, 22, 55)
? ?
The previous version of sscanf had "p" to change the symbol used to separate tokens. This specifier still exists but it has been formalised to match the array and enum syntax. What was previously:
PHP Code: sscanf("1,2,3", "p,iii", var0, var1, var2);
Is now:
PHP Code: sscanf("1,2,3", "p<,>iii", var0, var1, var2);
The old version will still work, but it will give a warning. Enum specifications can include delimiters, and is the only time "<>"s are contained in other "<>"s:
PHP Code: sscanf("1 12.0 Bob,c", "e<ifp<,>s[32]c>", var);
Note that the delimiter will remain in effect after the enum is complete. You can even use ">" as a specifier by doing "p<\>>" (or the older "p>").
When used with strings, the collection behaviour is overruled. Most specifiers are still space delimited, so for example this will work:
PHP Code: sscanf("1 2 3", "p<;>iii", var0, var1, var2);
Despite the fact that there are no ";"s. However, strings will ONLY use the specified delimiters, so:
PHP Code: sscanf("hello 1", "p<->s[32]i", str, var);
Will NOT work - the variable "str" will contain "hello 1". On the other hand, the example from earlier, slightly modified:
PHP Code: sscanf("hello there>27", "p<>>s[32]i", str, var);
WILL work and will give an output of:
You can now have optional delimiters using "P" (upper case "p" to match other "optional" specifiers). These are optional in the sense that you specify multiple delimiters and any one of them can be used to end the next symbol:
PHP Code: sscanf("(4, 5, 6, 7)", "P<(),>{s[2]}iiii", a, b, c, d);
This uses a "quiet section" to ignore anything before the first "(", and then uses multiple delimiters to end all the text. Example:
PHP Code: sscanf("42, 43; 44@", "P<,;@>a<i>[3]", arr);
? ?
EVERY format specifier (that is, everything except '', {} and p) now has an optional equivalent - this is just their letter capitalised, so for example the old "z" optional string specifier is now "S" (there is still "z" and, for completeness, "Z", but both give warnings). In addition to optional specifiers, there are also now default values:
PHP Code: sscanf("", "I(12)", var);
The "()"s (round brackets) contain the default value for the optional integer and, as the main string has no data, the value of "var" becomes "12". Default values come before array sizes and after specifications, so an optional array would look like:
PHP Code: sscanf("1 2", "A<i>(3)[4]", arr);
Note that the size of the array is "4" and the default value is "3". There are also two values which are defined, so the final value of "arr" is:
Array default values are clever, the final value of:
PHP Code: sscanf("", "A<i>(3,6)[4]", arr);
Will be:
The difference between "3" and "6" is "3", so the values increase by that every index. Note that it is not very clever, so:
PHP Code: sscanf("", "A<i>(1,2,2)[4]", arr);
Will produce:
The difference between "2" and "2" (the last 2 numbers in the default) is 0, so there will be no further increase. For "l" (logical) arrays, the value is always the same as the last value, as it is with "g" if the last value is one of the special values (INFINITY, NEG_INFINITY (same as -INFINITY), NAN or NAN_E). Note that:
PHP Code: sscanf("", "a<I>(1,2,2)[4]", arr);
Is invalid syntax, the "A" must be the capital part.
Enums can also be optional:
PHP Code: sscanf("4", "E<ifs[32]c>(1, 12.0, Bob, c)", var);
In that code all values except "4" will be default. Also, again, you can escape commas with "\\" in default enum strings. Some final examples:
PHP Code: sscanf("1", "I(2)I(3)I(4)", var0, var1, var2); sscanf("", "O(045)H(0xF4)B(0b0100)U(Y_Less)", octnum, hexnum, binnum, user); sscanf("0xFF", "N(0b101)");
That last example is of a specifier not too well described yet - the "number" specifier, which will work out the format of the number from the leading characters (0x, 0b, 0 or nothing). Also note that the second example has changed - see the next section.
? ?
The "u", "q", and "r" specifiers search for a user by name or ID. The method of this search has changed in the latest versions of "sscanf".
Additionally "U", "Q", and "R" used to take a name or ID as their default value - this has since been changed to JUST a number, and sscanf will not try and determine if this number is online:
Previous:
PHP Code: sscanf(params, "U(Y_Less)", id); if (id == INVALID_PLAYER_ID) { ? ?// Y_Less or the entered player is not connected. }
New:
PHP Code: sscanf(params, "U(-1)", id); if (id == -1) { ? ?// No player was entered. } else if (id == INVALID_PLAYER_ID) ? ?// Entered player is not connected. }
See the section on options for more details.
Users can now optionally return an ARRAY of users instead of just one. This array is just a list of matched IDs, followed by "INVALID_PLAYER_ID". Given the following players:
Code: 0) Y_Less
1) [CLAN]Y_Less
2) Jake
3) Alex
4) Hass
This code:
PHP Code: new ids[3], i; if (sscanf("Le", "?<MATCH_NAME_PARTIAL=1>u[3]", ids)) printf("Error in input"); for (i = 0; ids[i] != INVALID_PLAYER_ID; ) { ? ?if (ids[i] == cellmin) ? ?{ ? ? ? ?printf("Too many matches"); ? ? ? ?break; ? ?} ? ?printf("id = %d", ids[i]); } if (i == 0) printf("No matching players found.");
Will output:
Code: id = 0
id = 1
Too many matches
Searching "Les" instead will give:
And searching without "MATCH_NAME_PARTIAL" will give:
Code: No matching players found.
Basically, if an array of size "N" is passed, this code will return the first N-1 results. If there are less than "N" players whose name matches the given name then that many players will be returned and the next slot will be "INVALID_PLAYER_ID" to indicate the end of the list. On the other hand if there are MORE than "N - 1" players whose name matches the given pattern, then the last slot will be "cellmin" to indicate this fact.
When combined with "U" and returning the default, the first slot is always exactly the default value (even if that's not a valid connected player) and the next slot is always "INVALID_PLAYER_ID".
Note also that user arrays can't be combined with normal arrays or enums, but normal single-return user specifiers still can be.
? ?- Custom (kustom) specifiers
The latest version of sscanf adds a new "k" specifier to allow you to define your own specifers in PAWN:
PHP Code: SSCANF:playerstate(string[]) { ? ?if ('0' <= string[0] <= '9') ? ?{ ? ? ? ?new ? ? ? ? ? ?ret = strval(string); ? ? ? ?if (0 <= ret <= 9) ? ? ? ?{ ? ? ? ? ? ?return ret; ? ? ? ?} ? ?} ? ?else if (!strcmp(string, "PLAYER_STATE_NONE")) return 0; ? ?else if (!strcmp(string, "PLAYER_STATE_ONFOOT")) return 1; ? ?else if (!strcmp(string, "PLAYER_STATE_DRIVER")) return 2; ? ?else if (!strcmp(string, "PLAYER_STATE_PASSENGER")) return 3; ? ?else if (!strcmp(string, "PLAYER_STATE_WASTED")) return 7; ? ?else if (!strcmp(string, "PLAYER_STATE_SPAWNED")) return 8; ? ?else if (!strcmp(string, "PLAYER_STATE_SPECTATING")) return 9; }
The code above, when added to the top level of your mode, will add the "playerstate" specifier, allowing you to do:
PHP Code: sscanf(params, "uk<playerstate>", playerid, state);
This system supports optional custom specifiers with no additional PAWN code:
PHP Code: sscanf(params, "uK<playerstate>(PLAYER_STATE_NONE)", playerid, state);
The new version of "sscanf2.inc" includes functions for "k<weapon>" and "k<vehicle>" allowing you to enter either the ID or name and get the ID back, but both are VERY basic at the moment and I expect other people will improve on them.
Note that custom specifiers are not supported in either arrays or enumerations.
Note also that custom specifiers always take a string input and always return a number, but this can be a Float, bool, or any other single cell tag type.
The optional kustom specifier "K" takes a default value that is NOT (as of sscanf 2.8) parsed by the given callback:
"999" is NOT a valid vehicle model, but if no other value is supplied then 999 will be returned, allowing you to differentiate between the user entering an invalid vehicle and not entering anything at all.
Also as of sscanf 2.8, "k" can be used in both arrays and enums.
Options
The latest version of sscanf introduces several options that can be used to customise the way in which sscanf operates. There are two ways of setting these options - globally and locally:
PHP Code: SSCANF_Option(SSCANF_QUIET, 1);
This sets the "SSCANF_QUIET" option globally. Every time "sscanf" is called the option (see below) will be in effect. Note that the use of:
Instead of a string as:
Is entirely valid here - all the options are defined in the sscanf2 include already.
Alternatively you can use "?" to specify an option locally - i.e. only for the current sscanf call:
PHP Code: sscanf(params, "si", str, num); sscanf(params, "?<SSCANF_QUIET=1>si", str, num); sscanf(params, "si", str, num);
Obviously "s" without a length is deprecated, and the first and last "sscanf" calls will give a warning in the console, but the second one won't as for just that one call prints have been disabled. The following code disables prints globally then enables them locally:
PHP Code: SSCANF_Option(SSCANF_QUIET, 1); sscanf(params, "si", str, num); sscanf(params, "?<SSCANF_QUIET=0>si", str, num); sscanf(params, "si", str, num);
Note that disabling prints is a VERY bad idea when developing code as you open yourself up to unreported buffer overflows when no length is specified on strings less than 32 cells (the default length).
To specify multiple options requires multiple calls:
PHP Code: SSCANF_Option(SSCANF_QUIET, 1); SSCANF_Option(MATCH_NAME_PARTIAL, 0); sscanf(params, "?<SSCANF_QUIET=1>?<MATCH_NAME_PARTIAL=0>s[10]i", str, num);
The options are:
? ?
? ?The behaviour of "U", "Q", and "R" have been changed to take any number as a default, instead of a connected player. Setting "OLD_DEFAULT_NAME" to "1" will revert to the old version.
? ?
? ?Currently sscanf will search for players by name, and will ALWAYS search for player whose name STARTS with the specified string. If you have, say "[CLAN]Y_Less" connected and someone types "Y_Less", sscanf will not find "[CLAN]Y_Less" because there name doesn't start with the specified name. This option, when set to 1, will search ANYWHERE in the player's name for the given string.
? ?
? ?Whatever the value of "MATCH_NAME_PARTIAL", the first found player will always be returned, so if you do a search for "_" on an RP server, you could get almost anyone. To detect this case, if more than one player will match the specified string then sscanf will return an ID of "cellmin" instead. This can be combined with "U" for a lot more power:
? ?PHP Code: ? ?sscanf(params, "?<CELLMIN_ON_MATCHES=1>U(-1)", id); ? ?if (id == -1) ? ?{ ? ? ? ?// No player was entered. ? ?} ? ?else if (id == cellmin) ? ?{ ? ? ? ?// Multiple matches found ? ?} ? ?else if (id == INVALID_PLAYER_ID) ? ?{ ? ? ? ?// Entered player is not connected. ? ?} ? ?else ? ?{ ? ? ? ?// Found just one player. ? ?} ? ?
? ?
? ?Don't print any errors to the console. REALLY not recommended unless you KNOW your code is stable and in production.
? ?
? ?As with "U", "K" used to require a valid identifier as the default and would parse it using the specified callback, so this would NOT work:
? ?Code: ? ?K<vehicle>(Veyron)
? ?
? ?Because that is not a valid vehicle name in GTA. The new version now JUST takes a number and returns that regardless:
? ?[code
? ?K<vehicle>(9999)
? ?[/code]
? ?This setting reverts to the old behaviour.
All specifiers
For quick reference, here is a list of ALL the specifiers and their use:
Code: [b][u]Format[/u][/b] [b][u]Use[/u][/b]
L(true/false) Optional logical truthity
l Logical truthity
K<callback>(any format number) ? ? ? ?Optional custom operator
k<callback> Custom operator
B(binary) Optional binary number
b Binary number
N(any format number) Optional number
n Number
C(character) Optional character
c Character
I(integer) Optional integer
i Integer
D(integer) Optional integer
d Integer
H(hex value) Optional hex number
h Hex number
O(octal value) Optional octal value
o Octal value
F(float) Optional floating point number
f Floating point number
G(float/INFINITY/-INFINITY/NAN/NAN_E) Optional float with IEEE definitions
g Float with IEEE definitions
{ Open quiet section
} Close quiet section
P<delimiters> Multiple delimiters change
p<delimiter> Delimiter change
Z(string)[length] Invalid optional string
z(string)[length] Deprecated optional string
S(string)[length] Optional string
s[length] String
U(any format number) Optional user (bot/player)
u User (bot/player)
Q(any format number) Optional bot (bot)
q Bot (bot)
R(any format number) Optional player (player)
r Player (player)
A<type>(default)[length] Optional array of given type
a<type>[length] Array of given type
E<specification>(default) Optional enumeration of given layout
e<specification> Enumeration of given layout
'string' Search string
% Deprecated optional specifier prefix
? Local options specifier
"extract"
I've written some (extendable) macros so you can do:
PHP Code: extract params -> new a, string:b[32], Float:c; else { ? ?return SendClientMessage(playerid, COLOUR_RED, "FAIL!"); }
This will compile as:
PHP Code: new a, string:b[32], Float:c; if (unformat(params, "is[32]f", a, b, c)) { ? ?return SendClientMessage(playerid, COLOUR_RED, "FAIL!"); }
Note that "unformat" is the same as "sscanf", also note that the "SendClientMessage" part is optional:
PHP Code: extract params -> new a, string:b[32], Float:c;
Will simply compile as:
PHP Code: new a, string:b[32], Float:c; unformat(params, "is[32]f", a, b, c);
Basically it just simplifies sscanf a little bit (IMHO). I like new operators and syntax, hence this, examples:
PHP Code: // An int and a float. extract params -> new a, Float:b; // An int and an OPTIONAL float. extract params -> new a, Float:b = 7.0; // An int and a string. extract params -> new a, string:s[32]; // An int and a playerid. extract params -> new a, player:b;
As I say, the syntax is extendable, so to add hex numbers you would do:
PHP Code: #define hex_EXTRO:%0##%1,%2|||%3=%9|||%4,%5) EXTRY:%0##%1H"("#%9")"#,%2,%3|||%4|||%5) #define hex_EXTRN:%0##%1,%2|||%3|||%4,%5) EXTRY:%0##%1h,%2,%3|||%4|||%5) #define hex_EXTRW:%0##%1,%2|||%3[%7]|||%4,%5) EXTRY:%0##%1a<h>[%7],%2,%3|||%4|||%5)
That will add the tag "hex" to the system. Yes, the lines look complicated (because they are), but the ONLY things you need to change are the name before the underscore and the letter near the middle ("H", "h" and "a<h>" in the examples above for "optional", "required" and "required array" (no optional arrays yet besides strings)).
New examples (with "hex" added):
PHP Code: // A hex number and a player. extract params -> new hex:a, player:b; // 32 numbers then 32 players. extract params -> new a[32], player:b[32]; // 11 floats, an optional string, then an optional hex number. extract params -> new Float:f[11], string:s[12] = "optional", hex:end = 0xFF;
The code is actually surprisingly simple (I developed another new technique to simplify my "tag" macros and it paid off big style here). By default "Float", "string", "player" and "_" (i.e. no tag) are supported, and their individual letter definitions take up the majority of the code as demonstrated with the "hex" addition above. Note that "string:" is now used extensively in my code to differentiate from tagless arrays in cases like this, it is removed automatically but "player:" and "hex:" are not so you may wish to add:
PHP Code: #define player: #define hex:
To avoid tag mismatch warnings (to remove them AFTER the compiler has used them to determine the correct specifier).
The very first example had an "else", this will turn:
PHP Code: unformat(params, "ii", a, b);
In to:
PHP Code: if (unformat(params, "ii", a, b))
You MUST put the "else" on the same line as "extract" for it to be detected, but then you can use normal single or multi-line statements. This is to cover common command use cases, you can even leave things on the same line:
PHP Code: else return SendClientMessage(playerid, 0xFF0000AA, "Usage: /cmd <whatever>");
There is now the ability to split by things other than space (i.e. adds "P<?>" to the syntax - updated from using "p" to "P"):
PHP Code: extract params<|> -> new a, string:b[32], Float:c;
Will simply compile as:
PHP Code: new a, string:b[32], Float:c; unformat(params, "P<|>is[32]f", a, b, c);
Note that for technical reasons you can use "<->" (because it looks like the arrow after the "extract" keyword). You also can't use "<;>", "<,>", or "<)>" because of a bug with "#", but you can use any other character (most notably "<|>", as is popular with SQL scripts). I'm thinking of adding enums and existing variables (currently you HAVE to declare new variables), but not right now.
Errors/Warnings
? ?
If you get this error, DO NOT just download the dll from a random website. This is part of the "Microsoft Visual Studio Redistributable Package". This is required for many programs, but they often come with it. Download it here:
http://www.microsoft.com/download/en...s.aspx?id=5555
? ?- sscanf error: System not initialised
If you get this error, you need to make sure that you have recompiled ALL your scripts using the LATEST version of "sscanf2.inc". Older versions didn't really require this as they only had two natives - "sscanf" and "unformat", the new version has some other functions - you don't need to worry about them, but you must use "sscanf2.inc" so that they are correctly called. If you think you have done this and STILL get the error then try again - make sure you are using the correct version of PAWNO for example.
? ?- sscanf warning: String buffer overflow.
This error comes up when people try and put too much data in to a string. For example:
PHP Code: new str[10]; sscanf("Hello there, how are you?", "s[10]", str);
That code will try and put the string "Hello there, how are you?" in to the variable called "str". However, "str" is only 10 cells big and can thus only hold the string "Hello ther" (with a NULL terminator). In this case, the rest of the data is ignored - which could be good or bad:
PHP Code: new str[10], num; sscanf("Hello there you|42", "p<|>s[10]i", str, num);
In this case "num" is still correctly set to "42", but the warning is given for lost data ("e you").
Currently there is nothing you can do about this from a programming side (you can't even detect it - that is a problem I intend to address), as long as you specify how much data a user should enter this will simply discard the excess, or make the destination variable large enough to handle all cases.
- sscanf warning: Optional types invalid in array specifiers, consider using 'A'.
A specifier such as:
Has been written - here indicating an array of optional integers all with the default value "5". Instead you should use:
This is an optional array of integers all with the default value "5", the advantage of this is that arrays can have multiple defaults:
That will set the array to "5, 6, 7, 8, 9, 10, 11, 12, 13, 14" by default, incrementing by the found difference each time.
- sscanf warning: Optional types invalid in enum specifiers, consider using 'E'.
Similar to the previous warning, A specifier such as:
Is invalid, instead use:
This forces ALL the parts of an enum to be optional - anything less is not possible.
? ?- sscanf error: Multi-dimensional arrays are not supported.
This is not allowed:
PHP Code: sscanf(params, "a<a<i>[5]>[10]", arr);
A work-around can be done using:
PHP Code: sscanf(params, "a<i>[50]", arr[0]);
That will correctly set up the pointers for the system.
? ?- sscanf error: Search strings are not supported in arrays.
This is not allowed (see the section on search strings):
? ?- sscanf error: Delimiters are not supported in arrays.
This is not allowed:
Instead use:
? ?- sscanf error: Quiet sections are not supported in arrays.
This is not allowed:
Instead use:
? ?- sscanf error: Unknown format specifier '?'.
The given specifier is not known (this post contains a full list of all the specifiers near the bottom).
- sscanf warning: 'Z' doesn't exist - that would be an optional, deprecated optional string!.
You used "Z", don't; instead use "S".
? ?- sscanf warning: 'z' is deprecated, consider using 'S' instead.
You used "z", don't; instead use "S".
? ?- sscanf warning: Empty default values.
An optional specifier has been set as (for example):
Instead of:
This does not apply to strings as they can be legitimately empty.
? ?- sscanf warning: Unclosed default value.
You have a default value on an optional specifier that looks like:
Instead of:
? ?- sscanf warning: No default value found.
You have no default value on an optional specifier:
Instead of:
- sscanf warning: Unclosed specifier parameter, assuming '<', consider using something like p<<>.
A custom delimiter of:
Was found with no matching ">" after one character. In this case the system assumes you are using the old (deprecated) style of delimiters and sets it to just "<". Instead use:
Or, if you really do want a delimiter of "<" then use:
Note that this does not need to be escaped; however, a delimiter of ">" does:
The "\" may also need to be escaped when writing actual PAWN strings, leading to:
This also applies to array types ("a<" vs "a<i>"), note that this will result in an invalid array type.
- sscanf warning: Unenclosed specifier parameters are deprecated, consider using something like p<<>.
You are using the old style:
Instead of:
This also applies to array types ("ai" vs "a<i>").
- sscanf warning: No specified parameter found.
The format specifier just ends with:
This also applies to array types ("a" vs "a<i>").
- sscanf warning: Missing string length end.
- sscanf warning: Missing length end.
A string has been written as:
Instead of:
I.e. the length has not been closed.
- sscanf warning: Arrays without a length are deprecated, please add a destination size.
A string has been written as:
Instead of:
I.e. the length has not been included.
? ?- sscanf error: Invalid data length.
An invalid array or string size has been specified (0, negative, or not a number).
? ?- sscanf error: Invalid character in data length.
A string or array has been given a length that is not a number.
? ?- sscanf warning: Strings without a length are deprecated, please add a destination size.
In the old system, strings were not required to have lengths but this introduced security problems with overflows. Now you must add a length or get the default of "32".
? ?- sscanf error: String/array must include a length, please add a destination size.
Arrays are newer than strings, so never had an implementation not requiring a length, so there is no compatability problems in REQUIRING a length to be given.
? ?- sscanf warning: Can't have nestled quiet sections.
You have tried writing something like this:
This has a quiet section ("{}") inside another one, which makes no sense.
? ?- sscanf warning: Not in a quiet section.
"}" was found with no corresponding "{":
? ?- sscanf warning: Can't remove quiet in enum.
This is caused by specifiers such as:
Where the quiet section is started before the enum, but finishes part way through it rather than after it. This can be emulated by:
? ?- sscanf error: Arrays are not supported in enums.
Basically, you can't do:
You can, however, still do:
This is a little more awkward, but is actually more technically correct given how enums are compiled.
? ?- sscanf warning: Unclosed string literal.
A specifier starts a string with "'", but doesn't close it:
- sscanf warning: sscanf specifiers do not require '%' before them.
"format" uses code such as "%d", sscanf only needs "d", and confusingly the C equivalent function (also called "sscanf") DOES require "%". Sorry.
- sscanf error: Insufficient default values.
Default values for arrays can be partially specified and the remainder will be inferred from the pattern of the last two:
That specifier will default to the numbers "0" to "9". However, because enums have a mixture of types, all the default values for "E" must ALWAYS be specified:
Code: E<iiff>(0, 1, 0.0, 1.0)
This will not do:
- sscanf error: Options are not supported in enums.
- sscanf error: Options are not supported in arrays.
The "?" specifier for local options must appear outside any other specifier.
? ?- sscanf error: No option value.
An option was specified with no value:
? ?- sscanf error: Unknown option name.
The given option was not recognised. Check spelling and case:
Code: ?<NOT_A_VALID_NAME=1>
- sscanf warning: Could not find function SSCANF:?.
A "k" specifier has been used, but the corresponding function could not be found. If you think it is there check the spelling matches exactly - including the case.
- sscanf error: SSCANF_Init has incorrect parameters.
- sscanf error: SSCANF_Join has incorrect parameters.
- sscanf error: SSCANF_Leave has incorrect parameters.
- sscanf error: SSCANF_SetPlayerName has incorrect parameters.
You edited something in the sscanf2 include - undo it or redownload it.
Changelog
sscanf 2.8.2 - 18/04/2015
- Fixed a bug where "u" wasn't working correctly after a server restart.
|
|
|
Sistemas novedosos... |
Posted by: s1cky - 2019-04-21, 08:16 PM - Forum: Discusi?n GTA SA Multijugador
- Replies (2)
|
|
Hola,?este es un post para poner sistemas novedosos que se os ocurran para un servidor.
El pilar de un programador es el usuario ?no? pues... As? damos entre todos diferentes ideas frescas para nuestros programadores cuando se encuentren un poco sin ideas.
Aclarar si es [RP/FR/DM] antes de aportar, gracias.
|
|
|
Favorite Movies!! |
Posted by: Escoburger - 2019-04-21, 07:00 PM - Forum: Chat
- Replies (1)
|
|
Howdy mens,
My absolute favorite movie is "Donnie Brasco", I have a thing for mafias somehow, so all my favorite movies are mafia-ish. Also worth to mention fav movies "Goodfellas", "Casino", "Public Enemy No. 1" and ofc the classics The Godfather.
Also can't wait for The Irishman, directed by Martin Scorcsese, and featuring Pesci, De Niro and Pacino?!??!?!!!?Universe.exe has stopped working.
|
|
|
Mano Parei?kimas (Y-Less ir open.mp) |
Posted by: JonasP - 2019-04-21, 05:35 PM - Forum: Lithuanian/Lietuvi?kas
- No Replies
|
|
Tema apie open.mp situacija, Y-Less parei?kima (jo istorijos puse).
Klausimus apie open.mp galite ra?yti cia, klaidas irgi (pabandysiu i?taisyti, nes i?vertus viska antra karta neskaiciau).
Kartu i?versta ir pagrindinis puslapis?https://www.open.mp/?- de?ineje galite pasirinkti lietuviu kalba ant veliavos u?vedus pelyte.
Tai ganetinai laisvas vertimas, taciau mintis i?laikyta ir detos pastangos, kad nebutu i?kraipytas tekstas.
(2019-04-13, 04:01 PM)Y_Less Wrote: Manau, kad metas man papasakoto mano puse visoje ?ioje istorijoje. Jus esate visi bent dalinai teisus, bet, tikriausiai, ne ta dalimi, kuria manote. A? nebandau suskaldyti bendruomenes, a? nebandau sukurti konkurencija SA:MP ir ne ka ma?iau svarbus aspektas - a? nevogiu niekeno?kodo. Galite visi manyti, kad kate i?lindo i? mai?o ir viskas tapo vie?a vien del vieno prane?imo, kuris buvo visi?kai i?trauktas i? konteksto. Jus tegavot pa?velgti i ta hipotetini mai?a ir susidaryti nuomone, kad visa ?i drama yra kvaila, kas yra pilnai suprantama, kadangi truko komunikacijos. A? teband?iau perteikti pagrindines idejas, neatskleid?iant pernelyg daug informacijos, bet, deja, tai man atsirugo ir jums buvo pateikta tik puse visos istorijos, i? kurios beliko daryti i?vadas.
Taigi, praskleiskime ne?inios skrynia.
- A? nebandau suskaldyti bendruomenes. Taciau ka?kas TIKRAI STENGIASI ja sunaikinti - jie rinko duomenis, tycia atidejinejo ilgai lauktus atnaujinimus, grasino pa?alinti visa foruma (praeita savaite [?is prane?imas buvo para?ytas? 2019-04-13]) ir u?blokuoti visus, kurie dristu teigti, kad tai nera teisingas sprendimas. ?is ?mogus jau suskalde bendruomene i?leisdamas 2 atskiras ir lygiagrecias modo versijas ir tada lau?ydamas galva, kodel vienos i? ju aktyvumas nera toks, kokio tiketasi. Jau vir? metu ?mones pra?o, kad 0.3.7 ir 0.3dl butu suvienyta, kol jis sededamas svarste ar yra ?moniu, kurie to noretu. Jo nuomone SA:MP ir jo bendruomene mir?ta, o visam ?iam modui beliko kokie metai ar dveji ir jis visi?kai be jokios sa?ines grau?aties leist tam nutikti. Kai kurie i? musu su tuo nesutinka ir bande ji itikinti, kad jis pasiry?tu kokiems nors veiksmams - arba testu darbus, arba perleistu juos. Bendruomenes traukimasis yra nei?vengiamybe, bet ji mirs tik tuo atveju, jeigu ji nebus palaikoma - butent tai, kas cia ir vyksta.
Egzistuoja neoficialus discord serveris, kuriame ?mones smagiai leid?ia laika ir smaginasi vienas su kitu. Taciau jis neatsirado su mintimi tapti erdve mai?tauti. ?is serveris atsirado, nes ?monem patiko SA:MP ir jie naudojosi Discord, tad bendruomene naturaliai norejo apjungti ?iuos dalykus. Yra neofcialus forumas, Kalcor pats yra seniau teiges, kad jeigu jums nepatinka oficialus - susikurkite savo, taciau dabar blokuoja ?mones, kurie tai padaro. Taciau nei forumo, nei discordo a? nevaldau. Jie yra paprasciausi oficialiuju SA:MP nesekmiu judeti priekin padariniai. Tai nera skaidymas, tai progresas.
- A? neketinu startuoti konkurenta SA:MP. Du svarbus ?od?iai yra klaidinantys - "startuoti" ir "konkurenta." A? nieko "nestartuoju", a? tebandau i?gauti daugiau susidomejimo projektu, kuris jau senai isiva?iaves ir kuriamas. ?tai pastaruju metu git commit'ai:
Kaip matote, nera nieko naujo. Taigi -?kodel visa tai? Kodel tai nera konkurentas?
- A? esu jau karta palikes SA:MP, taip, taciau tai ivyko prie? 6 metus - nustokit zysti!
A? nei?duodu SA:MP, a? nei?duodu Kalcor - jis i?duoda SA:MP, taciau dauguma ?iu aspektu negeba atskirti viena nuo kito. Taip, jis sukure SA:MP, bet tai nepavercia modo jo vienintelio kuriniu. ?imtai kitu ?moniu idejo nesuskaiciuojamas valandas/dienas/savaites/METUS indelio dirbant su modu, darant ji tuo, koks jis yra ?iandien, bet kadangi Kalcor vienintelis turi prieiga prie ma?os dalelytes - serverio kodo, jis tiki, kad butent jis ir yra svarbiausia dalis ir gali diktuoti kokia modo kryptis ir kada jis baigsis. Prad?ioje, taip, jis atliko liuto dali visu darbu, bet paklauskite saves, kas, jusu nuomone, dave modui daugiau ?iuos pastaruosius kelerius metus - Kalcor ar bet kuris i? ?iu asmenu:
Mes nenorime per prievarta i? jo viska atimti, mes nenorime ji ar jo indeli ?eminti. Jis sukure ?i moda, jis itrauke ?mones, bet visi tie kiti ?mones, kurie padejo i?kelti SA:MP iki to, koks yra dabar, t.y. bendruomene, yra tie, kurie dabar yra var?omi ir ignoruojami. A? band?iau u?imti tarpininko role, taip pertransliuojant Kalcor po?iuri ?monems ir bendruomenes po?iuri jam ir u? tai susilaukiau nesibaigiancios lavinos kritikos i? abieju pusiu. A? taip pat daug kartu band?iau itikinti Kalcor perleisti modo valdyma ka?kam kitam (nebutinai man, taciau nebuvo kitu asmenu, kurie tuo apsiimtu). Kokios buvo reakcijos?
- Jis netiki, kad a? gebesiu igyvendinti didesnius atnaujinimus. Be abejo jis irgi ju net nebando igyvendinti ir netgi tiki, kad nera tokiu, kuriuos vertetu igyvendinti, todel kam tai turetu rupeti?
- Jis norejo plano. Mano prioritetai buvo klaidu taisymas, akivaizd?iu trukumu sasajoje (API) u?pildymas ir geresne platforma kitoms kalboms, t.y. tvarkingas C kalbos/pluginu API. Tai net nera sudetingos u?duotys ir a? tikrai irod?iau, kad gebu jas igyvendinti. Taciau tai, pasirodo, nesiskaito kaip planas.
- Jo ?od?iais: "jie to nenusipelne." Tai yra jo nuomone apie ?ia bendruomene, kuria a?, pasirodo, bandau suskaldyti, ir apie galimybe ka?kam testi modo kuryba.
Niekas nepergyvena, kad jis nori baigti, tai ganetinai akivaizdu ir pilnai suprantama. Taciau mes prie?taraujam jo norui kartu su savim u?baigti visa modo gyvenima. ?i bendruomene - itin ?auni bendruomene, suburus daug ilgameciu draugu, taciau jos centre yra u?daro kodo modas su paranoji?ku, viska norinciu kontroliuoti lyderiu. Mes norime pastumti ?i centra. Mes nenorime sunaikinti SA:MP, mes nenorime suskaldyti bendruomene (visa tai i?ai?kejo vie?ai i?ai?kejo, nes a? band?iau itraukti senai pamir?ta rusu bendruomene ir taip sugra?inti dali atskilusiuos bendruomenes), mes norime garantuoti modo testinuma, nes Kalcor to nenori.
Taigi jums pristatau:
open.mp
Tai yra tasai projektas (ir domenas; burger-shot forumas yra laikinas, kol mes paleisime pilnaji, o tai kol kas neivyko). Komanda sudaro DVIDE?IMT DVEJI auk?ciausio lygio San Andreas Multiplayer serveriu savininkai, programuotojai, testuotojai ir bendruomenes lyderiai, kurie kartu dirbdami bando atkurti visa moda nuo pat pamatu. Sukurti foruma lengvoji dalis; tai, kas itvirtino Kalcor kontrole buvo jo vienatinis priejimas prie modo kodo. Yra paplatinta versija, bet nuo pat prad?iu a? labai ai?kiai parod?iau, kad mes nesiterliosime ?iuo po?iuriu ir absoliuciai atsisakysime galimybes naudoti ?i platinta koda. Todel mes visa tai igyvendiname i? naujo, nuo nulio. I? prad?iu planavome paleisti pilna pradine versija be jokios i?ankstines informacijos, taciau to padaryti dabar jau nebepavyks. Bet jau ne tiek ir daug beliko.
Praeityje buvo atsi?akojimu nuo pagrindinio SA:MP modo, bet jie turejo dvi dideles problemas: 1) jie naudojo vogta koda, ko mes nedarome ir 2) jie bande i? naujo i?radineti dvirati - naujos programavimo kalbos, visi?kai naujas funkcionalumas ir t.t. Mes darome ?i moda visi?kai suderinama su SA:MP. Galesite permesti savo serveri i musu modo versija, NEPAKEITUS KODO ir jusu ?aidejai to net nepajus. Be abejo, ateityje yra planu naujam funkcionalumui, patobulinimams, bet ?iuo metu musu demesys yra ant suderinamumo su SA:MP, stabilumo, klaidu taisymo (taisymu, kuriuos mes, kaip bendruomene, jau ka?kada esame kure, nes Kalcor nekurdavo).
A? vir? metu labai daug pastangu dejau dirbant SU Kalcor, tobulinant SA:MP, a? tiesiog kartu turejau ir atsargini plana. Tad galite ir toliau likti su juo, jeigu tikite, kad jo po?iuris pasikeis ir, staiga, atnaujinimai prades vykti (ir jeigu visi ?ie nutikimai tai privers, tada mes busime vistiek ivykde pradine plano u?duoti). Arba galite likti su did?iaja dalimi bendruomenes, kuri supranta, kad yra problema ir nori ja i?taisyti, su ta dalimi, kuri buvo visada buvo kartu su jumis per visus nuotykius - padedant, mokant, hostinant, lyderiaujant.
Lieka jums nuspresti, kas, jusu nuomone, i?dave SA:MP... Jus ?inote, kur mus galite rasti.
|
|
|
Easy Modification |
Posted by: ThePez - 2019-04-21, 04:24 PM - Forum: Questions and Suggestions
- Replies (1)
|
|
Some time ago I saw a Post, SA-MP Plus this Plugin makes modify the Hud, hiding, showing, changing the color, and much more, also the checkpoints and other things.
This plugin did not work for all versions of SA-MP, plus the client had to download a .dll, to make it work.
I would love for you to do this, that you don't need to download files and it works well.
Original post?https://forum.sa-mp.com/showthread.php?t=520666
|
|
|
Simple PM System. |
Posted by: RajatAsthana - 2019-04-21, 10:59 AM - Forum: Filterscripts
- Replies (5)
|
|
~PM SYSTEM v 1.0~
Before starting let me say that "This is only for beginners."
Simple PM (Private Message) System.?
Personal message,?private message,?direct message,[1]?or?personal chat, often abbreviated as PM, DM, or PC, is a private form of messaging between different members on a given platform. It is only seen and accessible by the users participating in the message. It has grown popular because of the increasing demand for privacy and collaboration in this society where the public sharing domain dominates.
How To Install?
1) Download the AMX from the download section below.?
2) Place it in your "filterscript" folder.
3) Open server.cfg and add this line "filterscripts?PMsystem" .
4) Run samp-server.exe (or the linux one) .
Congratulations. You are successfully started the PMsystem by Rajat.
Where Da?Links At?
2) GitHub -?https://github.com/RyderAsthana/PM
=======================
|
|
|
|