saving weapon problem
#1

hey i try to save weapon it was successful but i notice a problem were i /q and it saves then i join again
and it load up the weapons but it give me twice the ammo i had here the fs simple [fs]

PHP код:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT
#include <a_samp>
#include <dini>
#include <dudb>
#include <sscanf2>
#pragma unused ret_memcpy
#pragma unused strtok
new file[256];
enum WepData
{
    
Weapon1,
    
Weapon1a,
    
Weapon2,
    
Weapon2a,
    
Weapon3,
    
Weapon3a,
    
Weapon4,
    
Weapon4a,
    
Weapon5,
    
Weapon5a,
    
Weapon6,
    
Weapon6a,
    
Weapon7,
    
Weapon7a,
    
Weapon8,
    
Weapon8a,
    
Weapon9,
    
Weapon9a,
    
Weapon10,
    
Weapon10a,
    
Weapon11,
    
Weapon11a,
    
Weapon12,
    
Weapon12a,
}
new 
WeaponInfo[MAX_PLAYERS][WepData];
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
" Weapon Saving + Loading by Milan_Huizen");
    print(
"--------------------------------------\n");
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
#else
main()
{
    print(
"\n----------------------------------");
    print(
" Blank Gamemode by your name here");
    print(
"----------------------------------\n");
}
#endif
public OnPlayerConnect(playerid)
{
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
format(filesizeof(file), "weapons/%s.ini"name);
    if (!
dini_Exists(file))
    {
        
dini_Create(file);
         
dini_IntSet(file"Weapon1",WeaponInfo[playerid][Weapon1] = 0);
         
dini_IntSet(file"Weapon1a",WeaponInfo[playerid][Weapon1a] = 0);
         
dini_IntSet(file"Weapon2",WeaponInfo[playerid][Weapon2] = 0);
          
dini_IntSet(file"Weapon2a",WeaponInfo[playerid][Weapon2a] = 0);
         
dini_IntSet(file"Weapon3",WeaponInfo[playerid][Weapon3] = 0);
         
dini_IntSet(file"Weapon3a",WeaponInfo[playerid][Weapon3a] = 0);
        
dini_IntSet(file"Weapon4",WeaponInfo[playerid][Weapon4] = 0);
        
dini_IntSet(file"Weapon4a",WeaponInfo[playerid][Weapon4a] = 0);
         
dini_IntSet(file"Weapon5",WeaponInfo[playerid][Weapon5] = 0);
         
dini_IntSet(file"Weapon5a",WeaponInfo[playerid][Weapon5a] = 0);
          
dini_IntSet(file"Weapon6",WeaponInfo[playerid][Weapon6] = 0);
          
dini_IntSet(file"Weapon6a",WeaponInfo[playerid][Weapon6a] = 0);
          
dini_IntSet(file"Weapon7",WeaponInfo[playerid][Weapon7] = 0);
          
dini_IntSet(file"Weapon7a",WeaponInfo[playerid][Weapon7a] = 0);
          
dini_IntSet(file"Weapon8",WeaponInfo[playerid][Weapon8] = 0);
          
dini_IntSet(file"Weapon8a",WeaponInfo[playerid][Weapon8a] = 0);
          
dini_IntSet(file"Weapon9",WeaponInfo[playerid][Weapon9] = 0);
          
dini_IntSet(file"Weapon9a",WeaponInfo[playerid][Weapon9a] = 0);
          
dini_IntSet(file"Weapon10",WeaponInfo[playerid][Weapon10] = 0);
          
dini_IntSet(file"Weapon10a",WeaponInfo[playerid][Weapon10a] = 0);
          
dini_IntSet(file"Weapon11",WeaponInfo[playerid][Weapon11] = 0);
          
dini_IntSet(file"Weapon11a",WeaponInfo[playerid][Weapon11a] = 0);
         
dini_IntSet(file"Weapon12",WeaponInfo[playerid][Weapon12] = 0);
          
dini_IntSet(file"Weapon12a",WeaponInfo[playerid][Weapon12a] = 0);
    }
    else
    {
         
WeaponInfo[playerid][Weapon1] = dini_Int(file"Weapon1");
         
WeaponInfo[playerid][Weapon1a] = dini_Int(file"Weapon1a");
         
WeaponInfo[playerid][Weapon2] = dini_Int(file"Weapon2");
         
WeaponInfo[playerid][Weapon2a] = dini_Int(file"Weapon2a");
        
WeaponInfo[playerid][Weapon3] = dini_Int(file"Weapon3");
         
WeaponInfo[playerid][Weapon3a] = dini_Int(file"Weapon3a");
         
WeaponInfo[playerid][Weapon4] = dini_Int(file"Weapon4");
         
WeaponInfo[playerid][Weapon4a] = dini_Int(file"Weapon4a");
         
WeaponInfo[playerid][Weapon5] = dini_Int(file"Weapon5");
         
WeaponInfo[playerid][Weapon5a] = dini_Int(file"Weapon5a");
         
WeaponInfo[playerid][Weapon6] = dini_Int(file"Weapon6");
         
WeaponInfo[playerid][Weapon6a] = dini_Int(file"Weapon6a");
         
WeaponInfo[playerid][Weapon7] = dini_Int(file"Weapon7");
         
WeaponInfo[playerid][Weapon7a] = dini_Int(file"Weapon7a");
         
WeaponInfo[playerid][Weapon8] = dini_Int(file"Weapon8");
         
WeaponInfo[playerid][Weapon8a] = dini_Int(file"Weapon8a");
         
WeaponInfo[playerid][Weapon9] = dini_Int(file"Weapon9");
         
WeaponInfo[playerid][Weapon9a] = dini_Int(file"Weapon9a");
         
WeaponInfo[playerid][Weapon10] = dini_Int(file"Weapon10");
         
WeaponInfo[playerid][Weapon10a] = dini_Int(file"Weapon10a");
         
WeaponInfo[playerid][Weapon11] = dini_Int(file"Weapon11");
         
WeaponInfo[playerid][Weapon11a] = dini_Int(file"Weapon11a");
         
WeaponInfo[playerid][Weapon12] = dini_Int(file"Weapon12");
         
WeaponInfo[playerid][Weapon12a] = dini_Int(file"Weapon12a");
    }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridnamesizeof(name));
        
