SSCANF returns Unarmed?
#1

Код HTML:
CMD:me(params[], playerid) {
	// if(isnull(params)) {
	// 	SendClientMessageToAll(COLOR_ME, "Usage: /me [action]");
	// 	return 1;
	// }
	// else {
	// 	new string[256], 
	// 		name[MAX_PLAYER_NAME + 1];
	// 	GetPlayerName(playerid, name, sizeof(name));
	// 	format(string, sizeof(string), "%s %s", name, params);
	// 	SendClientMessageToAll(COLOR_ME, string);
	// 	return 1;
	// }
	new action[256],
		name[MAX_PLAYER_NAME + 1],
		string[256];
	if (sscanf(params, "sz", action)) {
		return SendClientMessageToAll(0xC4C4C4FF, "Usage: /me [action]");
	}
	GetPlayerName(playerid, name, sizeof(name));
	format(string, sizeof(string), "%s %s", name, action);
	SendClientMessageToAll(COLOR_ME, string);
	return 1;
}
I have tried two different ways to make this command. But the first one just always sends "Usage: /me [action]" and the second one sends "Unarmed" for some reason. Can someone please point out what I am doing wrong here?
Thanks in advance!!!
Reply
#2

PHP код:
CMD:me(params[], playerid) {
new 
action[256],
        
name[MAX_PLAYER_NAME 1],
        
string[256];
    if (
sscanf(params"s[250]"action)) {
        return 
SendClientMessage(0xC4C4C4FF"Usage: /me [action]");
    }
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "%s %s"nameaction);
    
SendClientMessageToAll(COLOR_MEstring);
    return 
1;

Try this..
Reply
#3

Quote:
Originally Posted by JasonRiggs
Посмотреть сообщение
PHP код:
CMD:me(params[], playerid) {
new 
action[256],
        
name[MAX_PLAYER_NAME 1],
        
string[256];
    if (
sscanf(params"s[250]"action)) {
        return 
SendClientMessage(0xC4C4C4FF"Usage: /me [action]");
    }
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "%s %s"nameaction);
    
SendClientMessageToAll(COLOR_MEstring);
    return 
1;

Try this..
Now it says argument type mismatch (argument 2)
Reply
#4

Yeah sorry.. Try this now..

PHP код:
CMD:me(params[], playerid) {
new 
action[256],
        
name[MAX_PLAYER_NAME 1],
        
string[256];
    if (
sscanf(params"s[250]"action)) {
        return 
SendClientMessage(playerid0xC4C4C4FF"Usage: /me [action]");
    }
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "%s %s"nameaction);
    
SendClientMessageToAll(COLOR_MEstring);
    return 
1;

Reply
#5

The syntax is integer, string..
pawn Код:
CMD:me(playerid, params[])
+ use isnull macro, not sscanf. First code (commented out) is good. Just change string to 145 as max client message can be up to 144 characters.

EDIT: Why SendClientMessageToAll? You want to send only to player who executes command. Change to SendClientMessage.
Reply
#6

Still it it sends "Unarmed" to the client.
Reply
#7

You don't really need to use sscanf for this, you can simply check to see if the params are empty or not.

For example:
PHP код:

CMD
:me(playeridparams[])
{
    if(
strlen(params) == 0) return SendClientMessage(playerid0xC4C4C4FF"Usage: /me [action]");

    new 
string[128], name[MAX_PLAYER_NAME];
    
    
GetPlayerName(playeridnamesizeof(name));    

    
format(stringsizeof(string), "%s %s"nameparams);
    
SendClientMessageToAll(COLOR_MEstring); 
    return 
1;

Although rather than sending the message to everyone, I would recommend sending it in a proximity.

SendClientMessageToAll will send this /me to everyone on the server, if you're making a roleplay server, I wouldn't recommend that.

You can do a range check like this:

PHP код:

CMD
:me(playeridparams[])
{
    if(
strlen(params) == 0) return SendClientMessage(playerid0xC4C4C4FF"Usage: /me [action]");

    new 
string[128], name[MAX_PLAYER_NAME], FloatPos[3];
    
    
GetPlayerName(playeridnamesizeof(name));
    
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);

    
format(stringsizeof(string), "%s %s"nameparams);
    foreach(
Playeri)
     {
        if(
IsPlayerInRangeOfPoint(i/*30 is a good range but you can decrease/increase*/30.0Pos[0], Pos[1], Pos[2]))
        {
            
SendClientMessage(iCOLOR_MEstring);
        }
    }
    return 
1;

The code above will search for all the players in the range of the player typing the /me and then display the message to the players in the range.

Up to you though, however you wanna use it.
Reply
#8

Quote:
Originally Posted by ItsRobinson
Посмотреть сообщение
PHP код:
if(strlen(params) == 0
isnull is better than strlen as it checks the first character only whereas strlen count all of them.
Quote:
Originally Posted by ItsRobinson
Посмотреть сообщение
PHP код:
foreach(Playeri
Deprecated syntax, new syntax is:
pawn Код:
foreach(new i : Player)
Reply
#9

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
isnull is better than strlen as it checks the first character only whereas strlen count all of them.


Deprecated syntax, new syntax is:
pawn Код:
foreach(new i : Player)
Or that
Reply
#10

Guys it seems like the problem was that I switched the positions of the argument params[] and playerid.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)