SA-MP Forums Archive
Weapon Saving - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Weapon Saving (/showthread.php?tid=303490)



Weapon Saving - Oh - 13.12.2011

pawn Code:
#include <a_samp>
#include <dini>

#define PATH "Weapons"  //  Folder where players data saved

new bool:AlreadyGiveWeapons[MAX_PLAYERS];

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;
}


For some reason this crashes players near the person who dies.


Does anyone know why this happens?


THAT and, if anyone else has a different method please help / explain how to use it.


Re: Weapon Saving - jueix - 13.12.2011

Ye because when the player dies i think it reloads the weapons so basicly its trying to load weapons that aint there thats what i think it is but.


Re: Weapon Saving - Oh - 13.12.2011

I don\'t get it, anyone else?


Re: Weapon Saving - Rob_Maate - 13.12.2011

Why are you loading weapons from a file during gameplay?
Surely it would be better to just save the data in an array
Like
pawn Code:
new PlayerWeapons[MAX_PLAYERS][13];



Re: Weapon Saving - TheArcher - 13.12.2011

My question is, does that script really saves?

pawn Code:
#define PATH "Weapons"  //  Folder where players data saved
If weapons is a folder how can it be saved? If you meant file name. So you have to specify the format. e.g
pawn Code:
#define PATH "Weapons.ini"



Re: Weapon Saving - Oh - 13.12.2011

Uh it saves in different .inis it works fine.

It\'s just when a player dies people die near you, I don\'t understand how to make this "better".

Nor really knew how to do this in the first place. I just need to fix the crashing if a player dies near you.