Creating a command with multi parameters
#1

Im trying to write a little command with multi-parameters for a server.
The first code that i wrote it was this
Код:
COMMAND:admin(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
  		new
    		option[128],
    		item[128],
    		TargetPlayer,
    		TargetPlayerName [ MAX_PLAYER_NAME ],
    		AmmountP,
    		AdminName [ MAX_PLAYER_NAME ],
    		command[128];
        new szStr[ 128 ];
		GetPlayerName( playerid, AdminName, MAX_PLAYER_NAME );
		GetPlayerName( TargetPlayer, TargetPlayerName, MAX_PLAYER_NAME );
  		sscanf(params, "sss", option, item, command, TargetPlayer, AmmountP);
  		if (isnull(option))
  		{
    		SendClientMessage(playerid, COLOR_WHITE, " USAGE: /admin [Opzione]");
    		SendClientMessage(playerid, COLOR_WHITE, " OPTIONS: Give | Sett | SelfSETT");
    		return 1;
  		}
  		if (!strcmp(item, "Give") || !strcmp(item, "give"))
  		{
    		if (isnull(item))
    		{
        		SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin Give [Ozione]");
        		SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[USI]: soldi | armatura | vita");
				return 1;
    		}
    		if (!strcmp(item, "Soldi") || !strcmp(item, "soldi"))
    		{
				if(sscanf(command, "ui", TargetPlayer, AmmountP)) return SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin give soldi [ID/nome giocatore] [Quantitа]");
				if(!IsPlayerConnected(TargetPlayer)) return SendClientMessage(playerid, COLOR_SYSTEM_ERROR,"[ERRORE]: Il giocatore selezionato non и connesso o id/nome sbagliato");
    			GivePlayerMoney(TargetPlayer, AmmountP);
    			// Messaggio di avviso
    			format( szStr, sizeof(szStr), "[ADMIN]: %s ti ha givvato %i$", AdminName, AmmountP );
    			SendClientMessage(TargetPlayer, COLOR_SYSTEM_INFO, szStr );
    			format( szStr, sizeof(szStr), "[INFO]: Hai givvato a %s %i$", TargetPlayerName, AmmountP );
    			SendClientMessage(playerid, COLOR_SYSTEM_SUCCESS, szStr );
				return 1;
    		}
			else if (!strcmp(item, "Armatura") || !strcmp(item, "armatura"))
    		{
				if(sscanf(command, "u", TargetPlayer)) return SendClientMessage(playerid, 0xFFFFFFF,"Syntax error.Correct usage: /givesoldi [PlayerID] [Soldi]");
				if(!IsPlayerConnected(TargetPlayer)) return SendClientMessage(playerid, 0xFFFFFFF,"That player is not connected to the server!");
				SetPlayerArmour(TargetPlayer, 100);
				return 1;
    		}
    		else if (!strcmp(item, "money"))
    		{
      			// Code for the money...
    		}
  		}
  		else if (!strcmp(option, "Sett") || !strcmp(option, "sett"))
  		{
    		if (isnull(item))
    		{
      			SendClientMessage(playerid, COLOR_WHITE, " USAGE: /admin sett [Opzione]");
      			SendClientMessage(playerid, COLOR_WHITE, " OPTIONS: armatura, vita, Money");
      			return 1;
    		}
			else if (!strcmp(item, "Armatura") || !strcmp(item, "armatura"))
    		{
				if(sscanf(command, "u", TargetPlayer)) return SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin sett armatura [ID/nome giocatore]");
				if(!IsPlayerConnected(TargetPlayer)) return SendClientMessage(playerid, COLOR_SYSTEM_ERROR,"[ERRORE]: Il giocatore selezionato non и connesso o id/nome sbagliato");
				// Setting dell'armatura al giocatore selezionato
				SetPlayerArmour(TargetPlayer, 100);
				// Messaggio di avviso
    			format( szStr, sizeof(szStr), "[ADMIN]: %s ti ha settato l'armatura al massimo", AdminName );
    			SendClientMessage(TargetPlayer, COLOR_SYSTEM_INFO, szStr );
    			format( szStr, sizeof(szStr), "[INFO]: Hai settato l'armatura di %s al massimo", TargetPlayerName );
    			SendClientMessage(playerid, COLOR_SYSTEM_SUCCESS, szStr );
				return 1;
    		}
			else if (!strcmp(item, "Vita") || !strcmp(item, "vita"))
    		{
				if(sscanf(command, "u", TargetPlayer)) return SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin sett armatura [ID/nome giocatore]");
				if(!IsPlayerConnected(TargetPlayer)) return SendClientMessage(playerid, COLOR_SYSTEM_ERROR,"[ERRORE]: Il giocatore selezionato non и connesso o id/nome sbagliato");
				// Setting dell'armatura al giocatore selezionato
				SetPlayerHealth(TargetPlayer, 100);
				// Messaggio di avviso
    			format( szStr, sizeof(szStr), "[ADMIN]: %s ti ha settato la vita al massimo", AdminName );
    			SendClientMessage(TargetPlayer, COLOR_SYSTEM_INFO, szStr );
    			format( szStr, sizeof(szStr), "[INFO]: Hai settato la vita di %s al massimo", TargetPlayerName );
    			SendClientMessage(playerid, COLOR_SYSTEM_SUCCESS, szStr );
				return 1;
    		}
    		else if (!strcmp(item, "money"))
    		{
      			// Code for the money...
    		}
  		}
  		else if (!strcmp(option, "SelfSETT") || !strcmp(option, "selfsett"))
  		{
    		if (isnull(item))
    		{
      			SendClientMessage(playerid, COLOR_WHITE, " USAGE: /admin SelfSETT [Opzione]");
      			SendClientMessage(playerid, COLOR_WHITE, " OPTIONS: Armatura | Vita");
      			return 1;
    		}
    		if (!strcmp(item, "Armatura") || !strcmp(item, "armatura"))
    		{
      			SetPlayerArmour(playerid, 100);
      			SendClientMessage(playerid, COLOR_SYSTEM_SUCCESS, "[INFO]: Ti sei ricaricato l'armatura.");
      			return 1;
   			}
    		else if (!strcmp(item, "Vita") || !strcmp(item, "vita"))
    		{
      			SetPlayerHealth(playerid, 100);
      			SendClientMessage(playerid, COLOR_SYSTEM_SUCCESS, "[INFO]: Ti sei ricaricato la vita.");
      			return 1;
    		}
    		else if (!strcmp(item, "money"))
    		{
      			// Code for the money...
    		}
  		}
   	}
  	else if(PlayerInfo[playerid][pAdmin] == 0)
   	{
        SendClientMessage(playerid, COLOR_SYSTEM_ERROR, "[ERRORE]: Non sei autorizzato ad usare questo comando");
        return 1;
   	}
   	return 1;
}
(Is Im Italian)
But didn't work, for example when the admin try the command:
"/admin give soldi [id] [ammount]"
the command didn't work, the console show only this string
"sscanf warning: Strings without a length are deprecated, please add a destination size."
how i can fix it? or if someone can write a similar command? This is for admin, and i need to create for other player that aren't admins, for example in the RP server for putting or takeing something in the hood of the car.
Reply
#2

