Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <a_mysql>
- #include <sscanf2>
- #include <colors>
- new RandomMSG[][] =
- {
- "{FF0000}[BOT]S.A.M.:{FFFFFF}Please visit our forums to read the latest news!",
- "{FF0000}[BOT]S.A.M.:{FFFFFF}Did you know, the owners are Brad & illuminati?",
- "{FF0000}[BOT]S.A.M.:{FFFFFF}Please report if you have any questions",
- "{FF0000}[BOT]S.A.M.:{FFFFFF}Please visit our forums to read the latest news!"
- };
- native WP_Hash(_buffer[], len, const str[]);
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- #define MySQL_Host ""
- #define MySQL_Username "server_739"
- #define MySQL_Password ""
- #define MySQL_Database "server_739"
- enum pInfo
- {
- pScore,
- pAdmin,
- pVip,
- pTrusted,
- pHighest,
- pMoney,
- pKills,
- pDeaths
- }
- new PlayerInfo[MAX_PLAYERS][pInfo];
- new connection;
- new MySQL_Query[1800];
- new PasswordAttempts[MAX_PLAYERS];
- new IsPlayerLoggedIn[MAX_PLAYERS char];
- forward LoggedIn(playerid, const password[]);
- forward CheckPasswordAttempts(playerid);
- forward IsRegistered(playerid);
- //==============================================================================
- main()
- {
- print("\n----------------------------------");
- print(" Blank Gamemode by your name here");
- print("----------------------------------\n");
- }
- public OnGameModeInit()
- {
- SetTimer("SendMSG", 60000, true);
- connection = mysql_connect(MySQL_Host, MySQL_Username, MySQL_Database, MySQL_Password);
- if(!mysql_errno(connection)) print("MySQL Connection Success");
- else print("MySQL Connection Failed");
- SetGameModeText("Blank Script");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- return 1;
- }
- forward SendMSG();
- public SendMSG()
- {
- new randMSG = random(sizeof(RandomMSG));
- SendClientMessageToAll(-1, RandomMSG[randMSG]); // Replace the "COLOR" with your defined color.
- }
- public OnGameModeExit()
- {
- mysql_close(connection);
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- format(MySQL_Query, sizeof(MySQL_Query), "SELECT * FROM `Accounts` WHERE Username = '%s'", EscapeText(PlayerName(playerid)));
- mysql_function_query(connection, MySQL_Query, true, "IsRegistered", "i", playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(IsPlayerLoggedIn{playerid} == 1)
- {
- format(MySQL_Query, sizeof(MySQL_Query), "UPDATE `Accounts` SET Score = '%i' , Admin = '%i' , Vip = '%i' , Trusted_Players = '%i' , Highest_Donator = '%i' , Money = '%i', Kills = '%i', Deaths = '%i' WHERE Username = '%s'",
- PlayerInfo[playerid][pScore], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pVip], PlayerInfo[playerid][pTrusted], PlayerInfo[playerid][pHighest], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], EscapeText(PlayerName(playerid)));
- mysql_function_query(connection, MySQL_Query, false, "", "");
- }
- PlayerInfo[playerid][pAdmin] = 0;
- PlayerInfo[playerid][pVip] = 0;
- PlayerInfo[playerid][pScore] = 0;
- PlayerInfo[playerid][pTrusted] = 0;
- PlayerInfo[playerid][pHighest] = 0;
- PlayerInfo[playerid][pMoney] = 0;
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(killerid != INVALID_PLAYER_ID) return 1;
- PlayerInfo[playerid][pDeaths] += 1;
- PlayerInfo[killerid][pKills] += 1;
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- /*public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/mycommand", cmdtext, true, 10) == 0)
- {
- // Do something here
- return 1;
- }
- return 0;
- }*/
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- return 1;
- }
- public OnPlayerObjectMoved(playerid, objectid)
- {
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- return 1;
- }
- public OnVehicleMod(playerid, vehicleid, componentid)
- {
- return 1;
- }
- public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
- {
- return 1;
- }
- public OnVehicleRespray(playerid, vehicleid, color1, color2)
- {
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- return 1;
- }
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- public OnRconLoginAttempt(ip[], password[], success)
- {
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- return 1;
- }
- public OnPlayerStreamIn(playerid, forplayerid)
- {
- return 1;
- }
- public OnPlayerStreamOut(playerid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamIn(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamOut(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_REGISTER)
- {
- if(!response)
- {
- Kick(playerid);
- return 1;
- }
- if(!strlen(inputtext))
- {
- SendClientMessage(playerid, -1, "Enter a password.");
- ShowRegisterScreen(playerid);
- return 1;
- }
- if(strlen(inputtext) < 5)
- {
- SendClientMessage(playerid, -1, "Enter a password with more than 5 characters.");
- ShowRegisterScreen(playerid);
- return 1;
- }
- if(strlen(inputtext) >= 5)
- {
- new IP[20], hashedpass[200];
- GetPlayerIp(playerid, IP, sizeof(IP));
- WP_Hash(hashedpass, sizeof(hashedpass), inputtext);
- new querystring[1800];
- strcat(querystring, "INSERT INTO `Accounts` (`ID`, `Username`, `Password`, `Admin`, `Vip, `Money`, `Kills`, `Deaths`, `Trusted_Player`, `Highest_Donator`)");
- strcat(querystring, " VALUES");
- format(MySQL_Query, sizeof(MySQL_Query), "%s (NULL, '%s', '%s', '0', '0', '0', '0', '0', '0', '0')", querystring, EscapeText(PlayerName(playerid)), EscapeText(hashedpass));
- mysql_function_query(connection, MySQL_Query, false, "", "");
- }
- IsPlayerLoggedIn{playerid} = 1;
- return 1;
- }
- if(dialogid == DIALOG_LOGIN)
- {
- if(!response)
- {
- Kick(playerid);
- return 1;
- }
- if(!strlen(inputtext))
- {
- SendClientMessage(playerid, -1, "Enter a password.");
- ShowLoginScreen(playerid);
- }
- if(strlen(inputtext) < 5)
- {
- SendClientMessage(playerid, -1, "Enter a password with more than 5 char.");
- ShowLoginScreen(playerid);
- }
- if(strlen(inputtext) >= 5)
- {
- format(MySQL_Query, sizeof(MySQL_Query), "SELECT * FROM `Accounts` WHERE Username='%s'", EscapeText(PlayerName(playerid)));
- mysql_function_query(connection, MySQL_Query, true, "LoggedIn", "is", playerid, inputtext);
- }
- return 1;
- }
- return 1;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
- public LoggedIn(playerid, const password[])
- {
- new ppassword[500];
- new hashedpass[500];
- WP_Hash(hashedpass, sizeof(hashedpass), password);
- cache_get_field_content(0, "Password", ppassword, connection);
- if(!strcmp(hashedpass, ppassword))
- {
- if(IsPlayerLoggedIn{playerid} != 1)
- {
- new tempfetch[500];
- cache_get_field_content(0, "Score", tempfetch, connection), PlayerInfo[playerid][pScore] = strval(tempfetch);
- cache_get_field_content(0, "Admin", tempfetch, connection), PlayerInfo[playerid][pAdmin] = strval(tempfetch);
- cache_get_field_content(0, "Vip", tempfetch, connection), PlayerInfo[playerid][pVip] = strval(tempfetch);
- cache_get_field_content(0, "Trusted_Player", tempfetch, connection), PlayerInfo[playerid][pTrusted] = strval(tempfetch);
- cache_get_field_content(0, "Highest_Donator", tempfetch, connection), PlayerInfo[playerid][pHighest] = strval(tempfetch);
- cache_get_field_content(0, "Money", tempfetch, connection), PlayerInfo[playerid][pMoney] = strval(tempfetch);
- cache_get_field_content(0, "Kills", tempfetch, connection), PlayerInfo[playerid][pKills] = strval(tempfetch);
- cache_get_field_content(0, "Deaths", tempfetch, connection), PlayerInfo[playerid][pDeaths] = strval(tempfetch);
- IsPlayerLoggedIn{playerid} = 1;
- SendClientMessage(playerid, -1, "{8EC7DC}[INFO] {FFFFFF}Your statistics have been restored.");
- return 1;
- }
- }
- else
- {
- CheckPasswordAttempts(playerid);
- ShowLoginScreen(playerid);
- }
- return 1;
- }
- public CheckPasswordAttempts(playerid)
- {
- if(PasswordAttempts[playerid] == 0)
- {
- SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [1/3]");
- PasswordAttempts[playerid] ++;
- return 1;
- }
- if(PasswordAttempts[playerid] == 1)
- {
- SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [2/3]");
- PasswordAttempts[playerid] ++;
- return 1;
- }
- if(PasswordAttempts[playerid] == 2)
- {
- new string[128];
- SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}You have entered an incorrect password. [3/3]");
- format(string,sizeof(string),"{208DD6}[SERVER] {FFFFFF}%s[%d] has been kicked from the server. (Max password attempts)",PlayerName(playerid),playerid);
- SendClientMessageToAll(COLOR_WHITE,string);
- Kick(playerid);
- return 1;
- }
- return 1;
- }
- public IsRegistered(playerid)
- {
- new rows, fields;
- cache_get_data(rows, fields, connection);
- if(rows)
- {
- ShowLoginScreen(playerid);
- }
- else
- {
- ShowRegisterScreen(playerid);
- }
- return 1;
- }
- public OnQueryError(errorid, error[], callback[], query[], connectionHandle)
- {
- printf("Error ID: %i", errorid);
- printf("Error: %s", error);
- printf("callback: %s", callback);
- printf("query: %s", query);
- return 1;
- }
- stock EscapeText(text[])
- {
- new EscapedData[200];
- mysql_real_escape_string(text, EscapedData, connection);
- return EscapedData;
- }
- stock ShowLoginScreen(playerid)
- {
- new string[128];
- format(string, sizeof(string), "Before playing you must login\n\nUsername: %s\n\nEnter your password below and click login",PlayerName(playerid));
- ShowPlayerDialog(playerid,DIALOG_LOGIN,3,"{EDDC57}Login required",string,"Login","Cancel");
- }
- stock ShowRegisterScreen(playerid)
- {
- new string[128];
- format(string, sizeof(string), "This server requires you to register an account before playing\n\nUsername: %s\n\nEnter your desired password below then click ok",PlayerName(playerid));
- ShowPlayerDialog(playerid,DIALOG_REGISTER,3,"{EDDC57}Registration required",string,"Register","Cancel");
- }
- stock PlayerName(playerid)
- {
- new name[21];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- CMD:setlevel(playerid,params[])
- {
- new string[128], ID, level;
- if(PlayerInfo[playerid][pAdmin] < 3) // change this to owner level
- return SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}You don't have access to this command.");
- if(sscanf(params,"ii",ID,level))
- return SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}USAGE: /setlevel [playerid] [Level]");
- if(!IsPlayerConnected(ID))
- return SendClientMessage(playerid, COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}The requested playerid is not connected to the server.");
- if(PlayerInfo[playerid][pAdmin] <= PlayerInfo[ID][pAdmin])
- return SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF} This has no effect on the current playerid.");
- if(PlayerInfo[ID][pAdmin] == level)
- {
- format(string,sizeof(string),"{B30000}[ERROR] {FFFFFF}%s[%d] is already at the Administrator level: %d",PlayerName(ID),ID,level);
- SendClientMessage(playerid,COLOR_WHITE,string);
- return 1;
- }
- if(playerid == ID)
- return SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}You cannot set your own Administrator level.");
- if(PlayerInfo[ID][pAdmin] < level)
- {
- format(string, sizeof(string), "{46A4E3}[ADMIN] {FFFFFF}%s[%d] has promoted %s[%d] to level %d.",PlayerName(playerid),playerid,PlayerName(ID),ID,level);
- SendClientMessageToAll(COLOR_WHITE,string);
- }
- else if(PlayerInfo[ID][pAdmin] > level)
- {
- format(string, sizeof(string), "{46A4E3}[ADMIN] {FFFFFF}%s[%d] has demoted %s[%d] to level %d.",PlayerName(playerid),playerid,PlayerName(ID),ID,level);
- SendClientMessageToAll(COLOR_WHITE,string);
- }
- PlayerInfo[ID][pAdmin] = level;
- return 1;
- }
- CMD:setscore(playerid,params[])
- {
- new string[128], ID, score;
- if(PlayerInfo[playerid][pAdmin] < 3) // change to owner rank
- return SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}You don't have access to this command.");
- if(sscanf(params,"ii",ID,score))
- return SendClientMessage(playerid, COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}The requested playerid is not connected to the server.");
- if(!IsPlayerConnected(ID))
- return SendClientMessage(playerid, COLOR_WHITE,"{B30000}[ERROR] {FFFFFF}The requested playerid is not connected to the server.");
- if(PlayerInfo[playerid][pAdmin] < PlayerInfo[ID][pAdmin])
- return SendClientMessage(playerid,COLOR_WHITE,"{B30000}[ERROR] {FFFFFF} This has no effect on the current playerid.");
- format(string,sizeof(string),"{46A4E3}[ADMIN] {FFFFFF}%s[%d] has set %s[%d]'s score to %d.",PlayerName(playerid),playerid,PlayerName(ID),ID,score);
- SendClientMessageToAll(COLOR_WHITE,string);
- SetPlayerScore(ID, score);
- PlayerInfo[ID][pScore] = score;
- return 1;
- }
- CMD:kick(playerid, params[])
- {
- new id, sendername[MAX_PLAYER_NAME], string[128], reason[128];
- if(PlayerInfo[playerid][pAdmin] >= 1) return SendClientMessage(playerid, -1," you are not authorized to use this command");
- if(sscanf(params,"us[128]",id, reason)) return SendClientMessage(playerid, -1,"USAGE: /kick [playerid/partofname] [reason]");
- if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1,"Player is not connected");
- else
- {
- GetPlayerName(playerid, sendername, sizeof(sendername));
- format(string, sizeof(string), "AdmCmd: %s was kicked by %s, reason: %s", id, sendername, reason);
- SendClientMessageToAll(0xF00505FF ,string);
- Kick(id);
- }
- return 1;
- }
- CMD:ban(playerid, params[])
- {
- new id, sendername[MAX_PLAYER_NAME], string[128], reason[128];
- if(PlayerInfo[playerid][pAdmin] >= 1) return SendClientMessage(playerid, -1," you are not authorized to use this command");
- if(sscanf(params,"us[128]",id, reason)) return SendClientMessage(playerid, -1,"USAGE: /ban [playerid/partofname] [reason]");
- if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1,"Player is not connected");
- else
- {
- GetPlayerName(playerid, sendername, sizeof(sendername));
- format(string, sizeof(string), "AdmCmd: %s was BANNED! by %s, reason: %s", id, sendername, reason);
- SendClientMessageToAll(0xF00505FF ,string);
- Ban(id);
- }
- return 1;
- }
- CMD:forcekill(playerid, params[]) //using ZCMD this is how your command will start off looking like.
- {
- new otherplayerid;
- if(PlayerInfo[playerid][pAdmin] >= 3) return SendClientMessage(playerid, -1," you are not authorized to use this command");
- if(sscanf(params, "u", otherplayerid)) return SendClientMessage(playerid, COLOR_RED, "Use /forcekill [playerid/name]");
- else if(!IsPlayerConnected(otherplayerid)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
- else
- {
- SendClientMessage(otherplayerid,COLOR_RED,"You have been killed by an Administrator");
- SetPlayerHealth(otherplayerid,0);
- }
- return 1;
- }
- CMD:pay(playerid,params[])
- {
- new
- ID,
- amount,
- name[MAX_PLAYERS],
- string7[200],
- name2[MAX_PLAYERS],
- string8[200];
- if(sscanf(params, "ui", ID,amount)) return SendClientMessage(playerid, -1, "Usage: /pay [playerid] [amount]");
- if(amount > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1, "[ERROR]: You do not have enough money to pay that player!");
- if(amount <= 0) return SendClientMessage(playerid, -1, "[ERROR]: You cannot pay less than $1!");
- if(playerid == ID) return SendClientMessage(playerid, -1, "[ERROR]: You can't pay yourself!");
- GetPlayerName(ID, name2, sizeof(name2));
- format(string8, sizeof(string8),"You have paid %s $%i", name2, amount);
- SendClientMessage(playerid, COLOR_RED, string8);
- GetPlayerName(playerid, name, sizeof(name));
- format(string7, sizeof(string7), "%s(%d) Has paid you: $%i", name, playerid, amount);
- SendClientMessage(ID, COLOR_RED, string7);
- GivePlayerMoney(ID, amount);
- GivePlayerMoney(playerid, -amount);
- return 1;
- }
- CMD:fixveh(playerid,params[])
- {
- if(PlayerInfo[playerid][pAdmin] >= 3) return SendClientMessage(playerid, -1," you are not authorized to use this command");
- RepairVehicle(GetPlayerVehicleID(playerid));
- SendClientMessage(playerid, -1, "Vehicle Repaired");
- return 1;
- }
- CMD:givecash(playerid, params[])
- {
- new pID, cash;
- if(PlayerInfo[playerid][pAdmin] >= 6)
- {
- if(sscanf(params, "ud", pID, cash)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givecash [playerid] [amount of money]");
- if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
- ResetPlayerMoney(pID);
- return GivePlayerMoney(pID,cash);
- }
- else if(PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid, -1," you are not authorized to use this command");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement