PDA

View Full Version : Weapons don't load! :(


Brandondw8
20/05/2014, 07:43 PM
They save...but reset when I connect.
#define FILTERSCRIPT

#include <a_samp>
#include <dini>
#include <dudb>
#include <sscanf2>

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()
{

}

#endif


public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), "/Accounts/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(playerid, reason)
{
return 1;
}

public OnPlayerSpawn(playerid)
{
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon1], WeaponInfo[playerid][Weapon1a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon2], WeaponInfo[playerid][Weapon2a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon3], WeaponInfo[playerid][Weapon3a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon4], WeaponInfo[playerid][Weapon4a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon5], WeaponInfo[playerid][Weapon5a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon6], WeaponInfo[playerid][Weapon6a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon7], WeaponInfo[playerid][Weapon7a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon8], WeaponInfo[playerid][Weapon8a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon9], WeaponInfo[playerid][Weapon9a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon10], WeaponInfo[playerid][Weapon10a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon11], WeaponInfo[playerid][Weapon11a]);
GivePlayerWeapon(playerid, WeaponInfo[playerid][Weapon12], WeaponInfo[playerid][Weapon12a]);
SetTimerEx("save", 2000, 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), "/Accounts/weapons/%s.ini", name);
GetPlayerWeaponData(playerid, 1, WeaponInfo[playerid][Weapon1], WeaponInfo[playerid][Weapon1a]);
GetPlayerWeaponData(playerid, 2, WeaponInfo[playerid][Weapon2], WeaponInfo[playerid][Weapon2a]);
GetPlayerWeaponData(playerid, 3, WeaponInfo[playerid][Weapon3], WeaponInfo[playerid][Weapon3a]);
GetPlayerWeaponData(playerid, 4, WeaponInfo[playerid][Weapon4], WeaponInfo[playerid][Weapon4a]);
GetPlayerWeaponData(playerid, 5, WeaponInfo[playerid][Weapon5], WeaponInfo[playerid][Weapon5a]);
GetPlayerWeaponData(playerid, 6, WeaponInfo[playerid][Weapon6], WeaponInfo[playerid][Weapon6a]);
GetPlayerWeaponData(playerid, 7, WeaponInfo[playerid][Weapon7], WeaponInfo[playerid][Weapon7a]);
GetPlayerWeaponData(playerid, 8, WeaponInfo[playerid][Weapon8], WeaponInfo[playerid][Weapon8a]);
GetPlayerWeaponData(playerid, 9, WeaponInfo[playerid][Weapon9], WeaponInfo[playerid][Weapon9a]);
GetPlayerWeaponData(playerid, 10, WeaponInfo[playerid][Weapon10], WeaponInfo[playerid][Weapon10a]);
GetPlayerWeaponData(playerid, 11, WeaponInfo[playerid][Weapon11], WeaponInfo[playerid][Weapon11a]);
GetPlayerWeaponData(playerid, 12, WeaponInfo[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;
}

DarK_FeneR
20/05/2014, 09:50 PM
my problem, too... :( dini of sh**

rumen98
20/05/2014, 10:01 PM
#include <a_samp>
#include <dini>

#define PATH "Weapons"

new bool:AlreadyGiveWeapons[MAX_PLAYERS];

public OnFilterScriptInit()
{
printf("|------------------------------------------|");
printf("|--------- Weapons Saving System --------|");
printf("|No published version-----------------------|");
return 1;
}

public OnFilterScriptExit()
{
printf("|-----------------------------------------|");
printf("|---- Unload Weapons Saving System------|");
printf("|No published version----------------------|");
return 1;
}

public OnPlayerConnect(playerid)
{
AlreadyGiveWeapons[playerid] = false;
return 1;
}

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

SaveWeaponsToFile(playerid)
{
new i, path[50], string[128], weaponid, ammo;
path = GetPlayerFormattedName(playerid);
if (!dini_Exists(path)) dini_Create(path);
for (i=0; i<13; i++)
{
GetPlayerWeaponData(playerid,i,weaponid,ammo);
format(string,sizeof(string),"Weapon - %d",i);
dini_IntSet(path,string,weaponid);
format(string,sizeof(string),"AmmoID - %d",i);
dini_IntSet(path,string,ammo == 65535 ? 0 : ammo);
}
}

forward LoadWeaponsToFile(playerid);
public LoadWeaponsToFile(playerid)
{
new i, path[50], string[128], weaponid, ammo;
path = GetPlayerFormattedName(playerid);
ResetPlayerWeapons(playerid);
for (i=0; i<13; i++)
{
format(string,sizeof(string),"Weapon - %d",i);
weaponid = dini_Int(path,string);
format(string,sizeof(string),"AmmoID - %d",i);
ammo = dini_Int(path,string);
GivePlayerWeapon(playerid,weaponid,ammo);
}
AlreadyGiveWeapons[playerid] = true;
}

GetPlayerFormattedName(playerid)
{
new name[24], full[50];
GetPlayerName(playerid,name,sizeof(name));
format(full,sizeof(full),"%s/%s.txt",PATH,name);
return full;
}

public OnPlayerSpawn(playerid)
{
if (!AlreadyGiveWeapons[playerid]) SetTimerEx("LoadWeaponsToFile",250,false,"i",playerid);
return 1;
}
Should work, I tested it worked

Brandondw8
20/05/2014, 10:08 PM
my problem, too... :( dini of sh**

His works! Go to pawno and make a new file, save it in your filterscripts, add a Weapons folder in scriptfiles and it works!

#include <a_samp>
#include <dini>

#define PATH "Weapons"

new bool:AlreadyGiveWeapons[MAX_PLAYERS];

public OnFilterScriptInit()
{
printf("|------------------------------------------|");
printf("|--------- Weapons Saving System --------|");
printf("|No published version-----------------------|");
return 1;
}

public OnFilterScriptExit()
{
printf("|-----------------------------------------|");
printf("|---- Unload Weapons Saving System------|");
printf("|No published version----------------------|");
return 1;
}

public OnPlayerConnect(playerid)
{
AlreadyGiveWeapons[playerid] = false;
return 1;
}

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

SaveWeaponsToFile(playerid)
{
new i, path[50], string[128], weaponid, ammo;
path = GetPlayerFormattedName(playerid);
if (!dini_Exists(path)) dini_Create(path);
for (i=0; i<13; i++)
{
GetPlayerWeaponData(playerid,i,weaponid,ammo);
format(string,sizeof(string),"Weapon - %d",i);
dini_IntSet(path,string,weaponid);
format(string,sizeof(string),"AmmoID - %d",i);
dini_IntSet(path,string,ammo == 65535 ? 0 : ammo);
}
}

forward LoadWeaponsToFile(playerid);
public LoadWeaponsToFile(playerid)
{
new i, path[50], string[128], weaponid, ammo;
path = GetPlayerFormattedName(playerid);
ResetPlayerWeapons(playerid);
for (i=0; i<13; i++)
{
format(string,sizeof(string),"Weapon - %d",i);
weaponid = dini_Int(path,string);
format(string,sizeof(string),"AmmoID - %d",i);
ammo = dini_Int(path,string);
GivePlayerWeapon(playerid,weaponid,ammo);
}
AlreadyGiveWeapons[playerid] = true;
}

GetPlayerFormattedName(playerid)
{
new name[24], full[50];
GetPlayerName(playerid,name,sizeof(name));
format(full,sizeof(full),"%s/%s.txt",PATH,name);
return full;
}

public OnPlayerSpawn(playerid)
{
if (!AlreadyGiveWeapons[playerid]) SetTimerEx("LoadWeaponsToFile",250,false,"i",playerid);
return 1;
}
Should work, I tested it worked

Thank you Sir!

rumen98
20/05/2014, 10:10 PM
No problem, I'm glad that I helped you

Brandondw8
20/05/2014, 10:15 PM
No problem, I'm glad that I helped you

Glad someone finally helped fix it.
Already +repped ;)