Weapon Saving help!
#1

I'm using Y_INI to get the players Weapon Data on disconnect and save it in an ini file, weaponID's as PlayerInfo[playerid][pWeapon], PlayerInfo[playerid][pWeapon1] and so on, same goes for ammo but pAmmo.


The weapon saves work fine I've checked in the .ini files, my character e.g gets Weapon5 = 30, Ammo5 = 50

Ak47 - 50 ammo.

But as soon as I relog, the Weapon5 gets set to 0 and Ammo5 gets set to 0.

I have no idea why :/

The script to give him weapons, if he has one(this goes on login)

pawn Код:
if(PlayerInfo[playerid][pWeapon] >= 1) if(PlayerInfo[playerid][pAmmo] >= 0)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon], PlayerInfo[playerid][pAmmo]);
                    }
                    if(PlayerInfo[playerid][pWeapon1] >= 1) if(PlayerInfo[playerid][pAmmo] >= 1)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon1], PlayerInfo[playerid][pAmmo1]);
                    }
                    if(PlayerInfo[playerid][pWeapon2] >= 1) if(PlayerInfo[playerid][pAmmo] >= 2)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon2], PlayerInfo[playerid][pAmmo2]);
                    }

                    if(PlayerInfo[playerid][pWeapon3] >= 1) if(PlayerInfo[playerid][pAmmo] >= 3)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon3], PlayerInfo[playerid][pAmmo3]);
                    }

                    if(PlayerInfo[playerid][pWeapon4] >= 1) if(PlayerInfo[playerid][pAmmo] >= 4)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon4], PlayerInfo[playerid][pAmmo4]);
                    }

                    if(PlayerInfo[playerid][pWeapon5] >= 1) if(PlayerInfo[playerid][pAmmo] >= 5)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon5], PlayerInfo[playerid][pAmmo5]);
                    }

                    if(PlayerInfo[playerid][pWeapon6] >= 1) if(PlayerInfo[playerid][pAmmo] >= 6)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon6], PlayerInfo[playerid][pAmmo6]);
                    }

                    if(PlayerInfo[playerid][pWeapon7] >= 1) if(PlayerInfo[playerid][pAmmo] >= 7)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon7], PlayerInfo[playerid][pAmmo7]);
                    }

                    if(PlayerInfo[playerid][pWeapon8] >= 1) if(PlayerInfo[playerid][pAmmo] >= 8)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon8], PlayerInfo[playerid][pAmmo8]);
                    }

                    if(PlayerInfo[playerid][pWeapon9] >= 1) if(PlayerInfo[playerid][pAmmo] >= 9)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon9], PlayerInfo[playerid][pAmmo9]);
                    }

                    if(PlayerInfo[playerid][pWeapon10] >= 1) if(PlayerInfo[playerid][pAmmo] >= 10)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon10], PlayerInfo[playerid][pAmmo10]);
                    }

                    if(PlayerInfo[playerid][pWeapon11] >= 1) if(PlayerInfo[playerid][pAmmo] >= 11)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon11], PlayerInfo[playerid][pAmmo11]);
                    }

                    if(PlayerInfo[playerid][pWeapon12] >= 1) if(PlayerInfo[playerid][pAmmo] >= 12)
                    {
                        GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon12], PlayerInfo[playerid][pAmmo12]);
                    }


Weapon saving script

