Trunk system
#1

Hello guys I'm working on my own trunk system not only open/close but I want to make so players will be able to store weapons inside and take them out but I don't have any single clue how to do this, I already looked in 1 script and tested it on my test server and it's not working.. so I need to ask you guys to help me to figure out with this, maybe show part of codes, enums? and so on, I'm working with Dialogs.

Thanks for help.
Reply
#2

Okay guys this is what I tried:

pawn Код:
if(dialogid == DIALOG_PUT) // Put items in trunk
    {
        new buffer[512];
        new gunname[100];
        new gunID = GetPlayerWeapon(playerid);
        new gunAmmo = GetPlayerAmmo(playerid);
        GetWeaponName(gunID, gunname, sizeof(gunname));
        new vehicleid = GetPlayerVehicleID(playerid);
        if(response)
        {
            if(listitem == 0) // Slot 1
            {
                iTrunk[vehicleid][tWeapon1] = gunID;
                iTrunk[vehicleid][tAmmo1] = gunAmmo;
                RemovePlayerWeapon(playerid, gunID);
            }
            if(listitem == 1) // Slot 2
            {
                iTrunk[vehicleid][tWeapon2] = gunID;
                iTrunk[vehicleid][tAmmo2] = gunAmmo;
                RemovePlayerWeapon(playerid, gunID);
            }
            if(listitem == 2) // Slot 3
            {
                iTrunk[vehicleid][tWeapon3] = gunID;
                iTrunk[vehicleid][tAmmo3] = gunAmmo;
                RemovePlayerWeapon(playerid, gunID);
            }
            if(listitem == 3) // Slot 4
            {
                iTrunk[vehicleid][tWeapon4] = gunID;
                iTrunk[vehicleid][tAmmo4] = gunAmmo;
                RemovePlayerWeapon(playerid, gunID);
            }
            if(listitem == 4) // Slot 5
            {
                iTrunk[vehicleid][tWeapon5] = gunID;
                iTrunk[vehicleid][tAmmo5] = gunAmmo;
                RemovePlayerWeapon(playerid, gunID);
            }
            if(listitem == 5) // Slot 6
            {
                iTrunk[vehicleid][tWeapon6] = gunID;
                iTrunk[vehicleid][tAmmo6] = gunAmmo;
                RemovePlayerWeapon(playerid, gunID);
            }
        }
        return 1;
    }
    if(dialogid == DIALOG_TAKE) // Take items from trunk
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(response)
        {
            if(listitem == 0) // Slot 1
            {
                GivePlayerWeapon(playerid,iTrunk[vehicleid][tWeapon1],iTrunk[vehicleid][tAmmo1]);
            }
        }
        return 1;
    }
    // Rest

    return 0;
}
When I put weapon in trunk it remove it from my hands and I guess that is okay
But when I want to take it from trunk it remove my weapon also :/ can you help me guys with this?
Reply
#3

Sorry I fixed it right now, I forgot to change dialog ids at command...
Reply
#4

pawn Код:
if(dialogid == DIALOG_TAKE) // Take items from trunk
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(response)
        {
            if(listitem == 0) // Slot 1
            {
                GivePlayerWeapon(playerid,iTrunk[vehicleid][tWeapon1],iTrunk[vehicleid][tAmmo1]);
            }
        }
        return 1;
    }
Okay this is the code.. but player can now take same weapon out of trunk unlimited times how can I make so players can take this weapon out of trunk only once ?
Reply
#5

pawn Код:
iTrunk[vehicleid][tWeapon1] = 0;
iTrunk[vehicleid][tAmmo1] = 0;
Reply
#6

Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
pawn Код:
iTrunk[vehicleid][tWeapon1] = 0;
iTrunk[vehicleid][tAmmo1] = 0;
Thank you

Now I have 1 more question for this.

I want to make that dialogs will detect weapons name?

For now there is Slot 1 Slot 2 Slot 3...
But I want to make if there is weapon it will write: Slot 1 Deagle, Slot 2 Tec9
Depends which weapon is inside, how can I make this ?
Reply
#7

