Jump to content

Recommended Posts

Hi all.

Im making a voodoo themed character, and would like him be able to collect the souls of things that die near him because of an item im working on called the Soul Lantern, however i dont want them to be in the inventory, instead the lantern would show the number of souls, similar to how a spear shows durability. 

If possible, i want tougher creatures to drop more souls, maybe for every 50 health something has, it would drop 1 soul.

So for example, if the character had the Lantern equipped in his hand, and killed a rabbit, the rabbit would drop 1 Soul (since they have 25 health), which the character would then be able to pick up, which would raise the number on the Soul Lantern by 1. However if he killed a hound, it would drop 3 souls (since hounds have 150 health).

Does anyone know where I could find the code to make this happen, something i could base it off, or would even be kind enough to write the code for me.

Thanks in advance. 

 

 

Edited by FaZZa

I had following idea:

local RADIUS = 10 -- radius in which the player has to be for the victim to drop some souls
local SOULCOLLECTORTAG = "SoulCollector" -- tag on the player
local SOULPREFAB = "goldnugget" -- replace with own
local HP_PER_SOUL = 50

AddComponentPostInit("lootdropper", function(LootDropper, inst)
	local old_GenerateLoot = LootDropper.GenerateLoot
	LootDropper.GenerateLoot = function(self)
		local loots = old_GenerateLoot(self)

		if not self.inst.components.health then
			-- it was a non-living thing
			return loots
		end

		local soulcollector = GLOBAL.FindEntity(self.inst, RADIUS, nil, { SOULCOLLECTORTAG }, nil, nil)
		if soulcollector == nil then
			-- no soul collector nearby
			return loots
		end

		local maxhp = self.inst.components.health:GetMaxWithPenalty()
		local numsouls = math.ceil(maxhp / HP_PER_SOUL)
		for i = 1, numsouls do
			table.insert(loots, SOULPREFAB)
		end

		return loots
	end
end)

The rounding might need some tweaking, currently it always rounds up.

SOULPREFAB would be your prefab without inventoryitem component, so it won't be pickupable. A custom action for soul lantern with associated EQUIPPED or USEITEM component action could allow interacting with souls on the ground.

Edited by Muche

Does your character have the SoulCollector tag? For temporary testing purposes you can enter ThePlayer:AddTag("SoulCollector") into the debug console.

Does the target have the loopdropper component?

Here is a version with couple of debug prints:

AddComponentPostInit("lootdropper", function(LootDropper, inst)
	--print(("[ComponentPostInit_lootdropper(%s,%s)"):format(tostring(LootDropper), tostring(inst)))
	local old_GenerateLoot = LootDropper.GenerateLoot
	LootDropper.GenerateLoot = function(self)
		print(("[custom_lootdropper:GenerateLoot()]#1 self=%s, inst=%s"):format(tostring(self), tostring(self.inst)))
		local loots = old_GenerateLoot(self)
		print(("[custom_lootdropper:GenerateLoot()]#2 loots=%s"):format(tostring(loots)))
		if type(loots) == "table" then GLOBAL.dumptable(loots, 1, 0) end

		if not self.inst.components.health then
			-- it was a non-living thing
			print("[custom_lootdropper:GenerateLoot()]#3 non-living thing")
			return loots
		end

		local soulcollector = GLOBAL.FindEntity(self.inst, RADIUS, nil, { SOULCOLLECTORTAG }, nil, nil)
		if soulcollector == nil then
			-- no soul collector nearby
			print("[custom_lootdropper:GenerateLoot()]#4 no soulcollector nearby")
			return loots
		end

		local maxhp = self.inst.components.health:GetMaxWithPenalty()
		local numsouls = math.ceil(maxhp / HP_PER_SOUL)
		print(("[custom_lootdropper:GenerateLoot()]#5 maxhp=%s, numsouls=%s"):format(tostring(maxhp), tostring(numsouls)))
		for i = 1, numsouls do
			table.insert(loots, SOULPREFAB)
		end
		print(("[custom_lootdropper:GenerateLoot()]#6 loots=%s"):format(tostring(loots)))
		if type(loots) == "table" then GLOBAL.dumptable(loots, 1, 0) end

		return loots
	end
end)

 

Edited by Muche
fixed code

Using the original code you gave me and putting  ThePlayer:AddTag("SoulCollector")  in the console made it work, gold nuggets everywhere! and tougher things gave more gold so that works also.

Where do i need to put the  SoulCollector tag? in the .lua?

 

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
×
  • Create New...