Yakuzashi Posted June 23, 2018 Share Posted June 23, 2018 (edited) Hi, can someone tell me what I did wrong here ? When I hit target it should fall asleep but it does not. So here is my weapon's code with few lines from sleeping dart. Quote local assets= { Asset("ANIM", "anim/wand_saw.zip"), Asset("ANIM", "anim/swap_wand_saw.zip"), Asset("ATLAS", "images/inventoryimages/wand_saw.xml"), Asset("IMAGE", "images/inventoryimages/wand_saw.tex"), } local prefabs = { } ------sleep local function sleepattack(inst, owner, target) if not target:IsValid() then --target killed or removed in combat damage phase return end target.SoundEmitter:PlaySound("dontstarve/common/blackpowder_explo") if target.components.sleeper ~= nil then target.components.sleeper:AddSleepiness(100, 15, inst) elseif target.components.grogginess ~= nil then target.components.grogginess:AddGrogginess(100, 15) end if target.components.combat ~= nil and not target:HasTag("player") then target.components.combat:SuggestTarget(owner) end target:PushEvent("attacked", { owner = owner, damage = 0, weapon = inst }) end local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_wand_saw", "wand") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end local function OnUnequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end local function fn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("wand") inst.AnimState:SetBuild("wand_saw") inst.AnimState:PlayAnimation("idle") inst:AddTag("sharp") if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("weapon") inst.components.weapon:SetDamage(TUNING.SPIKE_DAMAGE) inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES * 3) inst.components.finiteuses:SetUses(TUNING.SPEAR_USES * 3) inst.components.finiteuses:SetOnFinished(inst.Remove) inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "wand_saw" inst.components.inventoryitem.atlasname = "images/inventoryimages/wand_saw.xml" inst:AddComponent("inspectable") inst:AddComponent("equippable") MakeHauntableLaunch(inst) inst.components.equippable:SetOnEquip( OnEquip ) inst.components.equippable:SetOnUnequip( OnUnequip ) inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(200) inst.components.finiteuses:SetUses(200) inst.components.finiteuses:SetOnFinished(inst.Remove) inst:AddComponent("weapon") inst.components.weapon:SetDamage(55) inst.components.weapon:SetOnAttack(sleepattack) inst:AddComponent("tool") inst.components.tool:SetAction(ACTIONS.CHOP, 2) return inst end return Prefab("common/inventory/wand_saw", fn, assets, prefabs) It worked only once when I set first value to 10 on this one [target.components.sleeper:AddSleepiness(100, 15, inst)]. If you are curious about explosion sound it was just indicator. Edited June 23, 2018 by Yakuzashi more info Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted June 30, 2018 Share Posted June 30, 2018 The only thing I can say theres one part of code that crashes me: target:PushEvent("attacked", { owner = owner, damage = 0, weapon = inst }) the rest seems fine, if anything this part wakes up the targets after being put to sleep if target.components.combat ~= nil and not target:HasTag("player") then target.components.combat:SuggestTarget(owner) end so if you want to keep them a sleep remove that part. Link to comment 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