Put this arrary of all weapon names in your script:
pawn Код:
new aWeaponNames[][32] =
{
    {"Unarmed"}, {"BrassKnuckles"}, {"GolfClub"}, {"NightStick"}, {"Knife"}, {"BaseballBat"},
    {"Shovel"}, {"PoolCue"}, {"Katana"}, {"Chainsaw"}, {"PurpleDildo"}, {"BigWhiteVibrator"},
    {"MedWhiteVibrator"}, {"SmlWhiteVibrator"}, {"Flowers"}, {"Cane"}, {"Grenade"}, {"Teargas"},
    {"Molotov"}, {"Empty Slot 1"}, {"Empty Slot 2"}, {"Empty Slot 3"},  {"Colt45"}, {"SDPistol"},
    {"DesertEagle"}, {"Shotgun"}, {"SawnoffShotgun"}, {"Spas12"}, {"Mac10"},
    {"MP5"}, {"AK47"}, {"M4"}, {"Tec9"}, {"CountryRifle"}, {"Sniper"}, {"RPG"},
    {"HeatRPG"}, {"Flamethrower"}, {"Minigun"}, {"Satchel"}, {"Detonator"},
    {"SprayCan"}, {"Extinguisher"}, {"Camera"}, {"NVGoggles"}, {"IRGoggles"},
    {"Parachute"}, {"Fake Pistol"}
};
I'm guessing you're saving the weapon ID in this variable:
pawn Код:
iTrunk[vehicleid][tWeapon1]
Here is an example of how you can format the string:
pawn Код:
format(string, sizeof(string), "Slot 1: %s", aWeaponNames[ iTrunk[vehicleid][tWeapon1] ]);
Reply
#8

pawn Код:
if(dialogid == DIALOG_PUT) // Put items in trunk
    {
        new gunID = GetPlayerWeapon(playerid);
        if(gunID == 0) return 1;
        new gunAmmo = GetPlayerAmmo(playerid);
        new vehicleid = GetPlayerVehicleID(playerid);
        if(vehicleid == INVALID_VEHICLE_ID) return 1;
        if(response)
        {
            switch(listitem)   
            {
                case 0:
                {
                    iTrunk[vehicleid][tWeapon1] = gunID;
                    iTrunk[vehicleid][tAmmo1] = gunAmmo;
                }
                case 1:
                {
                    iTrunk[vehicleid][tWeapon2] = gunID;
                    iTrunk[vehicleid][tAmmo2] = gunAmmo;
                }
                case 2:
                {
                    iTrunk[vehicleid][tWeapon3] = gunID;
                    iTrunk[vehicleid][tAmmo3] = gunAmmo;
                }
                case 3:
                {
                    iTrunk[vehicleid][tWeapon4] = gunID;
                    iTrunk[vehicleid][tAmmo4] = gunAmmo;
                }
                case 4:
                {
                    iTrunk[vehicleid][tWeapon5] = gunID;
                    iTrunk[vehicleid][tAmmo5] = gunAmmo;
                }
                case 5:
                {
                    iTrunk[vehicleid][tWeapon6] = gunID;
                    iTrunk[vehicleid][tAmmo6] = gunAmmo;
                }
            }
            RemovePlayerWeapon(playerid, gunID);
        }
        return 1;
    }

    if(dialogid == DIALOG_TAKE) // Take items from trunk
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(vehicleid == INVALID_VEHICLE_ID) return 1;
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon1], iTrunk[vehicleid][tAmmo1]);
                    iTrunk[vehicleid][tWeapon1] = 0;
                    iTrunk[vehicleid][tAmmo1] = 0;
                }
                case 1:
                {
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon2], iTrunk[vehicleid][tAmmo2]);
                    iTrunk[vehicleid][tWeapon2] = 0;
                    iTrunk[vehicleid][tAmmo2] = 0;
                }
                case 2:
                {
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon3], iTrunk[vehicleid][tAmmo3]);
                    iTrunk[vehicleid][tWeapon3] = 0;
                    iTrunk[vehicleid][tAmmo3] = 0;
                }
                case 3:
                {
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon4], iTrunk[vehicleid][tAmmo4]);
                    iTrunk[vehicleid][tWeapon4] = 0;
                    iTrunk[vehicleid][tAmmo4] = 0;
                }
                case 4:
                {
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon5], iTrunk[vehicleid][tAmmo5]);
                    iTrunk[vehicleid][tWeapon5] = 0;
                    iTrunk[vehicleid][tAmmo5] = 0;
                }
                case 5:
                {
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon6], iTrunk[vehicleid][tAmmo6]);
                    iTrunk[vehicleid][tWeapon6] = 0;
                    iTrunk[vehicleid][tAmmo6] = 0;
                }
            }
        }
        return 1;
    }
   
    // Rest
   
    return 0;
}

//Under your command to put items in the trunk:
new tstr[255];
format(tstr, sizeof(tstr), "Slot 1 - %s\nSlot 2 - %s\nSlot 3 - %s\nSlot 4 - %s\nSlot 5 - %s\nSlot 6 - %s", GetGunName(iTrunk[vehicleid][tWeapon1]), GetGunName(iTrunk[vehicleid][tWeapon2]), GetGunName(iTrunk[vehicleid][tWeapon3]), GetGunName(iTrunk[vehicleid][tWeapon4]), GetGunName(iTrunk[vehicleid][tWeapon5]), GetGunName(iTrunk[vehicleid][tWeapon6]));
ShowPlayerDialog(playerid, DIALOG_TAKE, DIALOG_STYLE_LIST, "Take A Weapon", tstr, "Select", "Cancel");
//Continue...

