Jump to content

Saving and counting mob kills


Recommended Posts

Is it possible to count how many mob i killed like 3 deerclops in codes and is it possible to count it? I am thinking something like that in character.lua but i don't have time to test it if anyone knows a better way it would be helpful.

local function countmob(inst, data)
local victim = data.victim
inst.deerclops_count = 0

if (
	victim:HasTag("deerclops")
) then
inst.deerclops_count = inst.deerclops_count +1
end
end

local function onpreload(inst, data)
  if data.deerclops_count then
    inst.deerclops_count = data.deerclops_count
  end
end

local function onsave(inst, data)
  data.deerclops_count = inst.deerclops_count
  end

 

Link to comment
Share on other sites

i dont know how to do it but that would be epic to know how many of _______ youve killed and also it might be nice to have a counter where you could see all the stuff that you burnt just so that in day 1000 you can look at the number and think "wow that was a lot of stuff"

  • Like 1
Link to comment
Share on other sites

Something in this way can be a solution:

local function onkill(inst, data)
  local mob = data.victim.prefab
  if inst.kill_count[mob] then inst.kill_count[mob] = inst.kill_count[mob] + 1 else inst.kill_count[mob] = 1 end
  inst.kill_count["total"] = inst.kill_count["total"] + 1
end

local function onpreload(inst, data)
  if data and data.kill_count then inst.kill_count = data.kill_count end
end

--in char onload
inst:ListenForEvent("killed", onkill)

--in master_postinit
inst.kill_count = { "total" = 0 }

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...