SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/06/2013, 12:27 PM   #1
Sasoft
Big Clucker
 
Sasoft's Avatar
 
Join Date: Nov 2011
Location: My Files
Posts: 136
Reputation: 8
Default Different parameters in one command

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.
Sasoft is offline   Reply With Quote
Old 20/06/2013, 12:37 PM   #2
S0n1COwnsYou
Big Clucker
 
S0n1COwnsYou's Avatar
 
Join Date: Feb 2013
Posts: 93
Reputation: 1
Default Re: Different parameters in one command

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
__________________
...
S0n1COwnsYou is offline   Reply With Quote
Old 20/06/2013, 12:51 PM   #3
Sasoft
Big Clucker
 
Sasoft's Avatar
 
Join Date: Nov 2011
Location: My Files
Posts: 136
Reputation: 8
Default Re: Different parameters in one command

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.
Sasoft is offline   Reply With Quote
Old 20/06/2013, 12:58 PM   #4
S0n1COwnsYou
Big Clucker
 
S0n1COwnsYou's Avatar
 
Join Date: Feb 2013
Posts: 93
Reputation: 1
Default Re: Different parameters in one command

create two commands :P
__________________
...
S0n1COwnsYou is offline   Reply With Quote
Old 20/06/2013, 01:29 PM   #5
SilverKiller
Gangsta
 
SilverKiller's Avatar
 
Join Date: Nov 2012
Location: =>space<=
Posts: 626
Reputation: 56
Default Re: Different parameters in one command

Show us your code.
__________________
I'm working on an admin system called skAdmin, 40% finished.


Scripting simple admin systems with some commands for free, PM me for more info.

I also need testers for my skAdmin filterscript, if you want to test, you are welcome!, just send me a pm.

Quote:
Originally Posted by cessil View Post
I quit school and became a professional sa-mp player
Guys, if i helped anyone incorrectly, please correct me, thank you.
SilverKiller is offline   Reply With Quote
Old 20/06/2013, 01:55 PM   #6
Sasoft
Big Clucker
 
Sasoft's Avatar
 
Join Date: Nov 2011
Location: My Files
Posts: 136
Reputation: 8
Default Re: Different parameters in one command

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;
}
Sasoft is offline   Reply With Quote
Old 20/06/2013, 01:57 PM   #7
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,066
Reputation: 2660
Default Re: Different parameters in one command

Use sscanf's optional specifiers.
__________________
Vince is offline   Reply With Quote
Old 20/06/2013, 02:00 PM   #8
Sasoft
Big Clucker
 
Sasoft's Avatar
 
Join Date: Nov 2011
Location: My Files
Posts: 136
Reputation: 8
Default Re: Different parameters in one command

Quote:
Originally Posted by Vince View Post
Use sscanf's optional specifiers.
Could you give me an example please?
Sasoft is offline   Reply With Quote
Old 20/06/2013, 02:12 PM   #9
SilverKiller
Gangsta
 
SilverKiller's Avatar
 
Join Date: Nov 2012
Location: =>space<=
Posts: 626
Reputation: 56
Default Re: Different parameters in one command

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;
}
__________________
I'm working on an admin system called skAdmin, 40% finished.


Scripting simple admin systems with some commands for free, PM me for more info.

I also need testers for my skAdmin filterscript, if you want to test, you are welcome!, just send me a pm.

Quote:
Originally Posted by cessil View Post
I quit school and became a professional sa-mp player
Guys, if i helped anyone incorrectly, please correct me, thank you.
SilverKiller is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A command with parameters. antonio112 Scripting Help 5 05/12/2011 02:37 AM
Command Parameters Lorenc_ Help Archive 5 08/05/2011 10:06 AM
Where put the parameters of each command universe Help Archive 1 05/12/2010 10:12 PM
Command parameters problem SpiderPork Help Archive 2 21/02/2010 08:10 AM
Count parameters in command godknightx Help Archive 5 25/09/2009 08:28 PM


All times are GMT. The time now is 06:08 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.