sscanf kustom specifiers and space - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: sscanf kustom specifiers and space (
/showthread.php?tid=622238)
sscanf kustom specifiers and space -
X337 - 20.11.2016
Hello, i have a sscanf custom specifiers to check if gang name is exists.
Here is my code:
Код:
SSCANF:gang(string[])
{
printf("SSCANF:gang string is \"%s\"", string);
new ret;
if ('0' <= string[0] <= '9')
{
ret = strval(string);
if(Iter_Contains(Gangs, ret))
return ret;
}
foreach(new i : Gangs)
{
if(!strcmp(g_Gang[i][gname], string, true))
return i;
}
return -1;
}
The problem is, it doesn't work while i'm trying to find a gang that have spaces in it.
I've debugged that code by printing "string" variable, and i found out that the string is getting cut off at space.
Код:
new testname[12] = "Gang name", id;
sscanf(testname, "k<gang>", id); // Prints SSCANF:gang string is "Gang"
testname = "Gang_name";
sscanf(testname, "k<gang>", id); // Prints SSCANF:gang string is "Gang_name"
Is there any way to fix this / to make it works?
Thanks in advance.
Re: sscanf kustom specifiers and space - justice96 - 20.11.2016
Just use Group_GetID method;
Код:
if(Group_GetID(string) != INVALID_GROUP) return SendClientMessage(playerid, -1, "ERROR: Gang name already exists!");
Re: sscanf kustom specifiers and space -
X337 - 20.11.2016
Quote:
Originally Posted by justice96
Just use Group_GetID method;
Код:
if(Group_GetID(string) != INVALID_GROUP) return SendClientMessage(playerid, -1, "ERROR: Gang name already exists!");
|
I didn't use y_group. However, thanks for the answer, i may use y_group in future.
Re: sscanf kustom specifiers and space - justice96 - 20.11.2016
Quote:
Originally Posted by X337
I didn't use y_group. However, thanks for the answer, i may use y_group in future.
|
Remember that, you can also defined a variable gang for player;
Код:
new gangid = PlayerInGang[playerid];
if(Group_GetID(gangid) != INVALID_GROUP) return SendClientMessage(playerid, -1, "ERROR: Gang name already exists!");
or you can loop each Gangs through foreach/Iter