SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/11/2016, 08:44 AM   #1
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 877
Reputation: 291
Default sscanf kustom specifiers and space

Hello, i have a sscanf custom specifiers to check if gang name is exists.
Here is my code:
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.

Code:
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.
X337 is offline   Reply With Quote
Old 20/11/2016, 08:50 AM   #2
justice96
Guest
 
Posts: n/a
Default Re: sscanf kustom specifiers and space

Just use Group_GetID method;

Code:
if(Group_GetID(string) != INVALID_GROUP) return SendClientMessage(playerid, -1, "ERROR: Gang name already exists!");
  Reply With Quote
Old 20/11/2016, 08:57 AM   #3
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 877
Reputation: 291
Default Re: sscanf kustom specifiers and space

Quote:
Originally Posted by justice96 View Post
Just use Group_GetID method;

Code:
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.
X337 is offline   Reply With Quote
Old 20/11/2016, 09:01 AM   #4
justice96
Guest
 
Posts: n/a
Default Re: sscanf kustom specifiers and space

Quote:
Originally Posted by X337 View Post
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;

Code:
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
  Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Optional specifiers - SSCANF CrashCar Scripting Help 3 18/04/2015 01:29 AM
sscanf User specifiers not working properly admiralspeedy Scripting Help 10 23/07/2014 05:13 AM
[Solved] SSCANF (K)Custom Specifiers... Crayder Scripting Help 0 31/12/2013 01:46 AM
Problem with sscanf specifiers - returns error message everytime. RajatPawar Scripting Help 7 27/03/2013 12:35 PM
[HELP]sscanf with specifiers CoDeZ Scripting Help 3 24/01/2013 07:06 PM


All times are GMT. The time now is 07:03 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.