Different parameters in one command
#1

I am kind of stuck at the moment, I'm trying to make a command where you can give your weapon or drugs to another player. I have covered the weapon part but now I have to make the drug part. Which needs another parameters. Is there a way to add it without screwing the weapon part up?

Example weapon part:
/give weapon target

Example drug part:
/give drugs target amount

If I add amount to sscanf it won't let me execute the weapon part anymore.
Reply
#2

make it like that
Example weapon part:
/give weapon target weaponid

Example drug part:
/give drugs target amount

now u have three params in each
Reply
#3

Quote:
Originally Posted by S0n1COwnsYou
View Post
make it like that
Example weapon part:
/give weapon target weaponid

Example drug part:
/give drugs target amount

now u have three params in each
Yea, I was thinking of that before, but I just want it to give the gun which the character is holding at the moment.
Reply
#4

create two commands :P
Reply
#5

Show us your code.
Reply
#6

Quote:
Originally Posted by SilverKiller
View Post
Show us your code.
pawn Code:
COMMAND:give(playerid, params[])
{
    new string[128], target, amount;
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "SERVER: You need to login first before using any command.");
    if(sscanf(params, " s[32]u", params, target, amount))
    {
        SCM(playerid, GREY, "[Parameters]: /give [option] [playerid]");
        SCM(playerid, COLOR_FADE1, "[Options]: weapon | weed");
        return 1;
    }
    if(!strcmp(params, "weapon", true))
    {
        if(target == playerid) return SCM(playerid, COLOR_GREY, "SERVER: You can't give it to yourself.");
        if(IsPlayerConnected(target))
        {
            if(IsPlayerNearPlayer(playerid, target, 1))
            {
                new playergun;
                new playerammo;
                playergun = GetPlayerWeapon(playerid);
                playerammo = GetPlayerAmmo(playerid);
                format(string, sizeof(string), "%s has given you a %s with %d ammo.", RPN(playerid), RWN(GetPlayerWeapon(playerid)), GetPlayerAmmo(playerid));
                SCM(target, COLOR_NEWBLUE, string);
                format(string, sizeof(string), "You have given %s a %s with %d ammo.", RPN(target), RWN(GetPlayerWeapon(playerid)), GetPlayerAmmo(playerid));
                SCM(playerid, COLOR_NEWBLUE, string);
                format(string, sizeof(string), "%s glances towards %s as he gives him/her something.", RPN(playerid), RPN(target));
                SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
                SetPlayerChatBubble(playerid, string, COLOR_PURPLE, 15.0, 5000);
                SetPlayerFacingPlayer(playerid, target);
                ApplyAnimation(playerid,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
                ApplyAnimation(target,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
                GiveZaiatWeapon(target, playergun, playerammo);
                RemoveZaiatWeapon(playerid, playergun);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "SERVER: You are too far away from that player.");
                return 1;
            }
        }
    }
    if(strcmp(params, "weed", true))
    {
        if(IsPlayerLoggedIn(playerid))
        {
            SCM(playerid, GREY, "[Parameters]: /give weed [playerid] [amount]");
            return 1;
        }
        if(PlayerInfo[playerid][pWeed] < amount) return SendClientMessage(playerid, COLOR_GREY, "SERVER: You don't have that much weed.");
        PlayerInfo[playerid][pWeed] -= amount;
        PlayerInfo[target][pWeed] += amount;
        format(string, sizeof(string), "NOTE: %s has given you a %d grams of weed.", RPN(playerid), amount);
        SCM(target, COLOR_LIGHTBLUE, string);
        format(string, sizeof(string), "NOTE: You have given %s, %d grams of weed.", RPN(target), amount);
        SCM(playerid, COLOR_LIGHTBLUE, string);
        format(string, sizeof(string), "%s glances towards %s as he gives him/her something.", RPN(playerid), RPN(target));
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        SetPlayerChatBubble(playerid, string, COLOR_PURPLE, 15.0, 5000);
        SetPlayerFacingPlayer(playerid, target);
        ApplyAnimation(playerid,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
        ApplyAnimation(target,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
    }
    return 1;
}
Reply
#7

Use sscanf's optional specifiers.
Reply
#8

Quote:
Originally Posted by Vince
View Post
Use sscanf's optional specifiers.
Could you give me an example please?
Reply
#9

I'm not sure if this will work, but try it:

pawn Code:
COMMAND:giveweapon(playerid, params[])
{
    new target, weapon, amount;
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "SERVER: You need to login first before using any command.");
    if(sscanf(params, "udd", target, amount))
    {
        SCM(playerid, GREY, "[Parameters]: /give [option] [playerid] [amount]");
        SCM(playerid, COLOR_FADE1, "[Options]: weapon | weed");
        return 1;
    }
    if(!strcmp(params, "weapon", true))
    {
        if(target == playerid) return SCM(playerid, COLOR_GREY, "SERVER: You can't give it to yourself.");
        if(IsPlayerConnected(target))
        {
            if(IsPlayerNearPlayer(playerid, target, 1))
            {
                if(sscanf(params, "udd", target, amount)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /give weapon [playerid] [weapon] [amount]");
                new string[128];
                format(string, sizeof(string), "%s has given you a %s with %d ammo.", RPN(playerid), RWN(GetPlayerWeapon(playerid)), GetPlayerAmmo(playerid));
                SCM(target, COLOR_NEWBLUE, string);
                format(string, sizeof(string), "You have given %s a %s with %d ammo.", RPN(target), RWN(GetPlayerWeapon(playerid)), GetPlayerAmmo(playerid));
                SCM(playerid, COLOR_NEWBLUE, string);
                format(string, sizeof(string), "%s glances towards %s as he gives him/her something.", RPN(playerid), RPN(target));
                SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
                SetPlayerChatBubble(playerid, string, COLOR_PURPLE, 15.0, 5000);
                SetPlayerFacingPlayer(playerid, target);
                ApplyAnimation(playerid,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
                ApplyAnimation(target,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
                GivePlayerWeapon(target, weapon, amount);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "SERVER: You are too far away from that player.");
                return 1;
            }
        }
    }
    if(strcmp(params, "weed", true))
    {
        new wAmount;
        new tArget;
        if(IsPlayerLoggedIn(playerid))
        {
            SCM(playerid, GREY, "You are not logged in!");
            return 1;
        }
        new Str[128];
        else if(sscanf(params, "ud", tArget, wAmount)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /give weed [playerid] [amount]");
        else if(PlayerInfo[playerid][pWeed] < wAmount) return SendClientMessage(playerid, COLOR_GREY, "SERVER: You don't have that much weed.");
        PlayerInfo[playerid][pWeed] -= wAmount;
        PlayerInfo[target][pWeed] += wAmount;
        format(Str, sizeof(Str), "NOTE: %s has given you a %d grams of weed.", RPN(playerid), wAmount);
        SCM(target, COLOR_LIGHTBLUE, Str);
        format(Str, sizeof(Str), "NOTE: You have given %s, %d grams of weed.", RPN(target), wAmount);
        SCM(playerid, COLOR_LIGHTBLUE, Str);
        format(Str, sizeof(Str), "%s glances towards %s as he gives him/her something.", RPN(playerid), RPN(tArget));
        SendNearbyMessage(playerid, 15, Str, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        SetPlayerChatBubble(playerid, Str, COLOR_PURPLE, 15.0, 5000);
        SetPlayerFacingPlayer(playerid, tArget);
        ApplyAnimation(playerid,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
        ApplyAnimation(tArget,"DEALER", "DEALER_DEAL",4.0,0,0,0,0,0);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)