Y_INI Weapon Saving problem
#1

Hello, I've got some probs with my weapon saving.. actually the ammo is the real problem. It loads perfectly BUT the ammo duplicates. I think I have to do something like TempGun & TempAmmo but I'm not sure.. it would be appreciated if someone helped me out on this.

Quote:

SAVING FUNC.
Код:
public SaveAccountInfo(playerid)
{
    new cash = GetPlayerCash(playerid);
	new skin = GetPlayerSkin(playerid);
	new level = GetPlayerScore(playerid);
	new int = GetPlayerInterior(playerid);
	new vw = GetPlayerVirtualWorld(playerid);
	new Float:X, Float:Y, Float:Z;
	new Float:facingangle;
	new Float:health, Float:armour;
	GetPlayerHealth(playerid, health);
	GetPlayerArmour(playerid, armour);
	GetPlayerFacingAngle(playerid, facingangle);
	GetPlayerPos(playerid, X, Y, Z);
    for (new i = 0; i < 13; i++)
    {
    GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
    }
	new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"Player Data");
    INI_WriteInt(File,"Cash",cash);
    INI_WriteInt(File,"Skin",skin);
    INI_WriteInt(File,"Level",level);
    INI_WriteInt(File,"Int",int);
    INI_WriteInt(File,"VW",vw);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][pBanned]);
    INI_WriteFloat(File, "FacingAngle", facingangle);
    INI_WriteFloat(File, "Health", health);
    INI_WriteFloat(File, "Armour", armour);
    INI_WriteFloat(File, "LastX", X);
    INI_WriteFloat(File, "LastY", Y);
    INI_WriteFloat(File, "LastZ", Z);
    INI_WriteInt(File,"Weapon0", weapons[0][0]);
    INI_WriteInt(File,"Weapon1", weapons[1][0]);
    INI_WriteInt(File,"Weapon2", weapons[2][0]);
    INI_WriteInt(File,"Weapon3", weapons[3][0]);
    INI_WriteInt(File,"Weapon4", weapons[4][0]);
    INI_WriteInt(File,"Weapon5", weapons[5][0]);
    INI_WriteInt(File,"Weapon6", weapons[6][0]);
    INI_WriteInt(File,"Weapon7", weapons[7][0]);
    INI_WriteInt(File,"Weapon8", weapons[8][0]);
    INI_WriteInt(File,"Weapon9", weapons[9][0]);
    INI_WriteInt(File,"Weapon10", weapons[10][0]);
    INI_WriteInt(File,"Weapon11", weapons[11][0]);
    INI_WriteInt(File,"Weapon12", weapons[12][0]);
    
    INI_WriteInt(File,"Ammo0", weapons[0][1]);
    INI_WriteInt(File,"Ammo1", weapons[1][1]);
    INI_WriteInt(File,"Ammo2", weapons[2][1]);
    INI_WriteInt(File,"Ammo3", weapons[3][1]);
    INI_WriteInt(File,"Ammo4", weapons[4][1]);
    INI_WriteInt(File,"Ammo5", weapons[5][1]);
    INI_WriteInt(File,"Ammo6", weapons[6][1]);
    INI_WriteInt(File,"Ammo7", weapons[7][1]);
    INI_WriteInt(File,"Ammo8", weapons[8][1]);
    INI_WriteInt(File,"Ammo9", weapons[9][1]);
    INI_WriteInt(File,"Ammo10", weapons[10][1]);
    INI_WriteInt(File,"Ammo11", weapons[11][1]);
    INI_WriteInt(File,"Ammo12", weapons[12][1]);
    INI_Close(File);
	return 1;
}
LOADING FUNC.
Код:
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    INI_Int("Level",PlayerInfo[playerid][pLevel]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Banned",PlayerInfo[playerid][pBanned]);
   	INI_Float("FacingAngle",PlayerInfo[playerid][pFacingAngle]);
    INI_Float("Health",PlayerInfo[playerid][pHealth]);
    INI_Float("Armour",PlayerInfo[playerid][pArmour]);
    INI_Float("LastX", PlayerInfo[playerid][pLastX]);
    INI_Float("LastY", PlayerInfo[playerid][pLastY]);
    INI_Float("LastZ", PlayerInfo[playerid][pLastZ]);
    
    INI_Int("Weapon0", weapons[0][0]);
    INI_Int("Weapon1", weapons[1][0]);
    INI_Int("Weapon2", weapons[2][0]);
    INI_Int("Weapon3", weapons[3][0]);
    INI_Int("Weapon4", weapons[4][0]);
    INI_Int("Weapon5", weapons[5][0]);
    INI_Int("Weapon6", weapons[6][0]);
    INI_Int("Weapon7", weapons[7][0]);
    INI_Int("Weapon8", weapons[8][0]);
    INI_Int("Weapon9", weapons[9][0]);
    INI_Int("Weapon10", weapons[10][0]);
    INI_Int("Weapon11", weapons[11][0]);
    INI_Int("Weapon12", weapons[12][0]);

    INI_Int("Ammo0", weapons[0][1]);
    INI_Int("Ammo1", weapons[1][1]);
    INI_Int("Ammo2", weapons[2][1]);
    INI_Int("Ammo3", weapons[3][1]);
    INI_Int("Ammo4", weapons[4][1]);
    INI_Int("Ammo5", weapons[5][1]);
    INI_Int("Ammo6", weapons[6][1]);
    INI_Int("Ammo7", weapons[7][1]);
    INI_Int("Ammo8", weapons[8][1]);
    INI_Int("Ammo9", weapons[9][1]);
    INI_Int("Ammo10", weapons[10][1]);
    INI_Int("Ammo11", weapons[11][1]);
    INI_Int("Ammo12", weapons[12][1]);
    return 1;
}
Reply
#2

