Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------- DoesPlayerExist ----------------*/
- Server:DoesPlayerExist(playerid)
- {
- new query[128];
- mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM users WHERE Name = '%e' LIMIT 1", GetName(playerid));
- mysql_pquery(sqlConnection, query, "SQL_DoesPlayerExist", "i", playerid);
- return true;
- }
- Server:SQL_DoesPlayerExist(playerid)
- {
- if(cache_get_row_count(sqlConnection) != 0) // Player Exists
- {
- ShowLoginDialog(playerid, "");
- return true;
- }
- else // Player Doesn't Exist
- {
- ShowRegisterDialog(playerid, "");
- return false;
- }
- }
- /*------------- ShowRegisterDialog ----------------*/
- Server:ShowRegisterDialog(playerid, error[])
- {
- if(LoggedIn[playerid]) return true;
- if(!strmatch(error, "")) {
- SendClientMessage(playerid, COLOR_WHITE, error);
- }
- SendClientMessage(playerid, COLOR_PINK, "You are playing on a practice RP script that is most likely incomplete with loads of bugs.");
- ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Matt's RP - Register", "Please enter a password to register an account.", "Register", "Quit");
- return true;
- }
- /*------------- ShowLoginDialog ------------------*/
- Server:ShowLoginDialog(playerid, error[])
- {
- if(LoggedIn[playerid]) return true;
- if(!strmatch(error, "")) {
- SendClientMessage(playerid, COLOR_WHITE, error);
- }
- ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Matt's RP - Login", "Please enter a password to login to your account.", "Login", "Quit");
- return true;
- }
- /*------------- AccountRegistered ------------------*/
- Server:SQL_AccountRegistered(playerid)
- {
- // Set unique player id
- pInfo[playerid][pSQLID] = cache_insert_id();
- // Send message.
- SendClientMessage(playerid, COLOR_WHITE, "You have successfully registered with the server. All statistics will be saved under this username!");
- // Clear the previous data values.
- LoadDefaultValues(playerid);
- // Load the player info.
- LoadPlayerInfo(playerid);
- return true;
- }
- /*------------- AccountLogin ------------------*/
- Server:SQL_AccountLogin(playerid)
- {
- if(cache_num_rows() == 0) {
- ShowLoginDialog(playerid, "Incorrect password.");
- return true;
- }
- // Send message
- SendClientMessage(playerid, COLOR_WHITE, "You have successfully logged into the server. All statistics will be saved under this username!");
- // Clear the previous data values.
- LoadDefaultValues(playerid);
- pInfo[playerid][pSQLID] = cache_get_field_content_int(0, "id", sqlConnection);
- // Load the players information.
- LoadPlayerInfo(playerid);
- return true;
- }
- /*------------- LoadPlayerInfo ------------------*/
- Server:LoadPlayerInfo(playerid)
- {
- new query[128];
- mysql_format(sqlConnection, query, sizeof(query), "SELECT * FROM users WHERE id = %d LIMIT 1", pInfo[playerid][pSQLID]);
- mysql_pquery(sqlConnection, query, "LoadPlayerInfo_", "i", playerid);
- return true;
- }
- Server:LoadPlayerInfo_(playerid)
- {
- LoggedIn[playerid] = true;
- pInfo[playerid][pAdminLevel] = cache_get_field_content_int(0, "AdminLevel", sqlConnection); // Get Admin Level
- pInfo[playerid][pMoney] = cache_get_field_content_int(0, "Money", sqlConnection); // Get Money
- pInfo[playerid][pLastPos][0] = cache_get_field_content_float(0, "LastX", sqlConnection);
- pInfo[playerid][pLastPos][1] = cache_get_field_content_float(0, "LastY", sqlConnection);
- pInfo[playerid][pLastPos][2] = cache_get_field_content_float(0, "LastZ", sqlConnection);
- pInfo[playerid][pLastPos][3] = cache_get_field_content_float(0, "LastRot", sqlConnection);
- pInfo[playerid][pLastInt] = cache_get_field_content_int(0, "Interior", sqlConnection);
- pInfo[playerid][pLastWorld] = cache_get_field_content_int(0, "World", sqlConnection);
- pInfo[playerid][pSkin] = cache_get_field_content_int(0, "Skin", sqlConnection);
- ResetPlayerMoney(playerid);
- GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
- SetPlayerSpawn(playerid);
- return true;
- }
- Server:TIMER_OneSecondTimer()
- {
- foreach(Player, i) {
- if(LoggedIn[i]) {
- LastSaveTime++;
- if(LastSaveTime < 5) {
- SavePlayerPos(i, false);
- } else {
- SavePlayerPos(i, true);
- LastSaveTime = 0;
- }
- }
- }
- return true;
- }
- Server:SavePlayerPos(playerid, bool:save)
- {
- GetPlayerPos(playerid, pInfo[playerid][pLastPos][0], pInfo[playerid][pLastPos][1], pInfo[playerid][pLastPos][2]);
- GetPlayerFacingAngle(playerid, pInfo[playerid][pLastPos][3]);
- pInfo[playerid][pLastInt] = GetPlayerInterior(playerid);
- pInfo[playerid][pLastWorld] = GetPlayerVirtualWorld(playerid);
- if(save) {
- new query[128];
- mysql_format(sqlConnection, query, sizeof(query), "UPDATE users SET LastX = %f, LastY = %f, LastZ = %f, LastRot = %f, Interior = %i, World = %i WHERE id = %i LIMIT 1",
- pInfo[playerid][pLastPos][0], pInfo[playerid][pLastPos][1], pInfo[playerid][pLastPos][2], pInfo[playerid][pLastPos][3], pInfo[playerid][pLastInt], pInfo[playerid][pLastWorld], pInfo[playerid][pSQLID]);
- mysql_pquery(sqlConnection, query);
- }
- return true;
- }
- /*------------- SetPlayerSpawn ------------------*/
- Server:SetPlayerSpawn(playerid)
- {
- SetSpawnInfo(playerid, 0, DEFAULT_SKIN, pInfo[playerid][pLastPos][0], pInfo[playerid][pLastPos][1], pInfo[playerid][pLastPos][2], pInfo[playerid][pLastPos][3], 0, 0, 0, 0, 0, 0);
- SpawnPlayer(playerid);
- SetPlayerVirtualWorld(playerid, pInfo[playerid][pLastWorld]);
- SetPlayerInterior(playerid, pInfo[playerid][pLastInt]);
- return true;
- }
- /*------------- LoadDefaultValues ------------------*/
- Server:LoadDefaultValues(playerid)
- {
- pInfo[playerid][pSQLID] = 0;
- pInfo[playerid][pAdminLevel] = 0;
- pInfo[playerid][pMoney] = 0;
- }
- /*------------- Send Local Message ------------------*/
- Server:SendLocalMessage(playerid, color, msg[])
- {
- if(!LoggedIn[playerid])return true;
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- foreach(Player, i) {
- if(LoggedIn[i]){
- if(IsPlayerInRangeOfPoint(i, 15.0, x, y, z) && GetPlayerInterior(i) == GetPlayerInterior(playerid) && GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
- SendClientMessage(i, color, msg);
- return true;
- }
- }
- }
- return true;
- }
- /*------------- Send Local Message Distance ------------------*/
- Server:SendLocalMessageDist(playerid, color, msg[], Float:distance)
- {
- if(!LoggedIn[playerid])return true;
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- foreach(Player, i) {
- if(LoggedIn[i]){
- if(IsPlayerInRangeOfPoint(i, distance, x, y, z) && GetPlayerInterior(i) == GetPlayerInterior(playerid) && GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
- SendClientMessage(i, color, msg);
- return true;
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement