Jump to content

Recommended Posts

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 )	end

In 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?

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)

@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 by rons0n
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?

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...