On Top:
PHP код:
enum weapon_system
{
    
pWeapon[MAX_WEAPONS],
    
pAmmo[MAX_WEAPONS]
};
new 
Weapon_Info[MAX_PLAYERS][weapon_system]; 
SaveAccount:

PHP код:
new wstring[32]
for(new 
0MAX_WEAPONSs++)
{
    
GetPlayerWeaponData(playeridsWeapon_Info[playerid][pWeapon][s], Weapon_Info[playerid][pAmmo][s]);
     for(new 
0MAX_WEAPONSw++)
     {
           
format(wstringsizeof(wstring), "Weapon%d"w);
               
INI_WriteInt(FilewstringWeapon_Info[playerid][pWeapon][w]);
     }
    for(new 
0MAX_WEAPONSa++)
    {
                
format(wstringsizeof(wstring), "Ammo%d"a);
                
INI_WriteInt(FilewstringWeapon_Info[playerid][pAmmo][a]);
    }

same thing in the load.
Reply
#3

Still the same.. and I don't think you read the whole thread, the ammo duplicated everytime I disconnect and reconnect.

EDIT: Fixed it!
Reply
#4

Looks weird. I suggest you to search your code (use CTRL+F) for duplications of LoadUser_data function.

Edit: Just curious, how did you fix it?
Reply
#5

pawn Код:
for(new s = 0; s < MAX_WEAPONS; s++)
    {
        new ammo = Weapon_Info[playerid][pAmmo][s];
        GivePlayerWeapon(playerid, Weapon_Info[playerid][pWeapon][s], Weapon_Info[playerid][pAmmo][s]);
        SetPlayerAmmo(playerid, GivePlayerWeapon(playerid, Weapon_Info[playerid][pWeapon][s], Weapon_Info[playerid][pAmmo][s]), Weapon_Info[playerid][pWeapon][s]-ammo);
        SetPlayerAmmo(playerid, Weapon_Info[playerid][pWeapon][s], Weapon_Info[playerid][pAmmo][s]);
    }
When a player spawns the ammo will automatically subtract itself.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)