format(filesizeof(file), "weapons/%s.ini"name);
           
GetPlayerWeaponData(playerid1WeaponInfo[playerid][Weapon1], WeaponInfo[playerid][Weapon1a]);
           
GetPlayerWeaponData(playerid2WeaponInfo[playerid][Weapon2], WeaponInfo[playerid][Weapon2a]);
           
GetPlayerWeaponData(playerid3WeaponInfo[playerid][Weapon3], WeaponInfo[playerid][Weapon3a]);
           
GetPlayerWeaponData(playerid4WeaponInfo[playerid][Weapon4], WeaponInfo[playerid][Weapon4a]);
           
GetPlayerWeaponData(playerid5WeaponInfo[playerid][Weapon5], WeaponInfo[playerid][Weapon5a]);
           
GetPlayerWeaponData(playerid6WeaponInfo[playerid][Weapon6], WeaponInfo[playerid][Weapon6a]);
           
GetPlayerWeaponData(playerid7WeaponInfo[playerid][Weapon7], WeaponInfo[playerid][Weapon7a]);
           
GetPlayerWeaponData(playerid8WeaponInfo[playerid][Weapon8], WeaponInfo[playerid][Weapon8a]);
           
GetPlayerWeaponData(playerid9WeaponInfo[playerid][Weapon9], WeaponInfo[playerid][Weapon9a]);
           
GetPlayerWeaponData(playerid10WeaponInfo[playerid][Weapon10], WeaponInfo[playerid][Weapon10a]);
           
GetPlayerWeaponData(playerid11WeaponInfo[playerid][Weapon11], WeaponInfo[playerid][Weapon11a]);
           
GetPlayerWeaponData(playerid12WeaponInfo[playerid][Weapon12], WeaponInfo[playerid][Weapon12a]);
         
dini_IntSet(file"Weapon1",WeaponInfo[playerid][Weapon1]);
         
dini_IntSet(file"Weapon1a",WeaponInfo[playerid][Weapon1a]);
         
dini_IntSet(file"Weapon2",WeaponInfo[playerid][Weapon2]);
          
dini_IntSet(file"Weapon2a",WeaponInfo[playerid][Weapon2a]);
         
dini_IntSet(file"Weapon3",WeaponInfo[playerid][Weapon3]);
          
dini_IntSet(file"Weapon3a",WeaponInfo[playerid][Weapon3a]);
          
dini_IntSet(file"Weapon4",WeaponInfo[playerid][Weapon4]);
          
dini_IntSet(file"Weapon4a",WeaponInfo[playerid][Weapon4a]);
          
dini_IntSet(file"Weapon5",WeaponInfo[playerid][Weapon5]);
          
dini_IntSet(file"Weapon5a",WeaponInfo[playerid][Weapon5a]);
          
dini_IntSet(file"Weapon6",WeaponInfo[playerid][Weapon6]);
             
dini_IntSet(file"Weapon6a",WeaponInfo[playerid][Weapon6a]);
          
dini_IntSet(file"Weapon7",WeaponInfo[playerid][Weapon7]);
          
dini_IntSet(file"Weapon7a",WeaponInfo[playerid][Weapon7a]);
          
dini_IntSet(file"Weapon8",WeaponInfo[playerid][Weapon8]);
          
dini_IntSet(file"Weapon8a",WeaponInfo[playerid][Weapon8a]);
          
dini_IntSet(file"Weapon9",WeaponInfo[playerid][Weapon9]);
          
dini_IntSet(file"Weapon9a",WeaponInfo[playerid][Weapon9a]);
          
dini_IntSet(file"Weapon10",WeaponInfo[playerid][Weapon10]);
          
dini_IntSet(file"Weapon10a",WeaponInfo[playerid][Weapon10a]);
          
dini_IntSet(file"Weapon11",WeaponInfo[playerid][Weapon11]);
          
dini_IntSet(file"Weapon11a",WeaponInfo[playerid][Weapon11a]);
          
dini_IntSet(file"Weapon12",WeaponInfo[playerid][Weapon12]);
          
dini_IntSet(file"Weapon12a",WeaponInfo[playerid][Weapon12a]);
        return 
1;
}
public 
OnPlayerSpawn(playerid)
{
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon1], WeaponInfo[playerid][Weapon1a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon2], WeaponInfo[playerid][Weapon2a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon3], WeaponInfo[playerid][Weapon3a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon4], WeaponInfo[playerid][Weapon4a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon5], WeaponInfo[playerid][Weapon5a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon6], WeaponInfo[playerid][Weapon6a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon7], WeaponInfo[playerid][Weapon7a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon8], WeaponInfo[playerid][Weapon8a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon9], WeaponInfo[playerid][Weapon9a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon10], WeaponInfo[playerid][Weapon10a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon11], WeaponInfo[playerid][Weapon11a]);
    
GivePlayerWeapon(playeridWeaponInfo[playerid][Weapon12], WeaponInfo[playerid][Weapon12a]);
    
SetTimerEx("save"1true"i"playerid);
    return 
1;
}
forward save(playerid);
public 
save(playerid)
{
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridnamesizeof(name));
        
format(filesizeof(file), "weapons/%s.ini"name);
           
GetPlayerWeaponData(playerid1WeaponInfo[playerid][Weapon1], WeaponInfo[playerid][Weapon1a]);
           
GetPlayerWeaponData(playerid2WeaponInfo[playerid][Weapon2], WeaponInfo[playerid][Weapon2a]);
           
GetPlayerWeaponData(playerid3WeaponInfo[playerid][Weapon3], WeaponInfo[playerid][Weapon3a]);
           
GetPlayerWeaponData(playerid4WeaponInfo[playerid][Weapon4], WeaponInfo[playerid][Weapon4a]);
           
GetPlayerWeaponData(playerid5WeaponInfo[playerid][Weapon5], WeaponInfo[playerid][Weapon5a]);
           
GetPlayerWeaponData(playerid6WeaponInfo[playerid][Weapon6], WeaponInfo[playerid][Weapon6a]);
           
GetPlayerWeaponData(playerid7WeaponInfo[playerid][Weapon7], WeaponInfo[playerid][Weapon7a]);
           
GetPlayerWeaponData(playerid8WeaponInfo[playerid][Weapon8], WeaponInfo[playerid][Weapon8a]);
           
GetPlayerWeaponData(playerid9WeaponInfo[playerid][Weapon9], WeaponInfo[playerid][Weapon9a]);
           
GetPlayerWeaponData(playerid10WeaponInfo[playerid][Weapon10], WeaponInfo[playerid][Weapon10a]);
           
GetPlayerWeaponData(playerid11WeaponInfo[playerid][Weapon11], WeaponInfo[playerid][Weapon11a]);
           
