SA-MP Forums Archive
How to make multiple commands into one? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to make multiple commands into one? (/showthread.php?tid=554890)



How to make multiple commands into one? - LeXuZ - 05.01.2015

Hello, I wanted to put a couple of commands into one command. I wanted it has /refund <ID> <Vehicle/Money etc..>
I don't know how I would put it into a single command, here is the commands if you are able to show me how to make it into the single command.
pawn Код:
ACMD:vehicle(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 2) return 0;
    new car;
    if(sscanf(params, "ud", ID, car)) return SCM(playerid, orange, "Give a player a vehicle: /vehicle <ID> <400 - 611>");
    if(ID == IPI) return SCM(playerid, red, "*Player is not connected!");
    new Float: x, Float: y, Float: z, Float: a;
    GetPlayerPos(ID, x, y, z);
    GetPlayerFacingAngle(ID, a);
    new rd1 = random(20);
    new rd2 = random(20);
    format(ustr, sizeof(ustr), "*You have given %s vehicle ID %d", GetName(ID), car);
    SCM(playerid, Lblue, ustr);
    format(ustr, sizeof(ustr), "%s %s has given you vehicle ID %d", AdminLevelName(playerid), GetName(playerid), car);
    SCM(ID, red, ustr);
    new veh = CreateVehicle(car, x, y, z, a, rd1, rd2, -1);
    PutPlayerInVehicle(ID, veh, 0);
    return 1;
}
pawn Код:
CMD:givemoney(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 2)return 0;
    new Amount;
    if(sscanf(params,"u",ID, Amount)) return SCM(playerid, orange, "Give money to a player: /givemoney <ID> <Amount>");
    GivePlayerMoney(ID, Amount);
    GetPlayerName(playerid,pName, MAX_PLAYER_NAME);
    format(ustr, sizeof(ustr), "%s %s has given you $%s", AdminLevelName(playerid),pName, Amount);
    SCM(ID, red, ustr);
    return 1;
}
If you know how to help it would be great!

I've also got a problem with my money command

pawn Код:
CMD:givemoney(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 2)return 0;
    new Amount;
    if(sscanf(params,"u",ID, Amount)) return SCM(playerid, orange, "Give money to a player: /givemoney <ID> <Amount>");
    GivePlayerMoney(ID, Amount);
    GetPlayerName(playerid,pName, MAX_PLAYER_NAME);
    format(ustr, sizeof(ustr), "%s %s has given you $%s", AdminLevelName(playerid),pName, Amount);
    SCM(ID, red, ustr);
    return 1;
}
It doesn't give the money to the player nor does it tell what has been given.

Thanks you for helping!


Re: How to make multiple commands into one? - Burooj - 05.01.2015

I don't know scripting i was learning something about the scripts with base to start to me scripting for my self and i can make own gamemode when i finish learn to scripts i start a server becouse now iam study plus two student this year i have to learn perfectly , he,


Re: How to make multiple commands into one? - Schneider - 05.01.2015

Here's the solution to your second problem:
You are using sscanf wrong. the second parameter of the sscanf-function are the format-specifiers. If you want to get 2 params after the command, you should enter 2 specifiers.
"d" for integers, "s[size]" for strings, "f" for floats and "u" for playerids". You want 2 params so you should add an extra "d" after the "u":

pawn Код:
sscanf(params,"ud",ID, Amount)
Another examples: If you have a "/jail [id] [minutes] [reason]" command you should use:
pawn Код:
new ID, Minutes, Reason[64];
sscanf(params, "uds[64]", ID, Minutes, Reason);
Or if you have a command like "/gotocoordinate [x] [y] [z]" you should use:

pawn Код:
new Float:X, Float:Y, Float:Z;
sscanf(params, "fff", X, Y, Z);



Re: How to make multiple commands into one? - LeXuZ - 05.01.2015

Quote:

I don't know scripting i was learning something about the scripts with base to start to me scripting for my self and i can make own gamemode when i finish learn to scripts i start a server becouse now iam study plus two student this year i have to learn perfectly , he,

Think you posted in the wrong place...
Quote:

Here's the solution to your second problem:
You are using sscanf wrong. the second parameter of the sscanf-function are the format-specifiers. If you want to get 2 params after the command, you should enter 2 specifiers.
"d" for integers, "s[size]" for strings, "f" for floats and "u" for playerids". You want 2 params so you should add an extra "d" after the "u":

This worked for the givemoney command, thank you, Schneider.
Still waiting for help on putting the codes together.


Re: How to make multiple commands into one? - vassilis - 05.01.2015

You want /refund veh id and /vehicle id doing the same command?


Re: How to make multiple commands into one? - Schneider - 05.01.2015

To put commands together you first have to extract the params the player enters (using sscanf), then you use strcmp to check if the entered param equals either "vehicle" or "money".

pawn Код:
CMD:refund(playerid, params[])
{
    new ID, Type[12], Param3;
    sscanf(params, "us[12]d", ID, Type, Param3);
    if(!IsPlayerConnected(ID)) return SCM(playerid, -1, "Player not connected");
   
    if(strcmp(Type, "vehicle", true) == 0)
    {
        if(Param3 < 400 || Param3 > 611) return SCM(playerid, -1, "Use: /refund vehicle [400-611]");
        new Float: x, Float: y, Float: z, Float: a;
        GetPlayerPos(ID, x, y, z);
        GetPlayerFacingAngle(ID, a);
        format(ustr, sizeof(ustr), "*You have given %s vehicle ID %d", GetName(ID), car);
        SCM(playerid, Lblue, ustr);
        format(ustr, sizeof(ustr), "%s %s has given you vehicle ID %d", AdminLevelName(playerid), GetName(playerid), car);
        SCM(ID, red, ustr);
        new veh = CreateVehicle(Param3, x, y, z, a, random(20), random(20), -1);
        PutPlayerInVehicle(ID, veh, 0);
    }
   
    else if(strcmp(Type, "money", true) == 0)
    {
        if (pInfo[playerid][Adminlevel] < 2) return 0;
        GivePlayerMoney(ID, Param3);
        GetPlayerName(playerid,pName, MAX_PLAYER_NAME);
        format(ustr, sizeof(ustr), "%s %s has given you $%d", AdminLevelName(playerid),pName, Param3);
        SCM(ID, red, ustr);
    }
    else
    {
        SCM(playerid, -1, "Use: /refund [id] [vehicle/money] [param]");
    }
    return 1;
}