PDA

View Full Version : How can I add a timer to this?


Dokins
05/02/2013, 04:56 PM
it's under OnPlayerConnect.

Basically, my server has a little lag I think and it logs the player in before checking if they're banned, theres nothing wrong with my code below, I think. It's just that when a player connects, it takes a while to load up and I'd like to let the server load up first before logging in?


new escape[MAX_PLAYER_NAME*2];
mysql_real_escape_string(GetName(playerid), escape);
format(query, sizeof(query), "SELECT `id` FROM `accounts` WHERE `PlayerName` = '%s' LIMIT 1", escape);
mysql_query(query);
mysql_store_result();

if(mysql_num_rows() > 0)
{
PlayerSQLID[playerid] = mysql_fetch_int();
new string[256],ip[16], pip;

Tazed[playerid] = 0;
pip = GetPlayerIp(playerid, ip, sizeof(ip));
Time[playerid] = gettime();
BanTime[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "BanTime", "accounts");
if(BanTime[playerid] > Time[playerid])
{
format(string,sizeof(string), "You are still {FF0000}BANNED{FFFFFF} from Bone County Roleplay until {FF0000}%s", date(BanTime[playerid]));
SendClientMessage(playerid, COLOUR_WHITE, string);
SendClientMessage(playerid, COLOUR_REALRED, "{FFFFFF}PLEASE DO {FF0000}NOT{FFFFFF} POST A {FF0000}BAN APPEAL {FFFFFF}as this is a Temporary Ban.");
SetTimerEx("KickPlayer",100,false,"i",playerid);// Kicks player in 500ms
}
if(Time[playerid] > BanTime[playerid]) // Check when a player connects to see if they have a timestamp, and if they do, check if it exceeds gettime()
{
MySQL_SetInteger(PlayerSQLID[playerid], "BanTime", 0, "accounts");
}
if(IsPlayerBanned(playerid) == 1)
{
format(string,sizeof(string), "Your IP:{FF0000} %s{FFFFFF} is {FF0000}BANNED{FFFFFF} from Bone County Roleplay.", pip);
SendClientMessage(playerid, COLOUR_WHITE, string);
format(string, sizeof(string), "PLEASE POST A {FF0000}BAN APPEAL{FFFFFF} ON http://bc-rp.net/forum/");
SendClientMessage(playerid, COLOUR_WHITE, string);
SetTimerEx("KickPlayer",100,false,"i",playerid);// Kicks player in 500ms
}
if(BanTime[playerid] == 0 && IsPlayerBanned(playerid)== 0)
{
format(string, sizeof(string), "Welcome to %s (SQLID %d)\n\nPlease enter your password below:", HOSTNAME, PlayerSQLID[playerid]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login Dialog", string, "Login", "Leave");
}
}
else
{
new string[256];
format(string, sizeof(string), "Welcome to %s\n\nPlease create an account by entering a password below:", HOSTNAME);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register Dialog", string, "Register", "Leave");
}
mysql_free_result();
}

Faisal_khan
05/02/2013, 05:00 PM
So add a timer to the login dialog. Read wiki.sa-mp.com for timers.

Dokins
05/02/2013, 05:05 PM
I CANT BELIEVE HOW STUPID I AM. I've been away from this for a while. Thank you. + rep.

Faisal_khan
05/02/2013, 05:06 PM
No problem, shit happens ;)

Dokins
05/02/2013, 05:07 PM
Hang on...Where do I put the timer? Shouldn't I delay it being displayed by putting a timer before it?

Faisal_khan
05/02/2013, 05:16 PM
Something like this:forward login();

public OnGameModeInit()
{
SetTimer("login", 1000, false); // Set a timer of 1000 miliseconds (1 second)
}

public login()
{
ShowPlayerDialog(...);
}

public OnPlayerConnect(playerid)
{
login();
return 1;
}

Dokins
05/02/2013, 05:18 PM
Sense = made. Thank you very much.

Faisal_khan
05/02/2013, 05:20 PM
No Problemo bruh!

Dokins
05/02/2013, 05:21 PM
Ugh just when I thought I got it, do I literally copy my login section? I'm a little confused.

Faisal_khan
05/02/2013, 05:28 PM
Yes, like this:


new escape[MAX_PLAYER_NAME*2];
mysql_real_escape_string(GetName(playerid), escape);
format(query, sizeof(query), "SELECT `id` FROM `accounts` WHERE `PlayerName` = '%s' LIMIT 1", escape);
mysql_query(query);
mysql_store_result();

if(mysql_num_rows() > 0)
{
PlayerSQLID[playerid] = mysql_fetch_int();
new string[256],ip[16], pip;

Tazed[playerid] = 0;
pip = GetPlayerIp(playerid, ip, sizeof(ip));
Time[playerid] = gettime();
BanTime[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "BanTime", "accounts");
if(BanTime[playerid] > Time[playerid])
{
format(string,sizeof(string), "You are still {FF0000}BANNED{FFFFFF} from Bone County Roleplay until {FF0000}%s", date(BanTime[playerid]));
SendClientMessage(playerid, COLOUR_WHITE, string);
SendClientMessage(playerid, COLOUR_REALRED, "{FFFFFF}PLEASE DO {FF0000}NOT{FFFFFF} POST A {FF0000}BAN APPEAL {FFFFFF}as this is a Temporary Ban.");
SetTimerEx("KickPlayer",100,false,"i",playerid);// Kicks player in 500ms
}
if(Time[playerid] > BanTime[playerid]) // Check when a player connects to see if they have a timestamp, and if they do, check if it exceeds gettime()
{
MySQL_SetInteger(PlayerSQLID[playerid], "BanTime", 0, "accounts");
}
if(IsPlayerBanned(playerid) == 1)
{
format(string,sizeof(string), "Your IP:{FF0000} %s{FFFFFF} is {FF0000}BANNED{FFFFFF} from Bone County Roleplay.", pip);
SendClientMessage(playerid, COLOUR_WHITE, string);
format(string, sizeof(string), "PLEASE POST A {FF0000}BAN APPEAL{FFFFFF} ON http://bc-rp.net/forum/");
SendClientMessage(playerid, COLOUR_WHITE, string);
SetTimerEx("KickPlayer",100,false,"i",playerid);// Kicks player in 500ms
}
if(BanTime[playerid] == 0 && IsPlayerBanned(playerid)== 0)
{
login();//added the callback here
}
}
else
{
new string[256];
format(string, sizeof(string), "Welcome to %s\n\nPlease create an account by entering a password below:", HOSTNAME);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register Dialog", string, "Register", "Leave");
}
mysql_free_result();
}
public login()
{
format(string, sizeof(string), "Welcome to %s (SQLID %d)\n\nPlease enter your password below:", HOSTNAME, PlayerSQLID[playerid]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login Dialog", string, "Login", "Leave");
}

Dokins
05/02/2013, 05:39 PM
Thank you very much. I really appreciate the time you have voluntarily given up, I have learned from this!