Weapon not saving
#1

Hello folks,
I made a quite advanced /inventory (for weapons) and made two commands:
/putgun - To put a gun inside the "bag" / inventory.
/takegun - To take a gun from the "bag" / inventory.

The weapons in the inventory save excellent. But the guns that the player didn't put in the bag don't save.
What is the problem here?

Here is my pInfo enum:
pawn Код:
enum pInfo
{
    pWeapons,
}
The saving:
pawn Код:
INI_WriteInt(File,"Weapons", PlayerInfo[playerid][pWeapons]);
The loading:
pawn Код:
INI_Int("Weapons", PlayerInfo[playerid][pWeapons]);
The publics:
pawn Код:
public SafeGivePlayerWeapon(playerid, weaponid, ammo)
{
    ScriptWeaponsUpdated[playerid] = 1;
    GivePlayerWeapon(playerid, weaponid, ammo);
    SetTimerEx("UpdateWeapons",2500,false,"i",playerid);
    return 1;
}

public UpdateWeapons(plyid)
{
    new weaponid, ammo;
    for(new i = 0; i < 13; i++)
    {
        GetPlayerWeaponData(plyid, i, weaponid, ammo);
        ScriptWeapons[plyid][i] = weaponid;
    }
    ScriptWeaponsUpdated[plyid] = 0;
    return 1;
}

public RemovePlayerWeapon(playerid, weaponid)
{
    new plyWeapons[12] = 0;
    new plyAmmo[12] = 0;
    for(new slot = 0; slot != 12; slot++)
    {
        new wep, ammo;
        GetPlayerWeaponData(playerid, slot, wep, ammo);

        if(wep != weaponid && ammo != 0)
        {
            GetPlayerWeaponData(playerid, slot, plyWeapons[slot], plyAmmo[slot]);
        }
    }

    SafeResetPlayerWeapons(playerid);
    for(new slot = 0; slot != 12; slot++)
    {
        if(plyAmmo[slot] != 0)
        {
            SafeGivePlayerWeapon(playerid, plyWeapons[slot], plyAmmo[slot]);
        }
    }
    return 1;
}

public SafeResetPlayerWeapons(playerid)
{
    ScriptWeaponsUpdated[playerid] = 1;
    ResetPlayerWeapons(playerid);
    SetTimerEx("UpdateWeapons",2500,false,"i",playerid);
    return 1;
}
Solutions?
Thanks!
Reply
#2

What do you mean don't save?
Reply
#3

If I give myself a gun as a level 5 admin.
/givegun [PLAYERID] [WEAPONID] [AMMO]

If I log off and back on, the weapon would be gone.

On the other hand, if I put it in my bag with /putgun 1-6 and if I would log off then and back on and do /takegun 1-6 (Depending in which slot I've put it) the gun would be there.

So the main problem here is:
Guns that player have in their hand or not in the /putgun won't be saved.
Reply
#4

When you give a player a weapon, you need to do this:


pawn Код:
PlayerInfo[playerid][GetWeaponSlot(weapon)] = weapon;
INI_WriteInt(File,"Weapons", PlayerInfo[playerid][GetWeaponSlot(weapon)]);
pawn Код:
GetWeaponSlot(weaponid)
{
    switch(weaponid)
    {
        case 0, 1:
        {
            return 0;
        }
        case 2, 3, 4, 5, 6, 7, 8, 9:
        {
            return 1;
        }
        case 22, 23, 24:
        {
            return 2;
        }
        case 25, 26, 27:
        {
            return 3;
        }
        case 28, 29, 32:
        {
            return 4;
        }
        case 30, 31:
        {
            return 5;
        }
        case 33, 34:
        {
            return 6;
        }
        case 35, 36, 37, 38:
        {
            return 7;
        }
        case 16, 17, 18, 39, 40:
        {
            return 8;
        }
        case 41, 42, 43:
        {
            return 9;
        }
        case 10, 11, 12, 13, 14, 15:
        {
            return 10;
        }
        case 44, 45, 46:
        {
            return 11;
        }
    }
    return -1;
}
Let me know if that works, Sorry for delayed reply.
Reply
#5

After looking at the code for a bit, I understood that the returns you used were the weaponslot in game.
The cases are the gunID's, if I'm right.

What I don't understand is why do you put a return -1 on the end?
I'm going to test that code.

Thanks in advance.

EDIT:
I get this error:

pawn Код:
(236) : error 017: undefined symbol "weapons"
(255) : error 017: undefined symbol "weapons"
This are the two lines:
pawn Код:
(236) PlayerInfo[playerid][GetWeaponSlot(weapons)] = weapons;
(255) INI_WriteInt(File,"Weapons", PlayerInfo[playerid][GetWeaponSlot(weapons)]);
Reply
#6

he said "When you give a player a weapon".. Replace "weapons" with the weapon id that shall be given to you.

I don't think this is accurate though, A better way is to save all the player's held weapons when he disconnects, And load them all when he connects/logs in, let me know if you're going to use that and I'll give you a script for that.
Reply
#7

pawn Код:
he said "When you give a player a weapon".. Replace "weapons" with the weapon id that shall be given to you.
Yeah that's for an individual weapon! It is better to do it when they disconnect.
Reply
#8

A misunderstanding by me. I apologize.

And yeah, I'm going for that method.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)