pawn Код:
forward weaponscheck(playerid);
public weaponscheck(playerid)
{
    GetPlayerWeaponData(playerid, 0, PlayerInfo[playerid][pWeapon], PlayerInfo[playerid][pAmmo]);
    GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][pWeapon1], PlayerInfo[playerid][pAmmo1]);
    GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][pWeapon2], PlayerInfo[playerid][pAmmo2]);
    GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][pWeapon3], PlayerInfo[playerid][pAmmo3]);
    GetPlayerWeaponData(playerid, 4, PlayerInfo[playerid][pWeapon4], PlayerInfo[playerid][pAmmo4]);
    GetPlayerWeaponData(playerid, 5, PlayerInfo[playerid][pWeapon5], PlayerInfo[playerid][pAmmo5]);
    GetPlayerWeaponData(playerid, 6, PlayerInfo[playerid][pWeapon6], PlayerInfo[playerid][pAmmo6]);
    GetPlayerWeaponData(playerid, 7, PlayerInfo[playerid][pWeapon7], PlayerInfo[playerid][pAmmo7]);
    GetPlayerWeaponData(playerid, 8, PlayerInfo[playerid][pWeapon8], PlayerInfo[playerid][pAmmo8]);
    GetPlayerWeaponData(playerid, 9, PlayerInfo[playerid][pWeapon9], PlayerInfo[playerid][pAmmo9]);
    GetPlayerWeaponData(playerid, 10, PlayerInfo[playerid][pWeapon10], PlayerInfo[playerid][pAmmo10]);
    GetPlayerWeaponData(playerid, 11, PlayerInfo[playerid][pWeapon11], PlayerInfo[playerid][pAmmo11]);
    GetPlayerWeaponData(playerid, 12, PlayerInfo[playerid][pWeapon12], PlayerInfo[playerid][pAmmo12]);
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"weapons");
    INI_WriteInt(File,"Weapon",PlayerInfo[playerid][pWeapon]);
    INI_WriteInt(File,"Ammo",PlayerInfo[playerid][pAmmo]);
    INI_WriteInt(File,"Weapon1",PlayerInfo[playerid][pWeapon1]);
    INI_WriteInt(File,"Ammo1",PlayerInfo[playerid][pAmmo1]);
    INI_WriteInt(File,"Weapon2",PlayerInfo[playerid][pWeapon2]);
    INI_WriteInt(File,"Ammo2",PlayerInfo[playerid][pAmmo2]);
    INI_WriteInt(File,"Weapon3",PlayerInfo[playerid][pWeapon3]);
    INI_WriteInt(File,"Ammo3",PlayerInfo[playerid][pAmmo3]);
    INI_WriteInt(File,"Weapon4",PlayerInfo[playerid][pWeapon4]);
    INI_WriteInt(File,"Ammo4",PlayerInfo[playerid][pAmmo4]);
    INI_WriteInt(File,"Weapon5",PlayerInfo[playerid][pWeapon5]);
    INI_WriteInt(File,"Ammo5",PlayerInfo[playerid][pAmmo5]);
    INI_WriteInt(File,"Weapon6",PlayerInfo[playerid][pWeapon6]);
    INI_WriteInt(File,"Ammo6",PlayerInfo[playerid][pAmmo6]);
    INI_WriteInt(File,"Weapon7",PlayerInfo[playerid][pWeapon7]);
    INI_WriteInt(File,"Ammo7",PlayerInfo[playerid][pAmmo7]);
    INI_WriteInt(File,"Weapon8",PlayerInfo[playerid][pWeapon8]);
    INI_WriteInt(File,"Ammo8",PlayerInfo[playerid][pAmmo8]);
    INI_WriteInt(File,"Weapon9",PlayerInfo[playerid][pWeapon9]);
    INI_WriteInt(File,"Ammo9",PlayerInfo[playerid][pAmmo9]);
    INI_WriteInt(File,"Weapon10",PlayerInfo[playerid][pWeapon10]);
    INI_WriteInt(File,"Ammo10",PlayerInfo[playerid][pAmmo10]);
    INI_WriteInt(File,"Weapon11",PlayerInfo[playerid][pWeapon11]);
    INI_WriteInt(File,"Ammo11",PlayerInfo[playerid][pAmmo11]);
    INI_WriteInt(File,"Weapon12",PlayerInfo[playerid][pWeapon12]);
    INI_WriteInt(File,"Ammo12",PlayerInfo[playerid][pAmmo12]);
    INI_Close(File);

A timer that gets set when he spawns to see what weapons he has, and which should be saved.

pawn Код:
SetTimerEx("weaponscheck", 1000, true, "i", playerid);
Reply


Messages In This Thread
Weapon Saving help! - by TheTerminator - 20.01.2015, 07:32
Re: Weapon Saving help! - by TheTerminator - 20.01.2015, 09:11

Forum Jump:


Users browsing this thread: 1 Guest(s)