[Tutorial] Fixing sscanf2 invalid id problem
#1

Hello,

I saw alot of people experiencing this issue

So, i made a tutorial for this (Sorry if it is not explained fully as it is my first tutorial)

First, if you have something like this in your script and you are using sscanf 2:

pawn Code:
new idvariable, something[60]; // Defines new idvariable for the id and something for the string (text) and something's size is 60.
if(sscanf(params, "us[60]", idvariable, something)) // This checks if the player didn't type the command fully, like the player typed /command 0 it will show him this cause he didn't type the text after 0 (id).
And then you check if the id is connected like this :

pawn Code:
if(!IsPlayerConnected(idvariable)) return SendClientMessage(playerid, -1, "Invalid Player ID"); // If the id is not connected it will return him a message in the chat with the white color (-1) Invalid Player ID.
It will return Invalid Player ID even if the id is connected.

Now i will tell you how to fix this.

Change the u (Username) in the sscanf param line to d (Integer) (That means we will change the u (Username) param to d (Integer). Example :

pawn Code:
if(sscanf(params, "ds[60]", idvariable, something))
Notes:

d = Integer
i = Integer
c = Character
u = User ID or name
s = String
h = Hex number
x = Hex number
f = Float
z = Optional string
When you fix this problem, you will be able to only use IDs for players, not names.

This is my first tutorial, i'm sorry if i didn't explain it fully!

Thank you for reading this.
Reply
#2

Very usefull helped me
Reply
#3

Thanks.
Reply
#4

Thanks, Helped me with a few problems in my gamemode
Reply
#5

how to fix this

pawn Code:
CMD:setstream(playerid, params[])
{
 if(!IsPlayerAdmin( playerid ) ) return SendClientMessage(playerid, -1,"You must be a higher level admin to use this command");
 new level, aname[MAX_PLAYER_NAME];
 new targetid;
 if(sscanf(params, "ri", targetid, level)) return SendClientMessage(playerid, -1,"ERROR: /setstream <playerid> <1> allow stream <0> disallow");
 if (level > 1 || level < 0) return SendClientMessage(playerid, -1,"ERROR: invalid stream lol");
 if(!IsPlayerConnected( targetid )) return SendClientMessage(playerid, -1,"ERROR: player isn't connected");
 new string1[130], tname[MAX_PLAYER_NAME], string2[130];
 new INI:File = INI_Open(UserPath(targetid ));
 INI_SetTag(File,"data");
 INI_WriteInt(File,"Stream", pStream);
 INI_Close(File);
 PlayerInfo[targetid][pStream] = level;
 GetPlayerName(playerid, aname, sizeof(aname));
 GetPlayerName(targetid, tname, sizeof(tname));
 new string3[130],string4[130];
 if(level == 0)
 {
 format(string1, sizeof(string1),"Administrator %s Has Demote You From Deejay STAFF",aname,level);
 SendClientMessage(playerid,0xFF9900AA,string1);
 format(string3, sizeof(string3),"You was disallow %s to be a deejay",tname,level);
 SendClientMessage(targetid,0xFF9900AA,string3);
 return 1;
 }
 if(level == 1)
 {
 format(string2, sizeof(string2),"Administrator %s Has Set You Stream Level To STAFF, Enjoy",aname,level);
 format(string4, sizeof(string4),"You was allowed %s to be a deejay",tname,level);
 SendClientMessage(playerid,0xFF9900AA,string4);
 SendClientMessage(targetid,0xFF9900AA,string2);
 return 1;
 }
 return 1;
}
Reply
#6

For some reason, if I use u identifier for id, i get errors like player is not connected. I faced this prolem from the early days since i started scripting (november 2012). In order to make my commands working I had to put d instead of u. Till today my commads are with d. Any idea why?
Reply
#7

oh shit D:
Reply
#8

Quote:
Originally Posted by ******
View Post
That's NOT how you fix the problem "d" is "integer", "u" is "user id or name". You are "fixing" the problem by destroying sscanf functionality (and by extension functionality of your own mode).

for one thing, always make sure you're using the latest version of sscanf. Then don't use "IsPlayerConnected(pid)" but "pid == INVALID_PLAYER_ID".
I tried to use INVALID_PLAYER_ID a while ago but that didn't fix the problem, but now when i try INVALID_PLAYER_ID with u it works, why didn't it work before??

@xFirex : Try what ****** said or change the "r" param to "d".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)