Need help with CMD..
#1

pawn Код:
if(strcmp(cmd,"/streetrespect",true) == 0)
    {
        if(!gPlayerLogged[playerid] == 0) SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");//First error
        else if(PlayerInfo[playerid][pCMDT] > 0) SendClientMessage(playerid,0xFF0000FF,"Please wait before using this command again.");
        else{
            new id;
            new targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];//warning 219: local variable "sendername" shadows a variable at a preceding level
            id = ReturnUser(tmp);
            GetPlayerName(id, targetname, sizeof(targetname));
            GetPlayerName(playerid, sendername, sizeof(sendername));
            if(sscanf(params, "u", id)) SendClientMessage(playerid, 0xCC0000AA, "USAGE: /respect <playerid/partofname>");//error 017: undefined symbol "params"
            else if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) SendClientMessage(playerid, -1, "ID not connected");
            else if(playerid == id) SendClientMessage(playerid, -1, "You can't give Street Respect to yourself.");
            else if(!IsPlayerInRangeOfPlayer(playerid, id, 5)) SendClientMessage(playerid, -1, "You aren't close enough to the player.");
            else
            {
                new string[128];//warning 219: local variable "string" shadows a variable at a preceding level
                PlayerInfo[playerid][StreetRespect]++;
                PlayerInfo[playerid][pCMDT] = 3600; // example 3600 - 1 hour
                format(string, sizeof(string), " You have gived Street Respect to %s.", GetPlayerName(id));//argoment doesnt match
                SendClientMessage(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), " Player %s has gived you Street Respect to you.", GetPlayerName(playerid));//argoment doesnt match
                SendClientMessage(id, COLOR_WHITE, string);
            }
        }
        return 1;
    }
ERROR:
pawn Код:
(15218) : warning 213: tag mismatch
(15222) : warning 219: local variable "sendername" shadows a variable at a preceding level
(15226) : error 017: undefined symbol "params"
(15232) : warning 219: local variable "string" shadows a variable at a preceding level
(15235) : warning 202: number of arguments does not match definition
(15235) : warning 202: number of arguments does not match definition
(15237) : warning 202: number of arguments does not match definition
(15237) : warning 202: number of arguments does not match definition
With best regards Scrillex
Reply
#2

Hello test the code bellow

