DerpTime 1 Report post Posted July 8, 2015 So to explain...I have 2 character.If "Character A" is killed by "Character B"I want it to drop an item.This is the code for players dropping items.GLOBAL.SetSharedLootTable("stuff", { {"meat", 1.00}, {"meat", 1.00}, {"meat", 0.33}}) AddPlayerPostInit(function(inst) inst:AddComponent("lootdropper") inst.components.lootdropper:SetChanceLootTable("stuff") inst:ListenForEvent("death", function() inst.components.lootdropper:DropLoot(inst:GetPosition()) end)end)Found it here I'm still hunting for the death function, I think it might have some insight in to how to implement this.Any ideas? Share this post Link to post Share on other sites
Malacath 123 Report post Posted July 9, 2015 (edited) If you mean that A and B should be specific player/prefabs, the event "death" get's pushed with some data, see health.lua:self.inst:PushEvent("death", { cause = cause, afflicter = afflicter })So you can listen like this:_G = GLOBAL // A habit, I keep it in this post so the other posts makes sense ^^ inst:ListenForEvent("death", function(data) if data.cause == _G.ThePlayer then inst.components.lootdropper:DropLoot(inst:GetPosition()) end end)I can't promise you that cause will give the prefab that caused it, or if it says something like "combat" but I'm sure with some trial and error you will find out. Maybe you'll want to use afflicter instead. Edited July 10, 2015 by Malacath Share this post Link to post Share on other sites
DerpTime 1 Report post Posted July 10, 2015 _G.ThePlayer whats the _G stand for?ill see what i can do with it. Share this post Link to post Share on other sites
Malacath 123 Report post Posted July 10, 2015 whats the _G stand for?ill see what i can do with it. Sorry,, bad habits ^^' _G = GLOBAL Share this post Link to post Share on other sites
DarkXero 2889 Report post Posted July 10, 2015 @DerpTime,data.cause is a string with the prefab of the entity that killed somebody.data.afflicter is the entity that killed somebody.local valid_murderers = { wilson = true, woodie = true, pinkthing = true, bluething = true,}inst:ListenForEvent("death", function(data) if valid_murderers[data.cause] then inst.components.lootdropper:DropLoot(inst:GetPosition()) endend)So depending on the data.cause, true or nil gets returned. @Malacath, another bad habit to drop is exchanging GetPlayer() with ThePlayer.ThePlayer is used mostly client side. Share this post Link to post Share on other sites
DerpTime 1 Report post Posted July 11, 2015 @DarkXero,actual ive been thinking about this.... doesn't this all not work...since im attempting to make it drop ...post-mortem?Ive been trying some thing differentI made a knife. for the most part i want to have her use this knife and sorta "ritual sacrifice" the other character.no i can make the knife do several things.add tag to target if the tartget is the one i want.i gave her too loot tablesone thats emptyand look for the tag when she dies.the only thing i cant seem to figure out is how to put in a timer for if she escapes, to remove the tag. Share this post Link to post Share on other sites
Malacath 123 Report post Posted July 11, 2015 @DerpTime, as long as the lootdropper component is not being removed on death, which I am pretty sure it isn't, then I don't believe you need to worry about that. So in general anything that you slap onto the player prefab stays there when the player dies. And since data.afflicter is the is the entity of what killed the player you can use most of DarkXero's code. Instead for checking in the table valid_murders you can instead check for tags of data.afflicter and decide upon that.And if I understand your dagger correctly, then you can either use DoTaskInTime after adding the tag to the target, there are many examples of this in the code, or you can listen for the event "losttarget". See what is more convinient for you and go with it. @DarkXero, I don't know what you mean. The code that I posted was a purely didactical example not meant to be ever used in anyone's code. So I don't see a problem with anything I did. And using _G is not actually a "bad habit", it just makes for more natural coding for me when using Lua. Share this post Link to post Share on other sites
DarkXero 2889 Report post Posted July 11, 2015 (edited) I don't know what you mean. The code that I posted was a purely didactical example not meant to be ever used in anyone's code. So I don't see a problem with anything I did. And using _G is not actually a "bad habit", it just makes for more natural coding for me when using Lua. Oh, my mistake then.GLOBAL.SetSharedLootTable("stuff", { {"meat", 1.00}, {"meat", 1.00}, {"meat", 0.33}})AddPlayerPostInit(function(inst) inst:AddComponent("lootdropper") inst.components.lootdropper:SetChanceLootTable("stuff") inst:ListenForEvent("death", function(inst, data) if data and data.afflicter then if data.afflicter.components.inventory then if data.afflicter.components.inventory:EquipHasTag("ritualweapon") then inst.components.lootdropper:DropLoot(inst:GetPosition()) end end end end)end)checks for killer to be holding equipment with the ritualweapon tag. No timers or other stuff. Edited July 11, 2015 by DarkXero Share this post Link to post Share on other sites