Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Top Killers System
- Vice City Multiplayer 0.4
- Squirrel
- By (LBR)Lucas
- */
- Accounts <- {}; /* Table where accounts will be */
- /* FUNCTIONS */
- /* Let's say we are loading the accounts from the database */
- function loadAccounts() {
- //9 "accounts"
- Accounts.rawset(1, {Name = "Player1", Kills = rand() % 1000});
- Accounts.rawset(2, {Name = "Player2", Kills = rand() % 1000});
- Accounts.rawset(3, {Name = "Player3", Kills = rand() % 1000});
- Accounts.rawset(4, {Name = "Player4", Kills = rand() % 1000});
- Accounts.rawset(5, {Name = "Player5", Kills = rand() % 1000});
- Accounts.rawset(6, {Name = "Player6", Kills = rand() % 1000});
- Accounts.rawset(7, {Name = "Player7", Kills = rand() % 1000});
- Accounts.rawset(8, {Name = "Player8", Kills = rand() % 1000});
- Accounts.rawset(9, {Name = "Player9", Kills = rand() % 1000});
- /* NOTE: You will have to adapt this function to load all the accounts of your database. */
- }
- function topKills() {
- /*Here, we will temporarily clone the original table, because we will
- have to delete some data (and we do not want this to happen in the main table)*/
- local backup_Accounts = clone Accounts;
- local limit = 5, tmp = "";
- while (limit) {
- local topScore = 0, index = 0;
- foreach (i, v in backup_Accounts)
- {
- if (backup_Accounts[i]["Kills"] > topScore) {
- topScore = backup_Accounts[i]["Kills"];
- index = i;
- }
- }
- if (index) tmp = tmp + backup_Accounts[index]["Name"] + " - " + backup_Accounts[index]["Kills"] + ", ";
- backup_Accounts.rawdelete(index);
- limit --;
- }
- return tmp != "" ? tmp.slice(0, tmp.len() - 2) : "No top killers";
- }
- function getAccountID(str) {
- foreach (i, v in Accounts) {
- if (Accounts[i]["Name"].tolower() == str.tolower()) {
- return i;
- break;
- }
- }
- return 0;
- }
- /* SERVER EVENTS */
- function onScriptLoad() {
- loadAccounts();
- print(topKills());
- }
- function onPlayerKill(killer, player, reason, bodypart) {
- /* Do not forget to update the amount of kills when the player scores */
- local i = getAccountID(killer.Name);
- if (i) Accounts[i]["Kills"] ++;
- }
Add Comment
Please, Sign In to add comment