GetPlayerWeaponData(playerid12WeaponInfo[playerid][Weapon12], WeaponInfo[playerid][Weapon12a]);
         
dini_IntSet(file"Weapon1",WeaponInfo[playerid][Weapon1]);
         
dini_IntSet(file"Weapon1a",WeaponInfo[playerid][Weapon1a]);
         
dini_IntSet(file"Weapon2",WeaponInfo[playerid][Weapon2]);
          
dini_IntSet(file"Weapon2a",WeaponInfo[playerid][Weapon2a]);
         
dini_IntSet(file"Weapon3",WeaponInfo[playerid][Weapon3]);
          
dini_IntSet(file"Weapon3a",WeaponInfo[playerid][Weapon3a]);
          
dini_IntSet(file"Weapon4",WeaponInfo[playerid][Weapon4]);
          
dini_IntSet(file"Weapon4a",WeaponInfo[playerid][Weapon4a]);
          
dini_IntSet(file"Weapon5",WeaponInfo[playerid][Weapon5]);
          
dini_IntSet(file"Weapon5a",WeaponInfo[playerid][Weapon5a]);
          
dini_IntSet(file"Weapon6",WeaponInfo[playerid][Weapon6]);
             
dini_IntSet(file"Weapon6a",WeaponInfo[playerid][Weapon6a]);
          
dini_IntSet(file"Weapon7",WeaponInfo[playerid][Weapon7]);
          
dini_IntSet(file"Weapon7a",WeaponInfo[playerid][Weapon7a]);
          
dini_IntSet(file"Weapon8",WeaponInfo[playerid][Weapon8]);
          
dini_IntSet(file"Weapon8a",WeaponInfo[playerid][Weapon8a]);
          
dini_IntSet(file"Weapon9",WeaponInfo[playerid][Weapon9]);
          
dini_IntSet(file"Weapon9a",WeaponInfo[playerid][Weapon9a]);
          
dini_IntSet(file"Weapon10",WeaponInfo[playerid][Weapon10]);
          
dini_IntSet(file"Weapon10a",WeaponInfo[playerid][Weapon10a]);
          
dini_IntSet(file"Weapon11",WeaponInfo[playerid][Weapon11]);
          
dini_IntSet(file"Weapon11a",WeaponInfo[playerid][Weapon11a]);
          
dini_IntSet(file"Weapon12",WeaponInfo[playerid][Weapon12]);
          
dini_IntSet(file"Weapon12a",WeaponInfo[playerid][Weapon12a]);
          return 
1;

nvm i fixed it!

i changed
PHP код:
else 
to
PHP код:
if (dini_Exists(file)) 
Reply
#2

I updated your code so it's a little.. smaller lol.

pawn Код:
new WeaponInfo[MAX_PLAYERS][13][2];

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), "weapons/%s.ini", name);
    new string[50];
    if (!dini_Exists(file))
    {
        dini_Create(file);
        for(new i = 0; i < 13; i++)
        {
            format(string, sizeof(string), "Weapon%d", i);
            dini_IntSet(file, string, 0);
            format(string, sizeof(string), "Weapon%da", i);
            dini_IntSet(file, string, 0);
        }
    }
    else
    {
        for(new i = 0; i < 13; i++)
        {
            format(string, sizeof(string), "Weapon%d", i);
            WeaponInfo[playerid][i][0] = dini_Int(file, string);
            format(string, sizeof(string), "Weapon%da", i);
            WeaponInfo[playerid][i][1] = dini_Int(file, string);
        }
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
   save(playerid);
   return 1;
}

public OnPlayerSpawn(playerid)
{
    for(new i = 0; i < 13; i++)
    {
        GivePlayerWeapon(playerid, WeaponInfo[playerid][i][0], WeaponInfo[playerid][i][1]);
    }
    SetTimerEx("save", 1, true, "i", playerid);
    return 1;
}

forward save(playerid);
public save(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), "weapons/%s.ini", name);
    new string[50];
    for(new i = 0; i < 13; i++)
    {
        GetPlayerWeaponData(playerid, i, WeaponInfo[playerid][i][0], WeaponInfo[playerid][i][1]);
        format(string, sizeof(string), "Weapon%d", i);
        dini_IntSet(file, string, WeaponInfo[playerid][i][0]);
        format(string, sizeof(string), "Weapon%da", i);
        dini_IntSet(file, string, WeaponInfo[playerid][i][1]);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)