AutismAlex

ZombieKillCounter

May 9th, 2021 (edited)
631
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. event onLoad(){
  2.     // nonQuery as we are creating a table
  3.     database.nonQuery("CREATE TABLE IF NOT EXISTS playerstats(
  4.    id VARCHAR(17) PRIMARY KEY,
  5.    zombiesKilled INT NOT NULL DEFAULT 0,
  6.    megaZombiesKilled INT NOT NULL DEFAULT 0
  7.    );");
  8. }
  9.  
  10. event onPlayerJoined(player){
  11.     // nonquery as we are inserting data
  12.     // @p0 acts as a placeholder, which the first argument is then passed into
  13.     database.nonQuery("INSERT IGNORE INTO playerstats (id, zombiesKilled, megaZombiesKilled) VALUES ('@p0', 0, 0);", player.id);
  14. }
  15.  
  16. event onZombieKilled(player){
  17.     // nonQuery as we are updating data, and not reading it
  18.     database.nonQuery("UPDATE playerstats SET zombiesKilled = zombiesKilled + 1 WHERE id = '@p0';", player.id);
  19. }
  20.  
  21. event onMegaZombieKilled(player){
  22.     // nonquery as we are inserting data
  23.     database.nonQuery("UPDATE playerstats SET megaZombiesKilled = megaZombiesKilled + 1 WHERE id = '@p0';", player.id);
  24. }
  25.  
  26. command zombiekills(){
  27.     permission = "zombiekills";
  28.     allowedCaller = "player";
  29.     execute(){
  30.         // firstRow as we only want to fetch one row of data for that player.
  31.         data = database.firstRow("Select * FROM playerstats WHERE id = '@p0';", player.id);
  32.         if(data.count == 0) return; // return if the data does not exist for some reason to prevent errors.
  33.         // message the player the info, the placeholders {0} and {1} are replaced with data[1] and data[2]
  34.         player.message("Zombies Killed: {0}\nMegas Killed: {1}".format(data[1], data[2]));
  35.     }
  36. }
RAW Paste Data