Name=Me-Borno X=0.00 Y=0.00 Z=0.00
1=Me-Borno 2=Other 3=Random
#include <dini>
new IDCache[MAX_PLAYERS]; //this will store the ID of the player.. it is the ID we manualy make, so not the "playerid" one new LoggedIn[MAX_PLAYERS]; //checks if the player is logged in new NickCache[MAX_PLAYERS][64]; //this will store the nickname of a player
public OnPlayerConnect(playerid) { new name[64]; GetPlayerName(playerid, name); NickCache[playerid] = name; //stored the player name into NickCache[playerid] } public OnPlayerDisconnect(playerid, reason) { NickCache[playerid] = ""; //makes the NickCache[playerid] empty LoggedIn[playerid] = 0; //dont forget this, else if someone joins on the playerid of the previous player, he whould be logged in xD }
stock GetUserID(name[]) //this is the function name, duh.. { new result; //this will eventualy store the ID of the player. for(new a = 1; a <= 10000; a++) //loops true all players, in/decrease if you have less slots { if(strlen(dini_Get("PLN.ini", a)) != 0) //this wil check if the name corresponding to the ID != "" { if(strfind(dini_Get("PLN.ini", a), name, true) == 0) //this wil check if the User name == name[] { result = a; //so the result will be a(the id) a = 10001; //and this will quit the for, so we wont continue } } else a = 10001; //if the slot doesn't contain anny info, it'll quit the for-statement } if(result != 0) return result; //so this returns the ID if found else return -1; // and if no result found, it'll return -1 }
stock Register(playerid, pass[]) { if(LoggedIn[playerid] == 1) return SendClientMessage(playerid, 0x000000, "You are already loggedin"); //if the player is loggedin, it will send this message if(GetUserID(NickCache[playerid]) != -1) return SendClientMessage(playerid, 0x000000, "You are already registered"); //if a player is already registered, itll send this message if(!strlen(pass)) return SendClientMessage(playerid, 0x000000, "Usage: /register <pass>"); //if the user didn't gave a password, itll send this message new result = -1; for(new a=1; a<10000; a++) //loop thrue all players { if(!strlen(dini_Get("PLN.ini", a))) //checks if the ID is empty { result = a; //will be the ID a = 10001; //will end the loop } } if(result != -1) { dini_Set("PLP.ini", result, pass); //sets the password in the ID table dini_Set("PLN.ini", result, NickCache[playerid]); //saves the name in the ID table SendClientMessage(playerid, 0x000000, "thanks for registering!"); IDCache[playerid] = result; //stores the ID LoggedIn[playerid] = 1; //the player is now loggedin } return 1; }
stock Login(playerid, pass[]) { if(LoggedIn[playerid] == 1) return SendClientMessage(playerid, 0x000000, "You are already loggedin"); if(GetUserID(NickCache[playerid]) == -1) return SendClientMessage(playerid, 0x000000, "Your account is not registered"); if(!strlen(pass)) return SendClientMessage(playerid, 0x000000, "Usage: /login <pass>"); new uid = GetUserID(NickCache[playerid]); if(strcmp(dini_Get("PLP.ini", uid), pass, true , strlen(dini_Get("PLP.ini", uid))) return SendClientMessage(playerid, 0x000000, "Incorrect password"); IDCache[playerid] = result; LoggedIn[playerid] = 1; return 1; }
if(result != -1) { dini_Set("PLP.ini", result, pass); //sets the password in the ID table dini_Set("PLN.ini", result, NickCache[playerid]); //saves the name in the ID table SendClientMessage(playerid, 0x000000, "thanks for registering!"); IDCache[playerid] = result; //stores the ID LoggedIn[playerid] = 1; //the player is now loggedin }
Код:
if(result != -1) { dini_Set("PLP.ini", result, pass); //sets the password in the ID table dini_Set("PLN.ini", result, NickCache[playerid]); //saves the name in the ID table SendClientMessage(playerid, 0x000000, "thanks for registering!"); IDCache[playerid] = result; //stores the ID LoggedIn[playerid] = 1; //the player is now loggedin } just asking cuz you didnt state it up at the top with the xyz ini's. |