sscanf not working properly
#1

Hello guys im trying to make a pm command using sscanf and zcmd but it doesnt turn out well

in game: /pm 0 a //still need help
Outcome: PM from 67: 97 //still need helpp

what is it with this 67 i cant see my own name and message seems like i wrote some numbers and they are not random if i write "b" instead of "a" it turns out to be 98.

My Code:
Код:
CMD:pm(playerid, params[])
{
	new otherid,string[150],text,pname[24];
	if (sscanf(params, "uc", otherid,text)) return SendClientMessage(playerid,-1,"Usage: /pm [playerid] [message]");
	if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, COLOR_RED, "That PlayerID is not connected!");
	GetPlayerName(playerid,pname,24);
	format(string,sizeof(string),"PM from %d: %d",pname,text);
	SendClientMessage(otherid,COLOR_YELLOW,string);
	return 1;
}
Any Help Is Appreciated.
Reply
#2

Код:
CMD:pm(playerid, params[])
{
	new otherid,string[150],text,pname[24];
	if (sscanf(params, "us", otherid,text)) return SendClientMessage(playerid,-1,"Usage: /pm [playerid] [message]");
	if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, COLOR_RED, "That PlayerID is not connected!");
	GetPlayerName(playerid,pname,24);
	format(string,sizeof(string),"PM from %d: %s",pname,text);
	SendClientMessage(otherid,COLOR_YELLOW,string);
	return 1;
}
CMD:id(playerid, params[])
{
	new id,string[150],name[24],pname[24];
	if(sscanf(params, "s", name)) return SendClientMessage(playerid,-1,"Usage: /id [name]");
	id = GetPlayerID(name);
	GetPlayerName(id,pname,24);
	format(string,sizeof(string),"%d %s",id,pname);
	SendClientMessage(playerid,COLOR_LIGHTGRAY,string);
	return 1;
}
Reply
#3

PHP код:
new otherid,string[150],text[64],pname[24];
    if (
sscanf(params"us[64]"otherid,text)) return SendClientMessage(playerid,-1,"Usage: /pm [playerid] [message]"); 
PHP код:
new id,string[150],name[24],pname[24];
    if(
sscanf(params"u"id)) return SendClientMessage(playerid,-1,"Usage: /id [name]"); 
1. You need to specified the size of the text because it's a string
2.The id it's get automate by sscanf from players online , so the u stands for id/name
Reply
#4

Quote:

2.The id it's get automate by sscanf from players online , so the u stands for id/name

but i dont want sscanf to send me Chaves Chaves thats why i did a GetPlayerID which will show first value 0 and still i get the name as 67 didnt fix any suggestion?

also now pm always returns SendClientMessage(playerid,-1,"Usage: /pm [playerid] [message]");
Reply
#5

PHP код:
new id,string[150],name[24],pname[24];
    if(
sscanf(params"s[24]"name)) return SendClientMessage(playerid,-1,"Usage: /id [name]"); 
Well this is, but i think you need enter the exact name
Reply
#6

no no i dont have any problem with my id script my id is good but my name should be chaves but it shows my 67 that needs fix im dying out of anger here please help
Reply
#7

@grymtn sscanf U switch works like these.
It expects a string, first it checks if its numerical only (If its ID in other words), if it is, it will just return that id as integer, if its not it will loop thru players and partially match string with player name. If string is shorter than player name but it does match as part of name, it will return id of that player. If you have two players that have same partial match, there will be possible mismatch (more players but only one possible return).

One solution would be to use custom (kustom or K<> switch). K Switch will call your public function where you can define logic for looking up players. One example of what you can do, is if you find multiple matches, you return -1, or if you have roleplay server then decide what to do with underscore if its present.
Reply
#8

PHP код:
format(string,sizeof(string),"PM from %d: %d",pname,text); 
I've look better now , you try to show a string, but you put integer
Should be:
PHP код:
format(string,sizeof(string),"PM from %s: %s",pname,text); 
Reply
#9

Quote:
Originally Posted by Banditul18
Посмотреть сообщение
PHP код:
new id,string[150],name[24],pname[24];
    if(
sscanf(params"s[24]"name)) return SendClientMessage(playerid,-1,"Usage: /id [name]"); 
thank you so much dude rep given but you dont use sscanf like "s[24]" with sscanf apparently it was "s"

wouldnt find it without you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)