dungdodger Posted December 24, 2014 Share Posted December 24, 2014 local function onattack(inst, owner, target) local theta = math.random() * 2 * PI local pt = inst:GetPosition() local radius = math.random(3, 6) local offset = FindWalkableOffset(pt, theta, radius, 12, true) if offset then local image = SpawnPrefab("pigman") local pos = pt + offset image.Transform:SetPosition(pos:Get()) doeffects(inst, pos) --image.components.follower:SetLeader(owner) owner.components.sanity:DoDelta(-TUNING.SANITY_TINY * 10) --owner.components.sanity:RecalculatePenalty() inst.SoundEmitter:PlaySound("dontstarve/maxwell/shadowmax_appear") return true end This is where i need to be i think.... new to all this,, Any how what i'm going for it to make the weapon unable to attack and spawn the pigman if im under 50 Sanity like before when it was a.. The Book code worked but i wasnt able to kill the mob and replace it with a pigman..... Here is what i tried to change to get the book code to work with the weapon code..local function canattack(inst) return (inst.components.sanity.current >= 50) end local function onattack(inst, owner, target) --Check sanity if not canattack(target) then if owner.components.talker then owner.components.talker:Say(GetString(owner.prefab, "ANNOUNCE_NOSANITY")) return true end endas u can see iv changed the onread and the canread (reader) just had no idea what i was doing but trying none the less ... It all works ...kinda as i want it to other then being able to still use it when under 50 sanity... if anyone could let me know what needs to change to make this work please speak up............ Im also looking in to making the mobs killed with this weapon not drop loot or if theres a way to desummon the target on hit replacing it with a pigman that would be the true Goal... And thanks for trying. Link to comment https://forums.kleientertainment.com/forums/topic/47457-help-with-sanity-check-onattack/ Share on other sites More sharing options...
dungdodger Posted December 24, 2014 Author Share Posted December 24, 2014 Ok Made some progress with this as of now it will only do the effect if i have the sanity and regents.. but it is still letting me use the Item as a Weapon ... I have been trying random stuff to make this work ,,,Can anyone help me Im trying to make it where im unable to attack with the weapon if under 50 Sanity.. Not just turn the effect off... local assets={Asset("ANIM", "anim/pighat.zip"),Asset("ANIM", "anim/swap_pighat.zip"),Asset("ATLAS", "images/inventoryimages/pighat.xml"),Asset("IMAGE", "images/inventoryimages/pighat.tex"),}prefabs = {"pigman","shadowwaxwell"}local function doeffects(inst, pos)SpawnPrefab("statue_transition").Transform:SetPosition(pos:Get())SpawnPrefab("statue_transition_2").Transform:SetPosition(pos:Get())endlocal function canattack(inst)return (inst.components.sanity.current >= 50)endlocal function onattack(inst, owner, target)--Check sanityif not canattack(owner) thenif owner.components.talker thenowner.components.talker:Say(GetString(owner.prefab, "Could_it_be_MY_Hat_is_FREE)"))return trueendend--Check reagentif not owner.components.inventory:Has("petals", TUNING.SHADOWWAXWELL_FUEL_COST) thenif owner.components.talker thenowner.components.talker:Say(GetString(owner.prefab, "ANNOUNCE_NOFUEL"))return trueendendowner.components.inventory:ConsumeByName("petals", TUNING.SHADOWWAXWELL_FUEL_COST * 5)--Ok you had everything. Make the image.local theta = math.random() * 2 * PIlocal pt = inst:GetPosition()local radius = math.random(3, 6)local offset = FindWalkableOffset(pt, theta, radius, 12, true)if offset thenlocal image = SpawnPrefab("pigman")local pos = pt + offsetimage.Transform:SetPosition(pos:Get())doeffects(inst, pos)owner.components.sanity:DoDelta(-TUNING.SANITY_TINY * 10)inst.SoundEmitter:PlaySound("dontstarve/maxwell/shadowmax_appear")return trueendendlocal function OnEquip(inst, owner)owner.AnimState:OverrideSymbol("swap_object", "swap_pighat", "swap_pighat")owner.AnimState:Show("ARM_carry")owner.AnimState:Hide("ARM_normal")endlocal function OnUnequip(inst, owner)owner.AnimState:Hide("ARM_carry")owner.AnimState:Show("ARM_normal")endlocal function fn()local inst = CreateEntity()local trans = inst.entity:AddTransform()local anim = inst.entity:AddAnimState()local sound = inst.entity:AddSoundEmitter()MakeInventoryPhysics(inst)anim:SetBank("pighat")anim:SetBuild("pighat")anim:PlayAnimation("idle")local minimap = inst.entity:AddMiniMapEntity()minimap:SetIcon("pighat.png")inst:AddComponent("inspectable")inst:AddComponent("inventoryitem")inst.components.inventoryitem.imagename = "pighat"inst.components.inventoryitem.atlasname = "images/inventoryimages/pighat.xml"inst:AddComponent("equippable")inst.components.equippable:SetOnEquip( OnEquip )inst.components.equippable:SetOnUnequip( OnUnequip )--Shovel with your hatinst:AddComponent("tool")inst.components.tool:SetAction(ACTIONS.DIG)inst:AddInherentAction(ACTIONS.DIG)---inst:AddTag("sharp")inst:AddComponent("weapon")inst.components.weapon:SetDamage(250)inst.components.weapon:SetOnAttack(onattack)return instendreturn Prefab("common/inventory/pighat", fn, assets) Link to comment https://forums.kleientertainment.com/forums/topic/47457-help-with-sanity-check-onattack/#findComment-592389 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