stock GetGunName(weaponid)
{
    new gunname[32];
    GetWeaponName(weaponid, gunname, sizeof(gunname));
    if(weaponid == 0) gunname = "None";
    return gunname;
}
Reply
#9

You can't imagine how helpful you was, thank you rep+

If you don't mind I want to ask, now when I store weapon, I can take it from ANY other vehicle, how should I fix that ?
Reply
#10

Anyone please? this is storing weapons in EVERY vehicle so I can take if from any car I want.. here is the code you might need to help me with fixing that problem:

What I want to make is.. the weapon I store it will be stored in car I'm standing at (I'm not using this code INSIDE of vehicle I'm using code if I'm near trunk.. -outside of vehicle) so weapons will be stored only at that car and I won't be able to take them out from another car, help me to figure out with this please ^^

pawn Код:
enum Trunk
{
    tWeapon1,
    tWeapon2,
    tWeapon3,
    tWeapon4,
    tWeapon5,
    tAmmo1,
    tAmmo2,
    tAmmo3,
    tAmmo4,
    tAmmo5
};
new iTrunk[MAX_VEHICLES][Trunk];
If player will choose "put in trunk" option
pawn Код:
if(listitem == 1) // Put in trunk
            {
                for(new i; i<MAX_VEHICLES; i++)
                {
                    new vehicleid = GetPlayerVehicleID(playerid);
                    new Float: vx, Float:vy, Float:vz;
                    new e, l, a, d, b, bo, o;
                    GetVehicleParamsEx(i,e,l,a,d,b,bo,o);
                    GetVehiclePos(i,vx,vy,vz);
                    GetXYBehindCar(i, vx, vy, 2.5);
                    if(IsPlayerInRangeOfPoint(playerid,2.5,vx,vy,vz))
                    {
                        if(bo > 0)
                        {
                            new tstr[255];
                            format(tstr, sizeof(tstr), "Slot 1 - %s (%d)\nSlot 2 - %s (%d)\nSlot 3 - %s (%d)\nSlot 4 - %s (%d)\nSlot 5 - %s (%d)", GetGunName(iTrunk[vehicleid][tWeapon1]),iTrunk[vehicleid][tAmmo1], GetGunName(iTrunk[vehicleid][tWeapon2]),iTrunk[vehicleid][tAmmo2], GetGunName(iTrunk[vehicleid][tWeapon3]),iTrunk[vehicleid][tAmmo3], GetGunName(iTrunk[vehicleid][tWeapon4]),iTrunk[vehicleid][tAmmo4],GetGunName(iTrunk[vehicleid][tWeapon5]),iTrunk[vehicleid][tAmmo5]);
                            ShowPlayerDialog(playerid, DIALOG_PUT, DIALOG_STYLE_LIST, "Store a weapon", tstr, "Select", "Cancel");
                            return 1;
                        }
                        else
                        {
                            SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF} Open it first.");
                            return 1;
                        }
                    }
                }
            }
If player will choose take from trunk option
pawn Код:
if(listitem == 2) // Take from trunk
            {
                for(new i; i<MAX_VEHICLES; i++)
                {
                    new vehicleid = GetPlayerVehicleID(playerid);
                    new Float: vx, Float:vy, Float:vz;
                    new e, l, a, d, b, bo, o;
                    GetVehicleParamsEx(i,e,l,a,d,b,bo,o);
                    GetVehiclePos(i,vx,vy,vz);
                    GetXYBehindCar(i, vx, vy, 2.5);
                    if(IsPlayerInRangeOfPoint(playerid,2.5,vx,vy,vz))
                    {
                        if(bo > 0)
                        {
                            new tstr[255];
                            format(tstr, sizeof(tstr), "Slot 1 - %s (%d)\nSlot 2 - %s (%d)\nSlot 3 - %s (%d)\nSlot 4 - %s (%d)\nSlot 5 - %s (%d)", GetGunName(iTrunk[vehicleid][tWeapon1]),iTrunk[vehicleid][tAmmo1], GetGunName(iTrunk[vehicleid][tWeapon2]),iTrunk[vehicleid][tAmmo2], GetGunName(iTrunk[vehicleid][tWeapon3]),iTrunk[vehicleid][tAmmo3], GetGunName(iTrunk[vehicleid][tWeapon4]),iTrunk[vehicleid][tAmmo4],GetGunName(iTrunk[vehicleid][tWeapon5]),iTrunk[vehicleid][tAmmo5]);
                            ShowPlayerDialog(playerid, DIALOG_TAKE, DIALOG_STYLE_LIST, "Take A Weapon", tstr, "Select", "Cancel");
                            return 1;
                        }
                        else
                        {
                            SendClientMessage(playerid, COLOR_RED,"{00FF00}INFO: {FFFFFF} Open it before putting something in it1");
                            return 1;
                        }
                    }
                }
            }
        }
        return 1;
    }
PUT in trunk and TAKE from trunk dialogs and functions ...
pawn Код:
if(dialogid == DIALOG_PUT) // Put items in trunk
    {
        new gunID = GetPlayerWeapon(playerid);
        if(gunID == 0) return SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} You need to have weapon in your hands.");
        new gunAmmo = GetPlayerAmmo(playerid);
        new vehicleid = GetPlayerVehicleID(playerid);
        if(vehicleid == INVALID_VEHICLE_ID) return 1;
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    if(iTrunk[vehicleid][tWeapon1] != 0 && iTrunk[vehicleid][tAmmo1] != 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is already used!");
                        return 1;
                    }
                    iTrunk[vehicleid][tWeapon1] = gunID;
                    iTrunk[vehicleid][tAmmo1] = gunAmmo;
                }
                case 1:
                {
                    if(iTrunk[vehicleid][tWeapon2] != 0 && iTrunk[vehicleid][tAmmo2] != 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is already used!");
                        return 1;
                    }
                    iTrunk[vehicleid][tWeapon2] = gunID;
                    iTrunk[vehicleid][tAmmo2] = gunAmmo;
                }
                case 2:
                {
                    if(iTrunk[vehicleid][tWeapon3] != 0 && iTrunk[vehicleid][tAmmo3] != 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is already used!");
                        return 1;
                    }
                    iTrunk[vehicleid][tWeapon3] = gunID;
                    iTrunk[vehicleid][tAmmo3] = gunAmmo;
                }
                case 3:
                {
                    if(iTrunk[vehicleid][tWeapon4] !=0 && iTrunk[vehicleid][tAmmo4] != 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is already used!");
                        return 1;
                    }
                    iTrunk[vehicleid][tWeapon4] = gunID;
                    iTrunk[vehicleid][tAmmo4] = gunAmmo;
                }
                case 4:
                {
                    if(iTrunk[vehicleid][tWeapon5] != 0 && iTrunk[vehicleid][tAmmo5] != 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is already used!");
                        return 1;
                    }
                    iTrunk[vehicleid][tWeapon5] = gunID;
                    iTrunk[vehicleid][tAmmo5] = gunAmmo;
                }
            }
            RemovePlayerWeapon(playerid, gunID);
        }
        return 1;
    }

    if(dialogid == DIALOG_TAKE) // Take items from trunk
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(vehicleid == INVALID_VEHICLE_ID) return 1;
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    if(iTrunk[vehicleid][tWeapon1] == 0 && iTrunk[vehicleid][tAmmo1] == 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is empty!");
                        return 1;
                    }
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon1], iTrunk[vehicleid][tAmmo1]);
                    iTrunk[vehicleid][tWeapon1] = 0;
                    iTrunk[vehicleid][tAmmo1] = 0;
                }
                case 1:
                {
                    if(iTrunk[vehicleid][tWeapon2] == 0 && iTrunk[vehicleid][tAmmo2] == 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is empty!");
                        return 1;
                    }
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon2], iTrunk[vehicleid][tAmmo2]);
                    iTrunk[vehicleid][tWeapon2] = 0;
                    iTrunk[vehicleid][tAmmo2] = 0;
                }
                case 2:
                {
                    if(iTrunk[vehicleid][tWeapon3] == 0 && iTrunk[vehicleid][tAmmo3] == 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is empty!");
                        return 1;
                    }
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon3], iTrunk[vehicleid][tAmmo3]);
                    iTrunk[vehicleid][tWeapon3] = 0;
                    iTrunk[vehicleid][tAmmo3] = 0;
                }
                case 3:
                {
                    if(iTrunk[vehicleid][tWeapon4] == 0 && iTrunk[vehicleid][tAmmo4] == 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is empty!");
                        return 1;
                    }
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon4], iTrunk[vehicleid][tAmmo4]);
                    iTrunk[vehicleid][tWeapon4] = 0;
                    iTrunk[vehicleid][tAmmo4] = 0;
                }
                case 4:
                {
                    if(iTrunk[vehicleid][tWeapon5] == 0 && iTrunk[vehicleid][tAmmo5] == 0)
                    {
                        SendClientMessage(playerid, -1,"{00FF00}INFO: {FFFFFF} This slot is empty!");
                        return 1;
                    }
                    GivePlayerWeapon(playerid, iTrunk[vehicleid][tWeapon5], iTrunk[vehicleid][tAmmo5]);
                    iTrunk[vehicleid][tWeapon5] = 0;
                    iTrunk[vehicleid][tAmmo5] = 0;
                }
            }
        }
        return 1;
    }
Rep+ for helpers, Thanks for help in advance
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)