Drug System problem
#1

Okay, I have a drug system and I use dUserSetInt to save player data into a .txt file for all accounts in scriptfiles. I just made it so when someone buys drugs, it will save it in their user file also, just like money, score etc... When I purchase the drugs then /quit the game the drugs save (thankfully) and rejoin, the drugs are still there (thankfully lol). But the problem is if I close the server or gmx (restart) it, the drugs set are deleted in-game and are also set to 0 in the user file. I tried putting this line under OnGameModeInit and Exit:

pawn Код:
if(udb_Exists(PlayerName2(playerid))) dUserSetINT(PlayerName2(playerid)).("drugs",playerdrugs[playerid]);
but obviously doesn't work and doesn't compile because playerid isn't defined as default in OnGameModeInit and Exit, I also tried making a loop for those 2 callbacks:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
   if(udb_Exists(PlayerName2(i))) dUserSetINT(PlayerName2(i)).("drugs",playerdrugs[i]);
}
it compiles, but doesnt work ingame either :S

So my question is how do I get it to save on game mode restart or when i close the server, because the drugs only saves if someone disconnects and rejoins which is good, but doesnt save when the server restarts/closes.

Thanks.
Reply
#2

Bump
Reply
#3

You can't save in OnPlayerDisconnect when the you do "gmx" or close the server.
Make a timer or costum gmx/exit command.
Reply
#4

Use this:

PHP код:
public OnGameModeInit()
{
    for(new 
0MAX_PLAYERS++) { OnPlayerConnect(i); }
    return 
1;
}
public 
OnGameModeExit()
{
    for(new 
0MAX_PLAYERS++) { OnPlayerDisconnect(i1); }
    return 
1;

Reply
#5

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
Use this:

PHP код:
public OnGameModeInit()
{
    for(new 
0MAX_PLAYERS++) { OnPlayerConnect(i); }
    return 
1;
}
public 
OnGameModeExit()
{
    for(new 
0MAX_PLAYERS++) { OnPlayerDisconnect(i1); }
    return 
1;

That's rather interesting.. Does this actually work, because if so: That's a great find!
Reply
#6

Quote:
Originally Posted by Skylar Paul
Посмотреть сообщение
That's rather interesting.. Does this actually work, because if so: That's a great find!
Yes, it works.
Reply
#7

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
Yes, it works.
There is no players on OnGameModeInit. It is called when the script is started, no players have joined yet. For OnGameModeExit, it may work, I wouldn't have a clue.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)