How to add options instead of one option
#1

How can i change that to be with 3 options instead of one only
Код:
CMD:setscore(playerid,params[]) {
	if(pInfo[playerid][Admin] >= 5) {
	    new tmp[256], tmp2[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index);
 	    if(isnull(tmp) || isnull(tmp2) || !IsNumeric(tmp2)) return SendClientMessage(playerid, RED, "USAGE: /setcriminal [playerid] [score]");
		new player1 = strval(tmp), score = strval(tmp2), string[128];
		if(pInfo[player1][Admin] == ServerInfo[MaxAdminLevel] && pInfo[playerid][Admin] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command on this admin.");
        if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID) {
		{
			CMDMessageToAdmins(playerid,"SETSCORE");
			format(string, sizeof(string), "You have set \"%s's\" criminal level to '%d' ", pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string);
			if(player1 != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your criminal level to '%d'", pInfo[playerid][Name], score); SendClientMessage(player1,blue,string); }
   			return SetPlayerCriminal(player1, score);
		}
	    } else return SendClientMessage(playerid,RED,"SERVER: Player is not connected");
	} else return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");
}
I want it to be like that,
Usage: /setscore <id> <score> <ammount>
Available Scores: Criminal, Cop, Paramedic

Here is my Paramedic & Cop codes
Код:
SetPlayerCop(player1, score), SetPlayerParamedic(player1, score), pInfo[playerid][Cop], pInfo[playerid][Paramedic]
Reply
#2

You should use sscanf for what you'd like to achieve: https://sampforum.blast.hk/showthread.php?tid=602923
Reply
#3

As FreAkeD said, you should use sscanf.

PHP код:
CMD:setscore(playerid,params[])
{
    if(
pInfo[playerid][Admin] >= 5)
    {
        new 
targetidscorestring[144];
         if(
sscanf(params"ud"targetidscore)) return SendClientMessage(playeridRED"USAGE: /setcriminal [playerid] [score]");
        if(
pInfo[targetid][Admin] == ServerInfo[MaxAdminLevel] && pInfo[playerid][Admin] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command on this admin.");
        if(
IsPlayerConnected(targetid) && targetid != INVALID_PLAYER_ID)
        {
            
CMDMessageToAdmins(playerid,"SETSCORE");
            
format(stringsizeof(string), "You have set \"%s's\" criminal level to '%d' "pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string);
            if(
targetid != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your criminal level to '%d'"pInfo[playerid][Name], score); SendClientMessage(targetid,blue,string); }
            return 
SetPlayerCriminal(targetidscore);
        } else return 
SendClientMessage(playerid,RED,"SERVER: Player is not connected");
    } else return 
SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");

Reply
#4

PHP код:
CMD:setscore(playeridparams[])
{
    new 
options[128], targetidscorestring[144];
    if(
pInfo[playerid][Admin] >= 5)
    if(
pInfo[targetid][Admin] == ServerInfo[MaxAdminLevel] && pInfo[playerid][Admin] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command on this admin.");
    if(
IsPlayerConnected(targetid) && targetid != INVALID_PLAYER_ID)
    if(
sscanf(params"us[128]d",targetid,options,score))
    {
        
SendClientMessage(playerid, -1"Usage: /setscore [playerid] [Option] [score]");
        
SendClientMessage(playerid, -1"{FF0000}Option:{00FF00}Criminal, Cop, Paramedic");
        return 
1;
    }
    else if(!
strcmp(options"Criminal"true5))
    {
      
CMDMessageToAdmins(playerid,"SETSCORE");
      
format(stringsizeof(string), "You have set \"%s's\" criminal level to '%d' "pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string);
      if(
targetid != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your criminal level to '%d'"pInfo[playerid][Name], score); SendClientMessage(targetid,blue,string); }
      return 
SetPlayerCriminal(targetidscore);
      
pInfo[targetid][Criminal] = score;
    }
    else if(!
strcmp(options"Cop"true5))
    {
      
CMDMessageToAdmins(playerid,"SETSCORE");
      
format(stringsizeof(string), "You have set \"%s's\" criminal level to '%d' "pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string);
      if(
targetid != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your cop level to '%d'"pInfo[playerid][Name], score); SendClientMessage(targetid,blue,string); }
      return 
SetPlayerCop(targetidscore);
      
pInfo[targetid][Cop] = score;
    }
    else if(!
strcmp(options"Paramedic"true5))
    {
      
CMDMessageToAdmins(playerid,"SETSCORE");
      
format(stringsizeof(string), "You have set \"%s's\" criminal level to '%d' "pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string);
      if(
targetid != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your paramedic level to '%d'"pInfo[playerid][Name], score); SendClientMessage(targetid,blue,string); }
      return 
SetPlayerParamedic(targetidscore);
      
pInfo[targetid][Paramedic] = score;
    }
    else 
SendClientMessage(playeridCOLOR_RED"Invalid Option.");
    else return 
SendClientMessage(playerid,RED,"SERVER: Player is not connected");
    else return 
SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");
    return 
1;

try this cmd if u get error tell me
Reply
#5

C:\Osher\Scripting Learning\Scripting Projects\Project #2\CNR - Project v0.0.3\gamemodes\CNR.pwn(2194) : error 029: invalid expression, assumed zero
C:\Osher\Scripting Learning\Scripting Projects\Project #2\CNR - Project v0.0.3\gamemodes\CNR.pwn(2194) : warning 215: expression has no effect
C:\Osher\Scripting Learning\Scripting Projects\Project #2\CNR - Project v0.0.3\gamemodes\CNR.pwn(2194) : error 001: expected token: ";", but found "return"

"
else return SendClientMessage(playerid,RED,"SERVER: Player is not connected");
else return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");
return 1;
"
Reply
#6

Quote:
Originally Posted by Oshery
Посмотреть сообщение
C:\Osher\Scripting Learning\Scripting Projects\Project #2\CNR - Project v0.0.3\gamemodes\CNR.pwn(2194) : error 029: invalid expression, assumed zero
C:\Osher\Scripting Learning\Scripting Projects\Project #2\CNR - Project v0.0.3\gamemodes\CNR.pwn(2194) : warning 215: expression has no effect
C:\Osher\Scripting Learning\Scripting Projects\Project #2\CNR - Project v0.0.3\gamemodes\CNR.pwn(2194) : error 001: expected token: ";", but found "return"

"
else return SendClientMessage(playerid,RED,"SERVER: Player is not connected");
else return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");
return 1;
"
remove these lines then try
Reply
#7

Try this:
PHP код:
CMD:setscore(playeridparams[]) 

    new 
options[128], targetidscorestring[144]; 
    if(
pInfo[playerid][Admin] >= 5) {
    if(
pInfo[targetid][Admin] == ServerInfo[MaxAdminLevel] && pInfo[playerid][Admin] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command on this admin."); 
    if(
IsPlayerConnected(targetid) && targetid != INVALID_PLAYER_ID) {
    if(
sscanf(params"us[128]d",targetid,options,score)) 
    { 
        
SendClientMessage(playerid, -1"Usage: /setscore [playerid] [Option] [score]"); 
        
SendClientMessage(playerid, -1"{FF0000}Option:{00FF00}Criminal, Cop, Paramedic"); 
        return 
1
    } 
    else if(!
strcmp(options"Criminal"true5)) 
    { 
      
CMDMessageToAdmins(playerid,"SETSCORE"); 
      
format(stringsizeof(string), "You have set \"%s's\" criminal level to '%d' "pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string); 
      if(
targetid != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your criminal level to '%d'"pInfo[playerid][Name], score); SendClientMessage(targetid,blue,string); } 
      return 
SetPlayerCriminal(targetidscore); 
      
pInfo[targetid][Criminal] = score
    } 
    else if(!
strcmp(options"Cop"true5)) 
    { 
      
CMDMessageToAdmins(playerid,"SETSCORE"); 
      
format(stringsizeof(string), "You have set \"%s's\" criminal level to '%d' "pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string); 
      if(
targetid != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your cop level to '%d'"pInfo[playerid][Name], score); SendClientMessage(targetid,blue,string); } 
      return 
SetPlayerCop(targetidscore); 
      
pInfo[targetid][Cop] = score
    } 
    else if(!
strcmp(options"Paramedic"true5)) 
    { 
      
CMDMessageToAdmins(playerid,"SETSCORE"); 
      
format(stringsizeof(string), "You have set \"%s's\" criminal level to '%d' "pInfo[playerid][Name], score); SendClientMessage(playerid,blue,string); 
      if(
targetid != playerid) { format(string,sizeof(string),"Administrator \"%s\" has set your paramedic level to '%d'"pInfo[playerid][Name], score); SendClientMessage(targetid,blue,string); } 
      return 
SetPlayerParamedic(targetidscore); 
      
pInfo[targetid][Paramedic] = score
    } 
    else 
SendClientMessage(playeridCOLOR_RED"Invalid Option."); 
    } else return 
SendClientMessage(playerid,RED,"SERVER: Player is not connected"); 
    } else return 
SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command."); 
    return 
1

Reply
#8

I also tried it and it didn't work, when i used /givescore with a wrong id it just gave me the message "unknown command" and then when i tried doing it correctly it wrote me the same like something went wrong
Код:
CMD:givescore(playerid, params[])
{
    new options[128], score;
    if(pInfo[playerid][Admin] >= 5) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");
    if(pInfo[toplayerid][Admin] == ServerInfo[MaxAdminLevel] && pInfo[playerid][Admin] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command on this admin.");
    if(IsPlayerConnected(toplayerid) && toplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid,RED,"SERVER: Player is not connected");

    if(sscanf(params, "us[128]d",toplayerid,options,score))
    {
        SendClientMessage(playerid, -1, "Usage: /givescore [playerid] [Option] [score]");
        SendClientMessage(playerid, -1, "{FF0000}Option:{00FF00}Criminal, Cop, Paramedic");
        return 1;
    }
    else if(!strcmp(options, "criminal", true, 5))
    {
     format(str, SOS, "Admin: %s has used command GIVESCORE", pInfo[playerid][Name]);
     SendAdminMessage(OR, str);
     format(str, SOS, "Administrator %s have given you %s criminal scores", pInfo[playerid][Name], score);
     SendClientMessage(toplayerid, OR, str);
     return a_GivePlayerCriminal(toplayerid, score);
    }
    else if(!strcmp(options, "cop", true, 5))
    {
     format(str, SOS, "Admin: %s has used command GIVESCORE", pInfo[playerid][Name]);
     SendAdminMessage(OR, str);
     format(str, SOS, "Administrator %s have given you %s cop scores", pInfo[playerid][Name], score);
     SendClientMessage(toplayerid, OR, str);
	 return a_GivePlayerCop(toplayerid, score);
    }
    else if(!strcmp(options, "paramedic", true, 5))
    {
     format(str, SOS, "Admin: %s has used command GIVESCORE", pInfo[playerid][Name]);
     SendAdminMessage(OR, str);
     format(str, SOS, "Administrator %s have given you %s paramedic scores", pInfo[playerid][Name], score);
     SendClientMessage(toplayerid, OR, str);
     return a_GivePlayerParamedic(toplayerid, score);
    }
    else SendClientMessage(playerid, COLOR_RED, "Invalid Option.");
    return 1;
}
Reply
#9

Quote:
Originally Posted by Oshery
Посмотреть сообщение
I also tried it and it didn't work, when i used /givescore with a wrong id it just gave me the message "unknown command" and then when i tried doing it correctly it wrote me the same like something went wrong
Код:
CMD:givescore(playerid, params[])
{
    new options[128], score;
    if(pInfo[playerid][Admin] >= 5) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");
    if(pInfo[toplayerid][Admin] == ServerInfo[MaxAdminLevel] && pInfo[playerid][Admin] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command on this admin.");
    if(IsPlayerConnected(toplayerid) && toplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid,RED,"SERVER: Player is not connected");

    if(sscanf(params, "us[128]d",toplayerid,options,score))
    {
        SendClientMessage(playerid, -1, "Usage: /givescore [playerid] [Option] [score]");
        SendClientMessage(playerid, -1, "{FF0000}Option:{00FF00}Criminal, Cop, Paramedic");
        return 1;
    }
    else if(!strcmp(options, "criminal", true, 5))
    {
     format(str, SOS, "Admin: %s has used command GIVESCORE", pInfo[playerid][Name]);
     SendAdminMessage(OR, str);
     format(str, SOS, "Administrator %s have given you %s criminal scores", pInfo[playerid][Name], score);
     SendClientMessage(toplayerid, OR, str);
     return a_GivePlayerCriminal(toplayerid, score);
    }
    else if(!strcmp(options, "cop", true, 5))
    {
     format(str, SOS, "Admin: %s has used command GIVESCORE", pInfo[playerid][Name]);
     SendAdminMessage(OR, str);
     format(str, SOS, "Administrator %s have given you %s cop scores", pInfo[playerid][Name], score);
     SendClientMessage(toplayerid, OR, str);
	 return a_GivePlayerCop(toplayerid, score);
    }
    else if(!strcmp(options, "paramedic", true, 5))
    {
     format(str, SOS, "Admin: %s has used command GIVESCORE", pInfo[playerid][Name]);
     SendAdminMessage(OR, str);
     format(str, SOS, "Administrator %s have given you %s paramedic scores", pInfo[playerid][Name], score);
     SendClientMessage(toplayerid, OR, str);
     return a_GivePlayerParamedic(toplayerid, score);
    }
    else SendClientMessage(playerid, COLOR_RED, "Invalid Option.");
    return 1;
}
wht errors you got in your code

PHP код:
CMD:givescore(playeridparams[])
{
    new 
options[128], score;
    if(
pInfo[playerid][Admin] >= 5) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command.");
    if(
pInfo[toplayerid][Admin] == ServerInfo[MaxAdminLevel] && pInfo[playerid][Admin] != ServerInfo[MaxAdminLevel]) return SendClientMessage(playerid,RED,"SERVER: You are not authorized to use this command on this admin.");
    if(
IsPlayerConnected(toplayerid) && toplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid,RED,"SERVER: Player is not connected");
    if(
sscanf(params"us[128]d",toplayerid,options,score))
    {
        
SendClientMessage(playerid, -1"Usage: /givescore [playerid] [Option] [score]");
        
SendClientMessage(playerid, -1"{FF0000}Option:{00FF00}Criminal, Cop, Paramedic");
        return 
1;
    }
    else if(!
strcmp(options"criminal"true5))
    {
     
format(strSOS"Admin: %s has used command GIVESCORE"pInfo[playerid][Name]);
     
SendAdminMessage(OR, str);
     
format(strSOS"Administrator %s have given you %s criminal scores"pInfo[playerid][Name], score);
     
SendClientMessage(toplayerid, OR, str);
     return 
a_GivePlayerCriminal(toplayeridscore);
    }
    else if(!
strcmp(options"cop"true5))
    {
     
format(strSOS"Admin: %s has used command GIVESCORE"pInfo[playerid][Name]);
     
SendAdminMessage(OR, str);
     
format(strSOS"Administrator %s have given you %s cop scores"pInfo[playerid][Name], score);
     
SendClientMessage(toplayerid, OR, str);
     return 
a_GivePlayerCop(toplayeridscore);
    }
    else if(!
strcmp(options"paramedic"true5))
    {
     
format(strSOS"Admin: %s has used command GIVESCORE"pInfo[playerid][Name]);
     
SendAdminMessage(OR, str);
     
format(strSOS"Administrator %s have given you %s paramedic scores"pInfo[playerid][Name], score);
     
SendClientMessage(toplayerid, OR, str);
     return 
a_GivePlayerParamedic(toplayeridscore);
    }
    else 
SendClientMessage(playeridCOLOR_RED"Invalid Option.");
    return 
1;

Reply
#10

After doing the command with a wrong id (in purpose) it returns me a message "Unknown Command" and then it wont work for the next time i use it correctly, it will keep return me an unknown command message.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)