Take specific gun from trunk
#1

Hello, i am having a /trunk system, there are 4 slots for weapons, and to take out a weapon from the trunk you must type /trunk take gun, and when you type that it will just give you a random gun from the trunk, i want to have it like that you can take out a specific gun, example if you type /trunk take 2, and that will give you weapon number two in the trunk.. i hope any of you Guys can help me out with this.. Rep+

pawn Код:
if(!strcmp(tmp,"take",true))
            {
                tmp = strtok(cmdtext,idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /trunk take [gun/pot/crack/mats]");
                    return 1;
                }
                if(strcmp(tmp,"gun",true) == 0)
                {
                    new vehicleid=GetClosestCar(playerid);
                    if(Trunk[vehicleid] == 0)
                        return SendClientMessage(playerid, COLOR_GREY, "You must open the trunk before you can take weapons from it.");
                    new counter = 0;
                    new result;
                    new plyName[MAX_PLAYER_NAME];

                    GetPlayerName(playerid, plyName, MAX_PLAYER_NAME);
                    for(new i; i != MAX_VEHICLES; i++)
                    {
                        new dist = CheckPlayerDistanceToVehicle(3.5, playerid, i);
                        if(dist)
                        {
                            result = i;
                            counter++;
                        }
                    }

                    switch(counter)
                    {
                        case 0:
                        {
                            SendClientMessage(playerid, COLOR_GREY, "   No cars with trunk near you");
                            return 1;
                        }

                        case 1:
                        {
                            if(IsPlayerInAnyVehicle(playerid))
                            {
                                SendClientMessage(playerid, COLOR_GREY, "   You can't reach the trunk from here.");
                                return 1;
                            }
                            if(IsAnOwnableCar(result))
                            {
                                if(VehicleOwned[result] == PlayerInfo[playerid][pCarkey]) { }
                                else if(VehicleOwned[result] == PlayerInfo[playerid][pCarkey2]) { }
                                else if(VehicleOwned[result] == PlayerInfo[playerid][pCarkey3]) { }
                                else if(VehicleOwned[result] == PlayerInfo[playerid][pCarkey4]) { }
                                else if(VehicleOwned[result] == PlayerInfo[playerid][pCarkey5]) { }
                                else
                                {
                                    SendClientMessage(playerid, COLOR_GREY, "  Trunk is locked !");
                                    return 1;
                                }
                            }

                            if(IsNotAEngineCar(result))
                            {
                                SendClientMessage(playerid, COLOR_GREY, "  This vehicle doesn't have the trunk !");
                                return 1;
                            }

                            if(VehicleOwned[result] != SCRIPT_CARS)
                            {
                                new key2 = VehicleOwned[result];
                                if(CarInfo[key2][cTrunkCounter] != 0)
                                {
                                    new gunName[100];
                                    AddWeapon(playerid, CarInfo[key2][cTrunkWep][CarInfo[key2][cTrunkCounter]]);
                                    GetWeaponName(CarInfo[key2][cTrunkWep][CarInfo[key2][cTrunkCounter]], gunName, sizeof(gunName));
                                    CarInfo[key2][cTrunkWep][CarInfo[key2][cTrunkCounter]] = '\0';
                                    CarInfo[key2][cTrunkAmmo][CarInfo[key2][cTrunkCounter]] = '\0';
                                    CarInfo[key2][cTrunkCounter]--;
                                    GetPlayerName(playerid, sendername, sizeof(sendername));
                                    format(string, sizeof(string), "* %s takes a %s from the trunk.", sendername, gunName);
                                    ProxDetector(25.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                                    SaveCars();
                                    return 1;
                                }
                            }
                            else if(VehicleOwned[result] == SCRIPT_CARS)
                            {
                                if(vehTrunkCounter[result] != 0)
                                {
                                    new gunName[100];
                                    AddWeapon(playerid, vehTrunk[result][vehTrunkCounter[result]]);
                                    GetWeaponName(vehTrunk[result][vehTrunkCounter[result]], gunName, sizeof(gunName));
                                    vehTrunk[result][vehTrunkCounter[result]] = '\0';
                                    vehTrunkAmmo[result][vehTrunkCounter[result]] = '\0';
                                    vehTrunkCounter[result]--;
                                    GetPlayerName(playerid, sendername, sizeof(sendername));
                                    format(string, sizeof(string), "* %s takes a %s from the trunk.", sendername, gunName);
                                    ProxDetector(25.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                                    SaveTrunk();
                                    return 1;
                                }
                            }

                            else
                            {
                                SendClientMessage(playerid, COLOR_GREY, "   Trunk is empty ! ");
                                return 1;
                            }
                        }

                        default:
                        {
                            SendClientMessage(playerid, COLOR_GREY, "   Found more then one car in range");
                            return 1;
                        }
                    }
                    return 1;
                }
Reply
#2

See, that's why you should use sscanf.
pawn Код:
CMD:take(playerid, params[])
{
    new object[ 7 ], slotid;
   
    if(!sscanf(params, "s[7]I(-1)", object, slotid)) {
        if(!strcmp(object, "gun", true)) {
            if(slotid == -1) { //No parameter passed for 'slotid', give random gun (Only typed /take gun)
            }
            else {
                if(!(0 <= slotid <= 3))
                    return SendClientMessage(playerid, -1, "Only 4 slots (0 - 3) available.");
                //Give gun
            }
         }
         else if(!strcmp(object, "pot", true))
         //Same with crack, mats...
     }
     return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)