I've already tryied to change the value adding [number], but if I insert that in the code, sscanf and in "new", pawno give me an error

Quote:
Originally Posted by ******
Посмотреть сообщение
Check the sscanf topic - it has full documentation on how to do strings there.
Reply
#3

Example for one cmd
pawn Код:
COMMAND:admin(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 1) SendClientMessage(playerid, COLOR_SYSTEM_ERROR, "[ERRORE]: Non sei autorizzato ad usare questo comando");
    else
    {
        if(isnull(params))
        {
            SendClientMessage(playerid, COLOR_WHITE, " USAGE: /admin [Opzione]");
            SendClientMessage(playerid, COLOR_WHITE, " OPTIONS: Give | Sett | SelfSETT");
        }
        else
        {
            new option[10], item[10], TargetPlayer, AmmountP;
            sscanf(params, "s[10]S(unknown)[10]U(-1)I(-1)", option, item, TargetPlayer, AmmountP);
            if(!strcmp(option, "give", true))
            {
                if(!strcmp(item,"unknown",true))
                {
                    SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin Give [Ozione]");
                    SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[USI]: soldi | armatura | vita");
                }
                else
                {
                    if(!strcmp(item, "soldi", true))
                    {
                        if(TargetPlayer == -1 && AmmountP == -1) return SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin give soldi [ID/nome giocatore] [Quantita]");
                        if(!IsPlayerConnected(TargetPlayer)) return SendClientMessage(playerid, COLOR_SYSTEM_ERROR,"[ERRORE]: Il giocatore selezionato non e connesso o id/nome sbagliato");
                        GivePlayerMoney(TargetPlayer, AmmountP);
                    }
                    else if(!strcmp(item, "armatura", true))
                    {
                        if(TargetPlayer == -1) return SendClientMessage(playerid, 0xFFFFFFF,"[INFO]: Usa /admin give armatura [ID/nome giocatore]");
                        if(!IsPlayerConnected(TargetPlayer)) return SendClientMessage(playerid, 0xFFFFFFF,"That player is not connected to the server!");
                        SetPlayerArmour(TargetPlayer, 100.0);
                    }
                    else if(!strcmp(item, "vita", true))
                    {
                        if(TargetPlayer == -1) return SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin give vita [ID/nome giocatore]");
                        if(!IsPlayerConnected(TargetPlayer)) return SendClientMessage(playerid, COLOR_SYSTEM_ERROR,"[ERRORE]: Il giocatore selezionato non e connesso o id/nome sbagliato");
                        SetPlayerHealth(TargetPlayer, 100.0);
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[INFO]: Usa /admin Give [Ozione]");
                        SendClientMessage(playerid, COLOR_SYSTEM_INFO, "[USI]: soldi | armatura | vita");
                    }
                }
            }
        }
    }
    return 1;
}
Reply
#4

pawn Код:
CMD:test(playerid, cmdtext[])
{
    new sz_Param[30], sz_A_Param[30];

    if (sscanf(cmdtext, "s[30]S()[30]", sz_Param, sz_A_Param) )
    {
        SendClientMessage(playerid, -1, "/test parameter | parameter | parameter");
        return 1;
    }

    if (!strcmp(sz_Param, "parameter", true) ){
        new giveplayerid, amount;
        if (sscanf(sz_A_Param, "ud", giveplayerid, amount) )
        {
            SendClientMessage(playerid, -1, "/test parameter [ID/partofName] [amount]");
            return 1;
        }

    }

    else if (!strcmp(sz_Param, "parameter_two", true) ) {
        new Float:givefloat;
        if (sscanf(sz_A_Param, "f", givefloat) )
        {
            SendClientMessage(playerid, -1, "/test parameter_two [float]");
            return 1;
        }

    }

    return 1;
}
Here's a much simpler way of doing it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)