SA-MP Forums Archive
enum saving help - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: enum saving help (/showthread.php?tid=195070)



enum saving help - <Weponz> - 01.12.2010

Ok i have a fuel system that saves in game but once you /q and relog you lost all the fuel you have,How can i save it into a file so then i can GetPlayerInfo in OnPlayerSpawn so thay will have there fuel they originally had?

This is what i have:

pawn Код:
enum pInfo
{
    FuelAmount,
}

new PlayerInfo[MAX_PLAYERS][pInfo];

//This is how i give and take fuel
PlayerInfo[playerid][FuelAmount] = PlayerInfo[playerid][FuelAmount] -200;

PlayerInfo[playerid][FuelAmount] = PlayerInfo[playerid][FuelAmount] +200;

//etc etc etc
Any help?

Thanks In Advanced!


Re: enum saving help - Jochemd - 01.12.2010

Use dini - it's nice! Make a player account with his name

pawn Код:
public OnPlayerConnect(playerid)
{
    new Playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,Playername,sizeof(Playername)); // Lets say your name is Johnny
    if(dini_Exists(Playername)) PlayerInfo[playerid][FuelAmount] = dini_Int(Playername,"FuelAmount");
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new Playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,Playername,sizeof(Playername)); // Lets say your name is Johnny
    dini_IntSet(Playername,"FuelAmount",PlayerInfo[playerid][FuelAmount]); // FuelAmount in file Johnny contains now the amount of Fuel you have.
    return 1;
}



Re: enum saving help - <Weponz> - 01.12.2010

Can u explain it more,Im lost with dini and files etc,Can you please give me an example :S


Re: enum saving help - Jochemd - 01.12.2010

It's in my previous post now.


Re: enum saving help - <Weponz> - 01.12.2010

This will just automatically get there fuel stats? or do i have to do more?

Thanks BTW


Re: enum saving help - Jochemd - 01.12.2010

This is it.


Re: enum saving help - Kwarde - 01.12.2010

And it is better if you make a stock of it

pawn Код:
stock LoadPlayer(playerid)
{
    new pName[MAX_PLAYER_NAME], fstring[288]; //Idk why I am using 288 for files :S
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Get's a player name
    format(fstring, 288, "%s.ini", pName); //Format file "scriptfiles/USERNAME.ini".
    if(!dini_Exists(fstring)) return 0; //If the "scriptfiles/USERNAME.ini" doesn't exists. don't continue
    PlayerInfo[playerid][FuelAmmount] = dini_Int(fstring, "FuelAmmount");
    return 1;
}

stock SavePlayer(playerid)
{
    new pName[MAX_PLAYER_NAME], fstring[288]; //Idk why I am using 288 for files :S
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Get's a player name
    format(fstring, 288, "%s.ini", pName); //Format file "scriptfiles/USERNAME.ini".
    if(!dini_Exists(fstring)) dini_Create(fstring); //If the "scriptfiles/USERNAME.ini" doesn't exists, create it
    dini_IntSet(fstring, "FuelAmmount", PlayerInfo[playerid][FuelAmmount]);
    return 1;
}
Now you can use "LoadPlayer(playerid);" and "SavePlayer(playerid);"


Re: enum saving help - Jochemd - 01.12.2010

Yea that's good also but why are you using VERY oversized strings? Use 128 maximum :P xD


Re: enum saving help - Kwarde - 01.12.2010

128 is for client message's max strings
But I already know why I am using 288 (file string); I used a super save system with big strings AND file's :P
And the string where bigger then 200 (alot of maps, HASH + MD5 and codes)
I used that for benchmarks and backup's / old data. For example, if a players crashes, he'll get all his EXACT data back
Example of a map+file:
scriptfiles/safety/FF0/Players/Debug/SaveData/Temp/Backups/Server/1-12-2010/Hour_17/Kevin_Warde__HASHCODEHASHCODEHASHCODEMD5MD5MD5MD5M D5_39849328982749381294._tmp.txt.data_old :P
And I've decoded more stuff, but that's private. Only that above isn't really safe :/

Whatever,
His question is answered. I won't reply in this topic anymore.
If you have any comments, PM me