Using an array to save and load weapon data
#1

Hi guys. How could I change all of that into an array?

pawn Код:
enum PlayerData
{
    pWeapon1, pAmmo1,
    pWeapon2, pAmmo2,
    pWeapon3, pAmmo3,
    pWeapon4, pAmmo4,
    pWeapon5, pAmmo5,
    pWeapon6, pAmmo6,
    pWeapon7, pAmmo7,
    pWeapon8, pAmmo8,
    pWeapon9, pAmmo9,
    pWeapon10, pAmmo10,
    pWeapon11, pAmmo11,
    pWeapon12, pAmmo12,

}
What about the saving and loading?

pawn Код:
stock SavePlayerWeapons(playerid)
{
    if(PlayerStatistics[playerid][pAuth] == 1)
    {
        GetPlayerWeaponData(playerid, 1, PlayerStatistics[playerid][pWeapon1], PlayerStatistics[playerid][pAmmo1]);
        GetPlayerWeaponData(playerid, 2, PlayerStatistics[playerid][pWeapon2], PlayerStatistics[playerid][pAmmo2]);
        GetPlayerWeaponData(playerid, 3, PlayerStatistics[playerid][pWeapon3], PlayerStatistics[playerid][pAmmo3]);
        GetPlayerWeaponData(playerid, 4, PlayerStatistics[playerid][pWeapon4], PlayerStatistics[playerid][pAmmo4]);
        GetPlayerWeaponData(playerid, 5, PlayerStatistics[playerid][pWeapon5], PlayerStatistics[playerid][pAmmo5]);
        GetPlayerWeaponData(playerid, 6, PlayerStatistics[playerid][pWeapon6], PlayerStatistics[playerid][pAmmo6]);
        GetPlayerWeaponData(playerid, 7, PlayerStatistics[playerid][pWeapon7], PlayerStatistics[playerid][pAmmo7]);
        GetPlayerWeaponData(playerid, 8, PlayerStatistics[playerid][pWeapon8], PlayerStatistics[playerid][pAmmo8]);
        GetPlayerWeaponData(playerid, 9, PlayerStatistics[playerid][pWeapon9], PlayerStatistics[playerid][pAmmo9]);
        GetPlayerWeaponData(playerid, 10, PlayerStatistics[playerid][pWeapon10], PlayerStatistics[playerid][pAmmo10]);
        GetPlayerWeaponData(playerid, 11, PlayerStatistics[playerid][pWeapon11], PlayerStatistics[playerid][pAmmo11]);
        GetPlayerWeaponData(playerid, 12, PlayerStatistics[playerid][pWeapon12], PlayerStatistics[playerid][pAmmo12]);

        format(Query, sizeof(Query), "UPDATE `Accounts` SET `Weapon1` = '%d', `Weapon2` = '%d', `Weapon3` = '%d', `Weapon4` = '%d', `Weapon5` = '%d', `Weapon6` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pWeapon1], PlayerStatistics[playerid][pWeapon2], PlayerStatistics[playerid][pWeapon3], PlayerStatistics[playerid][pWeapon4], PlayerStatistics[playerid][pWeapon5], PlayerStatistics[playerid][pWeapon6], PlayerStatistics[playerid][pDatabaseID]);
        mysql_query(Query);
        format(Query, sizeof(Query), "UPDATE `Accounts` SET `Weapon7` = '%d', `Weapon8` = '%d', `Weapon9` = '%d', `Weapon10` = '%d', `Weapon11` = '%d', `Weapon12` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pWeapon7], PlayerStatistics[playerid][pWeapon8], PlayerStatistics[playerid][pWeapon9], PlayerStatistics[playerid][pWeapon10], PlayerStatistics[playerid][pWeapon11], PlayerStatistics[playerid][pWeapon12], PlayerStatistics[playerid][pDatabaseID]);
        mysql_query(Query);
       
        format(Query, sizeof(Query), "UPDATE `Accounts` SET `Ammo1` = '%d', `Ammo2` = '%d', `Ammo3` = '%d', `Ammo4` = '%d', `Ammo5` = '%d', `Ammo6` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pAmmo1], PlayerStatistics[playerid][pAmmo2], PlayerStatistics[playerid][pAmmo3], PlayerStatistics[playerid][pAmmo4], PlayerStatistics[playerid][pAmmo5], PlayerStatistics[playerid][pAmmo6], PlayerStatistics[playerid][pDatabaseID]);
        mysql_query(Query);
        format(Query, sizeof(Query), "UPDATE `Accounts` SET `Ammo7` = '%d', `Ammo8` = '%d', `Ammo9` = '%d', `Ammo10` = '%d', `Ammo11` = '%d', `Ammo12` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pAmmo7], PlayerStatistics[playerid][pAmmo8], PlayerStatistics[playerid][pAmmo9], PlayerStatistics[playerid][pAmmo10], PlayerStatistics[playerid][pAmmo11], PlayerStatistics[playerid][pAmmo12], PlayerStatistics[playerid][pDatabaseID]);
        mysql_query(Query);
    }
    return 1;
}

stock GivePlayerSavedWeapons(playerid)
{
    if(PlayerStatistics[playerid][pAuth] == 1)
    {
        SetPlayerArmedWeapon(playerid, 0);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon1], PlayerStatistics[playerid][pAmmo1]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon2], PlayerStatistics[playerid][pAmmo2]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon3], PlayerStatistics[playerid][pAmmo3]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon4], PlayerStatistics[playerid][pAmmo4]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon5], PlayerStatistics[playerid][pAmmo5]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon6], PlayerStatistics[playerid][pAmmo6]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon7], PlayerStatistics[playerid][pAmmo7]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon8], PlayerStatistics[playerid][pAmmo8]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon9], PlayerStatistics[playerid][pAmmo9]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon10], PlayerStatistics[playerid][pAmmo10]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon11], PlayerStatistics[playerid][pAmmo11]);
        GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapon12], PlayerStatistics[playerid][pAmmo12]);
    }
    return 1;
}
Reply
#2

