SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 30/08/2015, 09:42 PM   #1
CrazyChoco
Gangsta
 
Join Date: Feb 2012
Posts: 895
Reputation: 35
Question Delayed saving?

Hey Guys,
I was just wondering about something I just scripted. I wanted to make a delayed saveaccount (don't ask why) which saved 250 ms after player disconnected from server. But somehow, it didn't save any of the player stats even when the timer was called in OnPlayerDisconnect.

Anyhow, then I moved the saveaccount feature to onplayerdisconnect, and now it does save.

My question: How come, I can't save accounts with a delay on disconnect, but only when player disconnected without any delays.
CrazyChoco is offline   Reply With Quote
Old 30/08/2015, 09:51 PM   #2
Zonoya
Gangsta
 
Zonoya's Avatar
 
Join Date: Jul 2011
Location: Am I in Rio de Janeiro or the Amazon, you tell me?
Posts: 664
Reputation: 19
Default Re: Delayed saving?

It's probably because you're trying to save for a specific playerid, and because you're waiting, by the time you run the saveaccount code, the player has already left the game, OnPlayerDisconnect is called just as they leave the server, if you have it wait, it the player has already gone, and thus, you can't really save his stats that way.
__________________
Code:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success) //If the password was incorrect
    {
        printf("FAILED RCON LOGIN BY IP %s USING PASSWORD %s",ip, password);
        new pip[16];
        for(new i=0; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                SendClientMessage(i, 0xFFFFFFFF, "Wrong Password. Bye!"); //Send a message
                Ban(i); //They are now banned.
            }
        }
    }
    return 1;
}
Zonoya is offline   Reply With Quote
Old 30/08/2015, 09:54 PM   #3
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,133
Reputation: 445
Default Re: Delayed saving?

Quote:
Originally Posted by Zonoya View Post
It's probably because you're trying to save for a specific playerid, and because you're waiting, by the time you run the saveaccount code, the player has already left the game, OnPlayerDisconnect is called just as they leave the server, if you have it wait, it the player has already gone, and thus, you can't really save his stats that way.
If you have everything you're saving stored it should work(assuming you are attempting to save using variables and not functions relying on the player being connected). You may have a IsPlayerConnected or such type check in the delayed timer, if so try removing it - though you need to make sure you aren't saving anything using function values(such as the player's position in the timer).
Abagail is offline   Reply With Quote
Old 30/08/2015, 09:55 PM   #4
CrazyChoco
Gangsta
 
Join Date: Feb 2012
Posts: 895
Reputation: 35
Default Re: Delayed saving?

So i'm just wondering, IF i wanted to make a delayed saving (for no reason) how should I then do it?

Well my saving function:
HTML Code:
stock SaveUserAccount(playerid)
{
	new query[256];
	format(query, sizeof(query), "UPDATE `Accounts` SET Adminlevel = %d, Viplevel = %d, Class = %d WHERE `Username` = '%s'",
	UserAccount[playerid][Adminlevel], UserAccount[playerid][Viplevel], UserAccount[playerid][Class], GetName(playerid));
	mysql_function_query(MySQL, query, false, "Query", "");
	return true;
}
CrazyChoco is offline   Reply With Quote
Old 30/08/2015, 09:58 PM   #5
Zonoya
Gangsta
 
Zonoya's Avatar
 
Join Date: Jul 2011
Location: Am I in Rio de Janeiro or the Amazon, you tell me?
Posts: 664
Reputation: 19
Default Re: Delayed saving?

Quote:
Originally Posted by Abagail View Post
If you have everything you're saving stored it should work(assuming you are attempting to save using variables and not functions relying on the player being connected). You may have a IsPlayerConnected or such type check in the delayed timer, if so try removing it - though you need to make sure you aren't saving anything using function values(such as the player's position in the timer).
True. Look at Abagail's post, Choco, make sure all that applies, as they have said, it should work assuming you're not saving information that uses function values (position, money, score) unless you keep it all in variables, which for position is fairly unlikely.

EDIT: Hmm... I don't see anything wrong in that code. I'm going to have to pass the torch here to Abagail, it seems odd that it doesn't work.
__________________
Code:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success) //If the password was incorrect
    {
        printf("FAILED RCON LOGIN BY IP %s USING PASSWORD %s",ip, password);
        new pip[16];
        for(new i=0; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                SendClientMessage(i, 0xFFFFFFFF, "Wrong Password. Bye!"); //Send a message
                Ban(i); //They are now banned.
            }
        }
    }
    return 1;
}
Zonoya is offline   Reply With Quote
Old 30/08/2015, 10:06 PM   #6
CodeStyle175
Banned
 
Join Date: Apr 2014
Posts: 455
Reputation: 35
Default Re: Delayed saving?

It doesnt save because GetName(playerid) is called after player is disconnected
CodeStyle175 is offline   Reply With Quote
Old 30/08/2015, 10:09 PM   #7
CrazyChoco
Gangsta
 
Join Date: Feb 2012
Posts: 895
Reputation: 35
Default Re: Delayed saving?

Quote:
Originally Posted by CodeStyle175 View Post
It doesnt save because GetName(playerid) is called after player is disconnected
So you are saying, that I should getname before disconnnect, and store it in a variable?
CrazyChoco is offline   Reply With Quote
Old 30/08/2015, 10:10 PM   #8
CodeStyle175
Banned
 
Join Date: Apr 2014
Posts: 455
Reputation: 35
Default Re: Delayed saving?

Yes, but why you want to delay player stats saving,because there isnt any point for that.
and also i suggest
mysql_function_query(MySQL, query, false, "Query", ""); change to
mysql_tquery(MySQL, query);
CodeStyle175 is offline   Reply With Quote
Old 30/08/2015, 10:37 PM   #9
CrazyChoco
Gangsta
 
Join Date: Feb 2012
Posts: 895
Reputation: 35
Default Re: Delayed saving?

Quote:
Originally Posted by CodeStyle175 View Post
Yes, but why you want to delay player stats saving,because there isnt any point for that.
and also i suggest
mysql_function_query(MySQL, query, false, "Query", ""); change to
mysql_tquery(MySQL, query);
I just want to experiment with it, for fun. "You never learn, if you don't try it"

-Thanks for pointing it out. I've changed it immediately.
CrazyChoco is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server Crash: NPC Delayed Timers DJ_Shocker Scripting Help 4 28/06/2014 12:38 AM
How to make connect message delayed? grand.Theft.Otto Help Archive 7 24/03/2011 11:17 PM
Delayed Movement 0.3c Pendragon Client Support 1 08/02/2011 06:40 AM
Delayed spawn goes wrong hipy Help Archive 1 22/07/2009 02:08 PM


All times are GMT. The time now is 02:28 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.