Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============Defines===================//
- #define FILTERSCRIPT
- #if defined FILTERSCRIPT
- #define Dialog_Top10 1
- #define Dialog_NA 2
- #define Dialog_Register 3
- #define Dialog_Login 4
- #define Host "localhost"
- #define Username "root"
- #define Pass ""
- #define Database "HeadShot"
- //============Includes==================//
- #include a_samp
- #include a_mysql
- #include izcmd
- enum Info
- {
- HeadShotsW,
- HeadShotsL,
- Kills,
- mID
- }
- new PlayerData[MAX_PLAYERS][Info];
- new MySQL:ConexaoBDD, Query[300];
- new Text:TDEditor_TD[6];
- public OnFilterScriptInit()
- {
- print("--------------------------------------");
- print("HeadShots System Uploaded by: DelK");
- print("--------------------------------------");
- ConexaoBDD = mysql_connect(Host, Username, Pass, Database);
- if(mysql_errno(ConexaoBDD) != 0) printf("Failed to connect to MySQL database [error %d]", mysql_errno(ConexaoBDD));
- else print("Connection to the MySQL database successfully established");
- mysql_query(ConexaoBDD, "CREATE TABLE IF NOT EXISTS Ranking(ID int AUTO_INCREMENT PRIMARY KEY, Nick varchar(24) NOT NULL, HeadShotsW int NOT NULL, HeadShotsL int NOT NULL, Kills int NOT NULL)", false);
- TDEditor_TD[0] = TextDrawCreate(254.939559, 106.649986, "__HeadShot~n~____~n~~n~");
- TextDrawLetterSize(TDEditor_TD[0], 0.703526, 2.539165);
- TextDrawTextSize(TDEditor_TD[0], 416.000000, 0.000000);
- TextDrawAlignment(TDEditor_TD[0], 1);
- TextDrawColor(TDEditor_TD[0], -1);
- TextDrawUseBox(TDEditor_TD[0], 1);
- TextDrawBoxColor(TDEditor_TD[0], 370546326);
- TextDrawSetShadow(TDEditor_TD[0], 0);
- TextDrawSetOutline(TDEditor_TD[0], 1);
- TextDrawBackgroundColor(TDEditor_TD[0], -16776961);
- TextDrawFont(TDEditor_TD[0], 1);
- TextDrawSetProportional(TDEditor_TD[0], 1);
- TDEditor_TD[1] = TextDrawCreate(292.774566, 128.435012, "information_of_his_death");
- TextDrawLetterSize(TDEditor_TD[1], 0.230114, 0.888329);
- TextDrawAlignment(TDEditor_TD[1], 1);
- TextDrawColor(TDEditor_TD[1], -16776961);
- TextDrawSetShadow(TDEditor_TD[1], 0);
- TextDrawSetOutline(TDEditor_TD[1], 0);
- TextDrawBackgroundColor(TDEditor_TD[1], 370546198);
- TextDrawFont(TDEditor_TD[1], 1);
- TextDrawSetProportional(TDEditor_TD[1], 1);
- TDEditor_TD[2] = TextDrawCreate(253.770202, 138.534988, "Weapon:_%s");
- TextDrawLetterSize(TDEditor_TD[2], 0.230114, 0.888329);
- TextDrawAlignment(TDEditor_TD[2], 1);
- TextDrawColor(TDEditor_TD[2], -1378294017);
- TextDrawSetShadow(TDEditor_TD[2], 0);
- TextDrawSetOutline(TDEditor_TD[2], 1);
- TextDrawBackgroundColor(TDEditor_TD[2], 1296911693);
- TextDrawFont(TDEditor_TD[2], 1);
- TextDrawSetProportional(TDEditor_TD[2], 1);
- TDEditor_TD[3] = TextDrawCreate(253.629074, 147.351791, "Damage:_100");
- TextDrawLetterSize(TDEditor_TD[3], 0.230114, 0.888329);
- TextDrawAlignment(TDEditor_TD[3], 1);
- TextDrawColor(TDEditor_TD[3], -1378294017);
- TextDrawSetShadow(TDEditor_TD[3], 0);
- TextDrawSetOutline(TDEditor_TD[3], 1);
- TextDrawBackgroundColor(TDEditor_TD[3], 1296911693);
- TextDrawFont(TDEditor_TD[3], 1);
- TextDrawSetProportional(TDEditor_TD[3], 1);
- TDEditor_TD[4] = TextDrawCreate(253.629074, 156.552352, "Distance:_%f");
- TextDrawLetterSize(TDEditor_TD[4], 0.230114, 0.888329);
- TextDrawAlignment(TDEditor_TD[4], 1);
- TextDrawColor(TDEditor_TD[4], -1378294017);
- TextDrawSetShadow(TDEditor_TD[4], 0);
- TextDrawSetOutline(TDEditor_TD[4], 1);
- TextDrawBackgroundColor(TDEditor_TD[4], 1296911693);
- TextDrawFont(TDEditor_TD[4], 1);
- TextDrawSetProportional(TDEditor_TD[4], 1);
- TDEditor_TD[5] = TextDrawCreate(253.629074, 169.653152, "You_Ittook_one_headshot_in:_%s");
- TextDrawLetterSize(TDEditor_TD[5], 0.230114, 0.888329);
- TextDrawAlignment(TDEditor_TD[5], 1);
- TextDrawColor(TDEditor_TD[5], -1378294017);
- TextDrawSetShadow(TDEditor_TD[5], 0);
- TextDrawSetOutline(TDEditor_TD[5], 1);
- TextDrawBackgroundColor(TDEditor_TD[5], 370546198);
- TextDrawFont(TDEditor_TD[5], 1);
- TextDrawSetProportional(TDEditor_TD[5], 1);
- return 1;
- }
- #endif
- public OnFilterScriptExit()
- {
- mysql_close(ConexaoBDD);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new row;
- mysql_format(ConexaoBDD, Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Name(playerid));
- mysql_query(ConexaoBDD, Query, true);
- cache_get_row_count(row);
- if(row > 0)
- {
- ShowPlayerDialog(playerid, Dialog_Login, DIALOG_STYLE_MSGBOX, "Base - Do not use", "logging in", "Log Into", "Exit");
- }
- else
- {
- ShowPlayerDialog(playerid, Dialog_Register, DIALOG_STYLE_MSGBOX, "Base - Do not use", "Recording", "Register", "Exit");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- UpdateRanking();
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- SendDeathMessage(killerid, playerid, reason);
- if(killerid != INVALID_PLAYER_ID)
- {
- PlayerData[killerid][Kills]++;
- }
- SetTimerEx("Death", 1500, false, "i", playerid);
- return 1;
- }
- forward Death(playerid);
- public Death(playerid)
- {
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- for(new i = 0; i < 7; i++) TextDrawHideForPlayer(playerid, TDEditor_TD[i]);
- return 1;
- }
- public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
- {
- if(issuerid != INVALID_PLAYER_ID && bodypart == 9)
- {
- new string[55], Float: Distance;
- Distance = DistanceBetweenTwoPlayers(issuerid, playerid);
- SetPlayerHealth(playerid, 0);
- format(string, sizeof(string), "Weapon:_%s", Weapon(issuerid));
- TextDrawSetString(TDEditor_TD[2], string);
- format(string, sizeof(string), "Distance:_%.1f Meters", Distance);
- TextDrawSetString(TDEditor_TD[4], string);
- format(string, sizeof(string), "You_Ittook_one_headshot_in:_%s", Name(issuerid));
- TextDrawSetString(TDEditor_TD[5], string);
- for(new i = 0; i < 6; i++) TextDrawShowForPlayer(playerid, TDEditor_TD[i]);
- if(issuerid != INVALID_PLAYER_ID)
- {
- PlayerData[issuerid][HeadShotsW]++;
- PlayerData[playerid][HeadShotsL]++;
- }
- UpdateRanking();
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == Dialog_Register)
- {
- if(!response) return Kick(playerid);
- if(response)
- {
- format(Query, sizeof(Query), "INSERT INTO `Ranking` (Nick, HeadShotsW, HeadShotsL, Kills) VALUES ('%s', '0', '0','0')", Name(playerid));
- mysql_query(ConexaoBDD, Query, true);
- PlayerData[playerid][mID] = cache_insert_id();
- return 1;
- }
- return 1;
- }
- if(dialogid == Dialog_Login)
- {
- if(!response) return Kick(playerid);
- if(response)
- {
- ToChargeRanking(playerid);
- SendClientMessage(playerid, -1, "Successfully logged in!");
- return 1;
- }
- return 1;
- }
- if(dialogid == Dialog_Top10)
- {
- new QueryHeadShot[100];
- if(response)
- {
- if(listitem == 0)
- {
- format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `HeadShotsW` FROM `Ranking` WHERE `HeadShotsW`>'0' ORDER BY HeadShotsW DESC LIMIT 10;");
- mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHeadShotsW", "i", playerid);
- }
- if(listitem == 1)
- {
- format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `HeadShotsL` FROM `Ranking` WHERE `HeadShotsL`>'0' ORDER BY HeadShotsL DESC LIMIT 10;");
- mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHeadShotsL", "i", playerid);
- }
- if(listitem == 2)
- {
- format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `Kills` FROM `Ranking` WHERE `Kills`>'0' ORDER BY Kills DESC LIMIT 10;");
- mysql_tquery(ConexaoBDD, QueryHeadShot, "TopKills", "i", playerid);
- }
- }
- }
- switch(dialogid)
- {
- case Dialog_NA: if(response) return ShowPlayerDialog(playerid, Dialog_Top10, DIALOG_STYLE_LIST, "#Ranking MySQL!", "HeadShotsW\nHeadShotsL\nKills", "Confirm", "Cancel");
- }
- return 1;
- }
- CMD:armas(playerid)
- {
- GivePlayerWeapon(playerid, 24, 999);
- GivePlayerWeapon(playerid, 25, 999);
- GivePlayerWeapon(playerid, 29, 999);
- GivePlayerWeapon(playerid, 31, 999);
- GivePlayerWeapon(playerid, 32, 999);
- GivePlayerWeapon(playerid, 34, 999);
- return 1;
- }
- CMD:top10(playerid)
- {
- UpdateRanking();
- ShowPlayerDialog(playerid, Dialog_Top10, DIALOG_STYLE_LIST, "#Ranking MySQL!", "HeadShotsW\nHeadShotsL\nKills", "Confirm", "Cancel");
- return 1;
- }
- forward TopHeadShotsW(playerid);
- public TopHeadShotsW(playerid)
- {
- new string[200], Nick[70], HSs, contagem = 0;
- for(new i, r = cache_num_rows(); i < r; ++i)
- {
- cache_get_value_name(i, "Nick", Nick);
- cache_get_value_name_int(i, "HeadShotsW", HSs);
- format(string, sizeof(string),"%sNª %d° - %s | HeadShotsW: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Disconnected"):("{00FF00}Connected")));
- contagem++;
- }
- ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsW!", string, "Voltar", "Fechar");
- if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsW!", "There is no one in the Kills Ranking!\n", "Back", "Close");
- return 1;
- }
- forward TopHeadShotsL(playerid);
- public TopHeadShotsL(playerid)
- {
- new string[200], Nick[70], HSs, contagem = 0;
- for(new i, r = cache_num_rows(); i < r; ++i)
- {
- cache_get_value_name(i, "Nick", Nick);
- cache_get_value_name_int(i, "HeadShotsL", HSs);
- format(string, sizeof(string),"%sNª %d° - %s | HeadShotsL: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Disconnected"):("{00FF00}Connected")));
- contagem++;
- }
- ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsL!", string, "Back", "Close");
- if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsL!", "There is no one in the Kills Ranking!\n", "Back", "Close");
- return 1;
- }
- forward TopKills(playerid);
- public TopKills(playerid)
- {
- new string[200], Nick[70], HSs, contagem = 0;
- for(new i, r = cache_num_rows(); i < r; ++i)
- {
- cache_get_value_name(i, "Nick", Nick);
- cache_get_value_name_int(i, "DKills", HSs);
- format(string, sizeof(string),"%sNª %d° - %s | Kills: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Disconnected"):("{00FF00}Connected")));
- contagem++;
- }
- ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking Kills!", string, "Back", "Close");
- if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking Kills!", "There is no one in the Kills Ranking!\n", "Back", "Close");
- return 1;
- }
- stock ToChargeRanking(playerid)
- {
- format(Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Name(playerid));
- mysql_query(ConexaoBDD, Query, true);
- cache_get_value_name_int(0, "ID", PlayerData[playerid][mID]);
- cache_get_value_name_int(0, "HeadShotsW", PlayerData[playerid][HeadShotsW]);
- cache_get_value_name_int(0, "HeadShotsL", PlayerData[playerid][HeadShotsL]);
- cache_get_value_name_int(0, "Kills", PlayerData[playerid][Kills]);
- mysql_query(ConexaoBDD, Query, false);
- return 1;
- }
- stock UpdateRanking()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- format(Query, sizeof(Query), "UPDATE `Ranking` SET `Nick`='%s',`HeadShotsW`=%d,`HeadShotsL`=%d, `Kills`=%d WHERE `ID`=%d", Name(i), PlayerData[i][HeadShotsW], PlayerData[i][HeadShotsL], PlayerData[i][Kills], PlayerData[i][mID]);
- mysql_query(ConexaoBDD, Query, false);
- }
- return 1;
- }
- stock Name(playerid)
- {
- new pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, 24);
- return pName;
- }
- stock Weapon(playerid)
- {
- new ArmaName[15];
- GetWeaponName(GetPlayerWeapon(playerid), ArmaName, 15);
- return ArmaName;
- }
- stock GetPlayerConnect(const pName[])
- {
- static gpName[MAX_PLAYER_NAME];
- for(new i, j = GetPlayerPoolSize(); i <= j; i++)
- {
- GetPlayerName(i, gpName, sizeof(gpName));
- if(strcmp(pName, gpName, false) == 0)
- return i;
- }
- return INVALID_PLAYER_ID;
- }
- stock DistanceBetweenTwoPlayers(playerid, playerid2)
- {
- new Float: Pos1[3], Float: Pos2[3], Float: distance;
- GetPlayerPos(playerid, Pos1[0], Pos1[1], Pos1[2]);
- GetPlayerPos(playerid2,Pos2[0], Pos2[1], Pos2[2]);
- distance = floatsqroot(floatpower(floatabs(floatsub(Pos2[0], Pos1[0])),2)+floatpower(floatabs(floatsub(Pos2[1], Pos1[1])),2)+floatpower(floatabs(floatsub(Pos2[2], Pos1[2])),2));
- return floatround(distance);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement