SA-MP Forums Archive
Weapons Saving help - 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: Weapons Saving help (/showthread.php?tid=512893)



Weapons Saving help - JeaSon - 13.05.2014

well im bit confuse in this !

code is blow

pawn Код:
#define DIALOG_WEAPONS 91172
CMD:scs( playerid, params[])
{
    format(gsString, sizeof(gsString),"Chainsaw (1 Ammo) 5 cookies\n9mm Silenced (300 Ammo) 10 Cookies\nDesert Eagle (300 Ammo) 10 Cookies\nTec9 (300 Ammo) 10 Cookies\nShotgun (300 Ammo) 10 Cookies\nMicro SMG (300 Ammo) 10 Cookies\nSawnoff Shotgun (300 Ammo) 15 Cookies\nCombat Shotgun (300 Ammo) 15 Cookies\nAK47 (300 Ammo) 15 Cookies\nM4 (300 Ammo) 15 Cookies\nFlamethrower (50 Ammo) 15 Cookies\nCountry Rifle (50 Ammo) 15 Cookies\nSniper (50 Ammo) 20 Cookies");
    ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "YRS Spend Cookies Dialog...",gsString , "Select", "Cancel");
    return 1;
}
CMD:spendcookies( playerid, params[])
{
    return cmd_scs(playerid, params);
}

if(dialogid == DIALOG_WEAPONS)
    {
            if(response) // If they clicked 'Select' or double-clicked a weapon
            {
                // Give them the weapon
                switch(listitem)
                {
                    case 0:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 9, 1); // Give them a desert eagle
                            PlayerInfo[ playerid ][ Cookies ] -= 5;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                     }

                    case 1:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                           GivePlayerWeapon(playerid, 23, 300); // Give them an AK-47
                           PlayerInfo[ playerid ][ Cookies ] -= 10;
                           GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 2:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 24, 300); // Give them a Combat Shotgun
                            PlayerInfo[ playerid ][ Cookies ] -= 10;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 3:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 32, 300); // Give them a desert eagle
                            PlayerInfo[ playerid ][ Cookies ] -= 10;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }
                   
                    case 4:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 25, 300); // Give them an AK-47
                            PlayerInfo[ playerid ][ Cookies ] -= 10;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 5:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 28, 300); // Give them a Combat Shotgun
                            PlayerInfo[ playerid ][ Cookies ] -= 10;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 6:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 26   , 300); // Give them a desert eagle
                            PlayerInfo[ playerid ][ Cookies ] -= 15;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                     }

                    case 7:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 27, 300); // Give them an AK-47
                            PlayerInfo[ playerid ][ Cookies ] -= 15;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 8:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 30, 300); // Give them a Combat Shotgun
                            PlayerInfo[ playerid ][ Cookies ] -= 15;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 9:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 31, 300); // Give them a desert eagle
                            PlayerInfo[ playerid ][ Cookies ] -= 15;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 10:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 37, 50); // Give them an AK-47
                            PlayerInfo[ playerid ][ Cookies ] -= 15;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 11:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid,  33, 50); // Give them a Combat Shotgun
                            PlayerInfo[ playerid ][ Cookies ] -= 15;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }

                    case 12:
                    {
                        for (new i = 0; i < 13; i++)
                        {
                            GivePlayerWeapon(playerid, 34, 50); // Give them a Combat Shotgun
                            PlayerInfo[ playerid ][ Cookies ] -= 20;
                            GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
                        }
                    }
                }
            }

            return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
        }

i want when play buy a gun ! gun saves in PlayerInfo[ i] [wslot] and ammo in PlayerInfo[ i] [wslotammo]
can anyone tell me how can i do that


Re: Weapons Saving help - Madd92 - 13.05.2014

Quote:
Originally Posted by Namer
Посмотреть сообщение
pawn Код:
for (new i = 0; i < 13; i++)
{
    GivePlayerWeapon(playerid, 9, 1); // Give them a desert eagle
    PlayerInfo[ playerid ][ Cookies ] -= 5;
    GetPlayerWeaponData(playerid, 0, PlayerInfo[ i ][ wslot ], PlayerInfo[ i ][ wslotammo ]);
}
What is that? Where did you get that from? i should be the player id, so why player id 0-13?
Also where is wslot declared? You should either create an array at the top of your script where you assign each weapon id the associated weapon slot or (if you don't intent to use it anywhere else) use the correct wslot for every case in the switch construct.

Or, if you want to save all weapon slots regardless of what weapon you give the player, just save them all after the switch statement:

pawn Код:
for (new slot = 0; slot < 13; slot++)
        GetPlayerWeaponData(playerid, slot, PlayerInfo[playerid][wslot[slot]], PlayerInfo[playerid][wslotammo[slot]]);
You could also just define this array at the top of your code:
pawn Код:
static const
    WeaponIDSlot[] = {0, 0, 1, 1, 1, 1 , 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 8, 8, 8, -1, -1, -1,
        2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 4, 6, 6, 7, 7, 7, 7, 8, 12, 9, 9, 9, 11, 11, 11};
Now by just doing WeaponIDSlot[weaponid] you get the corresponding weapon slot to that weapon id.
But then you can't easily access the PlayerInfo[playerid][wslot] construct anymore, so you should declare that just like:
pawn Код:
new PlayerWeapons[MAX_PLAYERS][12];
new PlayerAmmo[MAX_PLAYERS][12];
for example. And then you could use that like this:
pawn Код:
case 0:
{
    GivePlayerWeapon(playerid, WEAPON_DEAGLE, 50); // Give them a desert eagle
    PlayerInfo[playerid][Cookies] -= 5;
    GetPlayerWeaponData(playerid, WeaponIDSlot[WEAPON_DEAGLE], PlayerWeapons[playerid][WeaponIDSlot[WEAPON_DEAGLE]], PlayerAmmo[playerid][WeaponIDSlot[WEAPON_DEAGLE]]);
}
Depends on how you prefer to do it.

I hope this helps you.