It's already in an array, they're just named

But you can use two different arrays like this:
pawn Код:
#define MAX_WEAPON_SLOTS 12
new PlayerWeapons[MAX_PLAYERS][MAX_WEAPON_SLOTS];
new PlayerAmmo[MAX_PLAYERS][MAX_WEAPON_SLOTS];
Reply
#3

Or...

new PlayerWeapons[MAX_PLAYERS][MAX_WEP_SLOTS][2];

And I have #define MAX_WEP_SLOTS 13 not 12 .
Reply
#4

That crashes the compiler afaik
Reply
#5

pawn Код:
new Admin_SpecWeaponSave[MAX_PLAYERS][MAX_WEP_SLOTS][2];
Been using it forever, compiles just fine.
Reply
#6

pawn Код:
enum PlayerStatistics // PlayerStatistics && PlayerData == ?????-
{
        pWeapons[13], // It's an enumerator, I don't know why you guys are using MAX_PLAYERS inside it.
    pWeaponAmmo[13], // Pawn doesn't support four-dimensional arrays (as it stands, the player variables would be three - PlayerStatistics[PLAYER SLOT][VARIABLE][ARRAY SLOT]).
}

// blah blah blah

stock SavePlayerWeapons(playerid)
{
    if(PlayerStatistics[playerid][pAuth] == 1)
    {
            for(new x; x < 13; x++)
            {
                GetPlayerWeaponData(playerid, x, PlayerStatistics[playerid][pWeapons][x], PlayerStatistics[playerid][pWeaponAmmo][x]);
            }
    }
}

stock GivePlayerSavedWeapons(playerid)
{
    if(PlayerStatistics[playerid][pAuth] == 1)
    {
            for(new x; x < 13; x++)
            {
                GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapons][x], PlayerStatistics[playerid][pWeaponAmmo][x]);
            }
    }
}
hollr.
Reply
#7

Quote:
Originally Posted by Brian.
Посмотреть сообщение
pawn Код:
enum PlayerStatistics // PlayerStatistics && PlayerData == ?????-
{
        pWeapons[13], // It's an enumerator, I don't know why you guys are using MAX_PLAYERS inside it.
    pWeaponAmmo[13], // Pawn doesn't support four-dimensional arrays (as it stands, the player variables would be three - PlayerStatistics[PLAYER SLOT][VARIABLE][ARRAY SLOT]).
}

// blah blah blah

stock SavePlayerWeapons(playerid)
{
    if(PlayerStatistics[playerid][pAuth] == 1)
    {
            for(new x; x < 13; x++)
            {
                GetPlayerWeaponData(playerid, x, PlayerStatistics[playerid][pWeapons][x], PlayerStatistics[playerid][pWeaponAmmo][x]);
            }
    }
}

stock GivePlayerSavedWeapons(playerid)
{
    if(PlayerStatistics[playerid][pAuth] == 1)
    {
            for(new x; x < 13; x++)
            {
                GivePlayerWeapon(playerid, PlayerStatistics[playerid][pWeapons][x], PlayerStatistics[playerid][pWeaponAmmo][x]);
            }
    }
}
hollr.
Ah. I was forgetting the "for(new x; x < 13; x++)" thanks!

* Credits will be included in the script
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)