FaZZa Posted April 6, 2016 Share Posted April 6, 2016 (edited) 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 April 6, 2016 by FaZZa Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/ Share on other sites More sharing options...
Muche Posted April 6, 2016 Share Posted April 6, 2016 (edited) 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 April 6, 2016 by Muche Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/#findComment-745744 Share on other sites More sharing options...
FaZZa Posted April 6, 2016 Author Share Posted April 6, 2016 Thank you for the code however i put it in the .lua and it caused a crash. Im still using the goldnugget as the soulprefab for testing purposes. Any ideas on how to fix? Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/#findComment-745770 Share on other sites More sharing options...
Muche Posted April 6, 2016 Share Posted April 6, 2016 That was meant for modmain.lua, not character prefab file (since that is the only place AddComponentPostInit from which it is easily accessed and uses GLOBAL.FindEntity; it wouldn't need GLOBAL to access FindEntity from within character prefab file). Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/#findComment-745774 Share on other sites More sharing options...
FaZZa Posted April 6, 2016 Author Share Posted April 6, 2016 ah my bad, ive put it in the modmain.lua, and happily no crash, however no gold nuggets are being dropped Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/#findComment-745782 Share on other sites More sharing options...
Muche Posted April 7, 2016 Share Posted April 7, 2016 (edited) 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 April 7, 2016 by Muche fixed code Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/#findComment-745787 Share on other sites More sharing options...
FaZZa Posted April 7, 2016 Author Share Posted April 7, 2016 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? Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/#findComment-745810 Share on other sites More sharing options...
FaZZa Posted April 7, 2016 Author Share Posted April 7, 2016 (edited) Scratch that, i found the right place for it, thanks alot mate, youre very helpful. Edited April 7, 2016 by FaZZa Link to comment https://forums.kleientertainment.com/forums/topic/66131-character-specific-loot-drops/#findComment-745834 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now