/kick command with zcmd & sscanf2
#1

okay I just learnt zcmd and sscanf today and im loving it, but i have one problem

Код:
CMD:kick(playerid,params[])
{
	new str, id;
	if(Logged[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"You are not logged in!");
	if(PlayerInfo[playerid][Level] < 2) return SendClientMessage(playerid,0xFF0000FF,"You are not an admin!");
	if(sscanf(params,"us[128];",id,str))
	{
	    SendClientMessage(playerid,0xFF0000FF,"USAGE: /kick [ID] [REASON]");
	    return 1;
	}
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xFF0000FF,"Invalid ID");
	if(PlayerInfo[id][Owner] == 1) return SendClientMessage(playerid,0xFF0000FF,"You cannot use this command on the owner!");
	new string[128];
	new name[MAX_PLAYER_NAME];
	new nname[MAX_PLAYER_NAME];
	GetPlayerName(id,name,MAX_PLAYER_NAME);
	GetPlayerName(playerid,nname,MAX_PLAYER_NAME);
	format(string,sizeof(string),"You have been kicked by Admin %s for: %s",nname,str);
	SendClientMessage(id,ORANGE,string);
	format(string,sizeof(string),"You have kicked %s for: %s",name,str);
	SendClientMessage(playerid,ORANGE,string);
	format(string,sizeof(string),"Admin %s has Kicked out %s for: %s",nname,name,str);
	SendClientMessageToAll(ORANGE,string);
	Kick(id);
	return 1;
}
it makes the reason for being kicked only one word, like if i type /kick 0 for hacking it will show up as
id 0 has been kicked reason: for
it will onyl show one word, how do i fix this?
Reply
#2

because u didn't assign 'str' to a string. Use new str[128];
Reply
#3

The same thing happened when i changed the str to 128 heres what it is now

Код:
CMD:kick(playerid,params[])
{
	new str[128];
	new id;
	if(Logged[playerid] == 0) return SendClientMessage(playerid,0xFF0000FF,"You are not logged in!");
	if(PlayerInfo[playerid][Level] < 2) return SendClientMessage(playerid,0xFF0000FF,"You are not an admin!");
	if(sscanf(params,"us;",id,str))
	{
	    SendClientMessage(playerid,0xFF0000FF,"USAGE: /kick [ID] [REASON]");
	    return 1;
	}
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xFF0000FF,"Invalid ID");
	if(PlayerInfo[id][Owner] == 1) return SendClientMessage(playerid,0xFF0000FF,"You cannot use this command on the owner!");
	new string[128];
	new name[MAX_PLAYER_NAME];
	new nname[MAX_PLAYER_NAME];
	GetPlayerName(id,name,MAX_PLAYER_NAME);
	GetPlayerName(playerid,nname,MAX_PLAYER_NAME);
	format(string,sizeof(string),"You have been kicked by Admin %s for: %s",nname,str);
	SendClientMessage(id,ORANGE,string);
	format(string,sizeof(string),"You have kicked %s for: %s",name,str);
	SendClientMessage(playerid,ORANGE,string);
	format(string,sizeof(string),"Admin %s has Kicked out %s for: %s",nname,name,str);
	SendClientMessageToAll(ORANGE,string);
	Kick(id);
	return 1;
}
Reply
#4

I think he means

if(sscanf(params,"us[128];",id,str)
Reply
#5

maybe a "z" instead of a "s" will do, the "z" parses the remaining string until its end, while the "s" only parses 1 word...
Код:
if(sscanf(params,"uz;",id,str))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)