PHP код:
if(strcmp(cmd,"/streetrespect",true) == 0)
    {
        if(
gPlayerLogged[playerid] == 0SendClientMessage(playeridCOLOR_GREY"You need to login first before using any command.");//First error
        
else if(PlayerInfo[playerid][pCMDT] > 0SendClientMessage(playerid,0xFF0000FF,"Please wait before using this command again.");
        else{
            new 
id;
            new 
targetname[MAX_PLAYER_NAME], sendername2[MAX_PLAYER_NAME];//warning 219: local variable "sendername" shadows a variable at a preceding level
            
id ReturnUser(tmp);
               
GetPlayerName(idtargetnamesizeof(targetname));
            
GetPlayerName(playeridsendername2sizeof(sendername2));
            if(
sscanf(cmd"u"id)) SendClientMessage(playerid0xCC0000AA"USAGE: /respect <playerid/partofname>");//error 017: undefined symbol "params"
            
else if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) SendClientMessage(playerid, -1"ID not connected");
            else if(
playerid == idSendClientMessage(playerid, -1"You can't give Street Respect to yourself.");
            else if(!
IsPlayerInRangeOfPlayer(playeridid5)) SendClientMessage(playerid, -1"You aren't close enough to the player.");
            else
            {
                new 
string2[128];//warning 219: local variable "string" shadows a variable at a preceding level
                
PlayerInfo[playerid][StreetRespect]++;
                
PlayerInfo[playerid][pCMDT] = 3600// example 3600 - 1 hour
                
format(string2sizeof(string2), " You have gived Street Respect to %s."targetname);//argoment doesnt match
                
SendClientMessage(playeridCOLOR_WHITEstring2);
                
format(string2sizeof(string2), " Player %s has gived you Street Respect to you."sendername2);//argoment doesnt match
                
SendClientMessage(idCOLOR_WHITEstring2);
            }
        }
        return 
1;
    } 
Reply
#3

when I type /streetrespect it gives me: ID NOT CONNECTED!

pawn Код:
if(strcmp(cmd,"/streetrespect",true) == 0)
    {
        if(gPlayerLogged[playerid] == 0) SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");//First error
        else if(PlayerInfo[playerid][pCMDT] > 0) SendClientMessage(playerid,0xFF0000FF,"Please wait before using this command again.");
        else
        {
            new id;
            new targetname[MAX_PLAYER_NAME], sendername2[MAX_PLAYER_NAME];//warning 219: local variable "sendername" shadows a variable at a preceding level
            id = ReturnUser(tmp);
            GetPlayerName(id, targetname, sizeof(targetname));
            GetPlayerName(playerid, sendername2, sizeof(sendername2));
            if(sscanf(cmd, "u", id)) SendClientMessage(playerid, 0xCC0000AA, "USAGE: /respect <playerid/partofname>");//error 017: undefined symbol "params"
            else if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) SendClientMessage(playerid, -1, "ID not connected");
            else if(playerid == id) SendClientMessage(playerid, -1, "You can't give Street Respect to yourself.");
            else if(!IsPlayerInRangeOfPlayer(playerid, id, 5)) SendClientMessage(playerid, -1, "You aren't close enough to the player.");
            else
            {
                new string2[128];//warning 219: local variable "string" shadows a variable at a preceding level
                PlayerInfo[playerid][StreetRespect]++;
                PlayerInfo[playerid][pCMDT] = 3600; // example 3600 - 1 hour
                format(string2, sizeof(string2), " You have gived Street Respect to %s.", targetname);//argoment doesnt match
                SendClientMessage(playerid, COLOR_WHITE, string2);
                format(string2, sizeof(string2), " Player %s has gived you Street Respect to you.", sendername2);//argoment doesnt match
                SendClientMessage(id, COLOR_WHITE, string2);
            }
        }
        return 1;
    }
Thank you for your help.
Reply
#4

oh sorry for fail

PHP код:
if(sscanf(cmd[13], "u"id)) SendClientMessage(playerid0xCC0000AA"USAGE: /respect <playerid/partofname>");//error 017: undefined sym 
Reply
#5

PHP код:
if(strcmp(cmd,"/streetrespect",true) == 0)
{
       if(
gPlayerLogged[playerid] == 0) return SendClientMessage(playeridCOLOR_GREY"You need to login first before using any command.");
       if(
PlayerInfo[playerid][pCMDT] > 0) return SendClientMessage(playerid,0xFF0000FF,"Please wait before using this command again.");
       new 
idtargetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
       
GetPlayerName(playeridsendernamesizeof(sendername));
       if(
sscanf(cmd"u"id)) return SendClientMessage(playerid0xCC0000AA"USAGE: /streetrespect <playerid/partofname>");
       if(! 
IsPlayerConnected(id)) return SendClientMessage(playerid, -1"ID not connected");
       if(
playerid == id) return SendClientMessage(playerid, -1"You can't give Street Respect to yourself.");
       if(! 
IsPlayerInRangeOfPlayer(playeridid5.0)) return SendClientMessage(playerid, -1"You aren't close enough to the player.");
       
GetPlayerName(idtargetnamesizeof targetname);
       new 
string[128];
       
PlayerInfo[playerid][StreetRespect]++;
       
PlayerInfo[playerid][pCMDT] = 3600// example 3600 - 1 hour
       
format(stringsizeof(string), "You have gived Street Respect to %s."targetname);
       
SendClientMessage(playeridCOLOR_WHITEstring);
       
format(stringsizeof(string), "Player %s has gived you Street Respect to you."sendername);
       
SendClientMessage(idCOLOR_WHITEstring);
       return 
1;

Here, read it carefuly. You dont require ReturnUser when using sscanf. Moreover you can use that sort of indentation for cleaner code.
Errors may occur if you are already having those variables defined in the callback. So rename them or simply use the pre defined ones.

I will recommend you to use ZCMD, cause its faster, less chances of error and much more.
Reply
#6

-->Gammix :your command wont work correctly! beacause your re passing the entire cmd string to sscanf

already i recommended to just use a command processor like zcmd with sscanf. This not only is faster, but its much safer due to how easy it is to make mistakes using the above methodology
Reply
#7

Quote:
Originally Posted by Golf
Посмотреть сообщение
-->Gammix :your command wont work correctly! beacause your re passing the entire cmd string to sscanf

already i recommended to just use a command processor like zcmd with sscanf. This not only is faster, but its much safer due to how easy it is to make mistakes using the above methodology
First read carefuly the code. Second read your posts before printing that crap. No where mentioned to use zcmd and just given a wrong shitty code which even not going to workout. You didnt even handle the strings and perform GetPlayerName before sscanf.

As concerned about mine, i assume that cmd is been splitted with sttrtok method. I have already point out the flaws and recommended him to use zcmd.

You must really write with your eyes open. Theres difference b/w cmd and cmdtext.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)