rons0n Posted December 4, 2015 Share Posted December 4, 2015 I'm going to paste the important parts, if you want the whole file for a better analysis feel free to ask! So my character has a pet and it has: inst:AddComponent("inventory") inst.sword = SpawnPrefab( "assassinsword" ) if inst.sword ~= nil then inst.components.inventory:Equip( inst.sword ) endIn it's character.lua and State { name = "attack", tags = {"attack"}, onenter = function(inst) --inst.SoundEmitter:PlaySound("dontstarve/wilson/hit") inst.components.combat:StartAttack() inst.Physics:Stop() inst.AnimState:PlayAnimation("atk") inst:DoTaskInTime(1, function (inst) inst.components.inventory:Equip( inst.sword ) end ) end, timeline = { TimeEvent(13*FRAMES, function(inst) inst.components.combat:DoAttack() end), }, events = { EventHandler("animover", function(inst) inst.sg:GoToState("idle") end), }, }, Inside the characters stategraphs. What happens is basically no matter what you do with the character weapon, as long as your 'pet' performs the attack action he immediately re-equips the weapon. Doesn't matter where it is. On the floor, in your inventory, etc But the problem i'm dealing with is that: Lets say you've given the character a torch and is aggroed in by spiders. Well the 1st thing he does is attack the spiders. So what happens? The torch immediately dissapears(I'm guessing within the 'pets' inventory to never to be seen again)and is replaced with the character weapon. Is it possible so that if he performs the attack that isn't his weapon, he drops that item first than re-equips and attacks with his character weapon? Link to comment https://forums.kleientertainment.com/forums/topic/59978-tell-my-pet-to-drop-it-before-he-attacks/ Share on other sites More sharing options...
DarkXero Posted December 4, 2015 Share Posted December 4, 2015 local function DropAndSwitch(inst) local swordslot = inst.sword.replica.equippable:EquipSlot() local inventory = inst.components.inventory local currentitem = inventory:GetEquippedItem(swordslot) inventory:DropItem(currentitem) inventory:Equip(inst.sword) end inst:DoTaskInTime(1, DropAndSwitch) Link to comment https://forums.kleientertainment.com/forums/topic/59978-tell-my-pet-to-drop-it-before-he-attacks/#findComment-692227 Share on other sites More sharing options...
rons0n Posted December 4, 2015 Author Share Posted December 4, 2015 (edited) @DarkXero, Oh wow thanks! Not exactly what I wanted but it makes the item not disappear for all eternity. It doesn't drop when it attacks, but it does drop when given Hand Equippable items! Thats awesome! Thanks as Usual Mr.Glommer-Who-Poops-Glorious-Code! Saved me a lot of trouble with other characters as well! Edit: Opps I may have gotten a bit too excited Dx So it seems like if you attack with a torch, he re-equips the weapon, and the torch goes into his inventory(?), BUT if you give him another item(such as an umbrella)he no longer drops the torch but the weapon instead. Is there a way to let him drop his all inventory altogether every time he switches the hand-equippable slot? Edited December 4, 2015 by rons0n Link to comment https://forums.kleientertainment.com/forums/topic/59978-tell-my-pet-to-drop-it-before-he-attacks/#findComment-692271 Share on other sites More sharing options...
DarkXero Posted December 4, 2015 Share Posted December 4, 2015 It doesn't drop when it attacks, but it does drop when given Hand Equippable items! It should drop. State { name = "attack", tags = {"attack"}, onenter = function(inst) --inst.SoundEmitter:PlaySound("dontstarve/wilson/hit") inst.components.combat:StartAttack() inst.Physics:Stop() inst.AnimState:PlayAnimation("atk") inst:DoTaskInTime(1, DropAndSwitch) end, timeline = { TimeEvent(13*FRAMES, function(inst) inst.components.combat:DoAttack() end), }, events = { EventHandler("animover", function(inst) inst.sg:GoToState("idle") end), },}, Code looks like this? Link to comment https://forums.kleientertainment.com/forums/topic/59978-tell-my-pet-to-drop-it-before-he-attacks/#findComment-692280 Share on other sites More sharing options...
rons0n Posted December 4, 2015 Author Share Posted December 4, 2015 @DarkXero, My apologies. I should've known what you've given me was suppose to be added into the stategraphs and not in the character file. Right? Because it works now yay! Sorry about the mix-up! Link to comment https://forums.kleientertainment.com/forums/topic/59978-tell-my-pet-to-drop-it-before-he-attacks/#findComment-692297 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