sscanf and my problem [SOLVED]
#1

Hello!

I have a command to choose between many actions (like "takeweapon", "setskin" and so on).
PHP код:
ocmd:range(playerid,params[])
{
    if(
Player[playerid][pAdmin] < 3)return SendClientMessage(playerid,-1,"{b65e5e}Fehler:{FFFFFF} Du besitzt nicht die Rechte fьr diesen Befehl!");
    new 
Float:range,auswahl[20],selfid,string[145],Float:X,Float:Y,Float:Z;
    
GetPlayerPos(playerid,X,Y,Z);
    if(
sscanf(params,"ifs[20]",selfid,range,auswahl))
    {
        
SendClientMessage(playerid,grau,"Befehl: /range [0 = alle; 1 = alle anderen] [Umkreis] [Auswahl (siehe unten)]");
        
SendClientMessage(playerid,grau,"* freeze | unfreeze | takeweapon | setskin");
        return 
1;
    }
    if(
range 1)return SendClientMessage(playerid,-1,"{b65e5e}Fehler:{FFFFFF} Der Umkreis muss mindestens 1 betragen!");
    if(!
strcmp(auswahl,"freeze",true))
    {
        
format(string,sizeof(string),"{0489B1}* %s %s hat im Umkreis von %0.2f alle Spieler eingefroren!",aRang[Player[playerid][pAdmin]],Player[playerid][pName],range);
        for(new 
i,j=GetPlayerPoolSize();i<=j;i++)
        {
            if(
selfid == && == playerid)continue;
            if(
IsPlayerInRangeOfPoint(i,range,X,Y,Z))
            {
                
TogglePlayerControllable(playerid,0);
                
SendClientMessage(i,-1,string);
                continue;
            }
        }
        return 
1;
    }
    return 
1;

This is already okay, it works.

But this don't work:
PHP код:
ocmd:range(playerid,params[])
{
    if(
Player[playerid][pAdmin] < 3)return SendClientMessage(playerid,-1,"{b65e5e}Fehler:{FFFFFF} Du besitzt nicht die Rechte fьr diesen Befehl!");
    new 
Float:range,auswahl[20],selfid,string[145],Float:X,Float:Y,Float:Z;
    
GetPlayerPos(playerid,X,Y,Z);
    if(
sscanf(params,"ifs[20]",selfid,range,auswahl))
    {
        
SendClientMessage(playerid,grau,"Befehl: /range [0 = alle; 1 = alle anderen] [Umkreis] [Auswahl (siehe unten)]");
        
SendClientMessage(playerid,grau,"* freeze | unfreeze | takeweapon | setskin");
        return 
1;
    }
    if(
range 1)return SendClientMessage(playerid,-1,"{b65e5e}Fehler:{FFFFFF} Der Umkreis muss mindestens 1 betragen!");
    if(!
strcmp(auswahl,"setskin",true))
    {
        new 
skinid;
        if(
sscanf(params,"ifs[20]i",selfid,range,auswahl,skinid))
        {
            
format(string,sizeof(string),"Befehl: /range %d %0.2f %s [Skin-ID]",selfid,range,auswahl);
            
SendClientMessage(playerid,grau,string);
            return 
1;
        }
        
format(string,sizeof(string),"{0489B1}* %s %s hat im Umkreis von %0.2f alle Spieler den Skin %d gegeben!",aRang[Player[playerid][pAdmin]],Player[playerid][pName],range);
        for(new 
i,j=GetPlayerPoolSize();i<=j;i++)
        {
            if(
selfid == && == playerid)continue;
            if(
IsPlayerInRangeOfPoint(i,range,X,Y,Z))
            {
                
SetPlayerSkin(i,skinid);
                
SendClientMessage(i,-1,string);
                continue;
            }
        }
        return 
1;
    }
    return 
1;

I think it's the problem with sscanf because I must add a new parameter after I fill in the first three.


EDIT:
I solved my problem. I added the length of the string to strcmp.
PHP код:
else if(!strcmp(auswahl,"setskin",true,7)) 
I hope you understand my problem, my English isn't good.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)