01.06.2016, 17:57
This is an example of threaded (non-lagging) way:
pawn Код:
forward LoadUserData(playerid, dbid);
public LoadUserData(playerid, dbid){
//this stock takes the ID passed to it and queries the user table
//it then stores info in the player enum
new query[128], rows, fields;
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `user` WHERE `id` = %i LIMIT 1;", dbid);
mysql_tquery(mysql, query, "OnUserDataLoaded", "d", playerid);
}
forward OnUserDataLoaded(playerid);
public OnUserDataLoaded(playerid) {
if(!cache_get_row_count(mysql)) {
SendClientMessage(playerid, COLOR_RED, "--------------------------------------------------------");
SendClientMessage(playerid, COLOR_RED, "An error occurred loading user information. Please try again.");
SendClientMessage(playerid, COLOR_RED, "If the problem persists, contact system administrators.");
SetTimerEx("DelayedKick", 1000, false, "i", playerid);
return false;
}
User[playerid][id] = cache_get_field_content_int(0, "id"); //user id
cache_get_field_content(0, "username", User[playerid][username], mysql, 24); //username
User[playerid][id] = cache_get_field_content_int(0, "level"); //level
User[playerid][pass] = 0; //password..never going to need this really so overwritten
cache_get_field_content(0, "timestamp", User[playerid][timestamp], mysql, 10); //timestamp
GetPlayerIp(playerid, User[playerid][ip_address], 16); //set ip address
return true;
}