Save-Point
[XP][XAS] XAS Enemy Kill Counter - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: [XP][XAS] XAS Enemy Kill Counter (/thread-5432.html)



[XP][XAS] XAS Enemy Kill Counter - Narzew - 03-28-2015

Script to count enemy kills in XAS-based game. Works with RMXP.
If you use custom save system, look at the bottom of the script, to prevent old save corruption.

Usage:
$game_system.get_enemy_kills(id) => get kills of enemy id
For example when I kill 3 enemies with ID 6, and 2 enemies with ID 7:
$game_system.get_enemy_kills(6) => 3
$game_system.get_enemy_kills(7) => 2

Code:
#====================================================
#**XAS Enemy Kill Counter
#**v 1.00
#**28.03.15
#**Narzew
#====================================================
#**License: GPL v3
#**Website: HackTut.org
#====================================================
#**Designed for XAS 3.91
#**Not tested with XAS 3.8 or lower
#====================================================
#**Instructions:
#**Paste the script in Xas Addons Section (below XAS Engine)
#**Use $game_system.get_enemy_kills(enemy_id) to get enemy kills
#**for example: $game_system.get_enemy_kills(2) will get number
#**of enemies with id 2 killed.
#====================================================

#====================================================
#**Game_System overwrite
#====================================================

class Game_System
  attr_accessor :enemy_kills
  alias xas_enemy_kill_counter_narzew1 initialize
  
  #====================================================
  #**Overwrite initialize method
  #====================================================
  
  def initialize
    @enemy_kills = []
    xas_enemy_kill_counter_narzew1
  end
  
  #====================================================
  #**gain_enemy_kill(id) => gain enemy kill of id
  #====================================================
  
  def gain_enemy_kill(id)
    if @enemy_kills[id] == nil
      @enemy_kills[id] = 0
    end
    @enemy_kills[id] += 1
  end
  
  #====================================================
  #**get_enemy_kills(id) => return number of kills of a enemy id
  #====================================================
  
  def get_enemy_kills(id)
    if @enemy_kills[id] == nil
      @enemy_kills[id] = 0
    end
    return @enemy_kills[id]
  end
  
end

#====================================================
#**Game_Event overwrite
#====================================================

class Game_Event < Game_Character
  
  #====================================================
  #**Overwrite enemy_defat_process defined by XAS
  #====================================================
  
  alias xas_enemy_kill_counter_narzew2 enemy_defeat_process
  def enemy_defeat_process(enemy)
    $game_system.gain_enemy_kill(enemy.id)
    xas_enemy_kill_counter_narzew2(enemy)
  end
  
end

#====================================================
#**Anti Save Corruption
#**Rewrite Scene_Load::read_save_data
#====================================================
#**If you use custom load system, comment method below and add:
#**$game_system.enemy_kills = [] if $game_system.enemy_kills == nil
#**after line:
#**$game_system = Marshal.load(file)
#====================================================

class Scene_Load < Scene_File
  alias xas_enemy_kill_counter_narzew3 read_save_data
  def read_save_data(file)
    xas_enemy_kill_counter_narzew3(file)
    $game_system.enemy_kills = [] if $game_system.enemy_kills == nil
  end
end