Drug System problem - 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: Drug System problem (
/showthread.php?tid=265381)
Drug System problem -
grand.Theft.Otto - 30.06.2011
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.
Re: Drug System problem -
grand.Theft.Otto - 01.07.2011
Bump
Re: Drug System problem -
=WoR=Varth - 02.07.2011
You can't save in OnPlayerDisconnect when the you do "gmx" or close the server.
Make a timer or costum gmx/exit command.
Re: Drug System problem -
Shadoww5 - 02.07.2011
Use this:
PHP код:
public OnGameModeInit()
{
for(new i = 0; i < MAX_PLAYERS; i ++) { OnPlayerConnect(i); }
return 1;
}
public OnGameModeExit()
{
for(new i = 0; i < MAX_PLAYERS; i ++) { OnPlayerDisconnect(i, 1); }
return 1;
}
Re: Drug System problem -
Skylar Paul - 02.07.2011
Quote:
Originally Posted by Shadoww5
Use this:
PHP код:
public OnGameModeInit()
{
for(new i = 0; i < MAX_PLAYERS; i ++) { OnPlayerConnect(i); }
return 1;
}
public OnGameModeExit()
{
for(new i = 0; i < MAX_PLAYERS; i ++) { OnPlayerDisconnect(i, 1); }
return 1;
}
|
That's rather interesting.. Does this actually work, because if so: That's a great find!
Re: Drug System problem -
Shadoww5 - 02.07.2011
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.
Re: Drug System problem -
[HiC]TheKiller - 02.07.2011
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.