enum saving help
#1

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!
Reply
#2

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;
}
Reply
#3

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

It's in my previous post now.
Reply
#5

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

Thanks BTW
Reply
#6

This is it.
Reply
#7

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);"
Reply
#8

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)