Jump to content

Help with Sanity Check onattack


dungdodger

Recommended Posts

	                  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    end

as 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
Share on other sites

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

local function canattack(inst)
return (inst.components.sanity.current >= 50)
end

local function onattack(inst, owner, target)

--Check sanity
if not canattack(owner) then
if owner.components.talker then
owner.components.talker:Say(GetString(owner.prefab, "Could_it_be_MY_Hat_is_FREE)"))
return true
end
end

--Check reagent
if not owner.components.inventory:Has("petals", TUNING.SHADOWWAXWELL_FUEL_COST) then
if owner.components.talker then
owner.components.talker:Say(GetString(owner.prefab, "ANNOUNCE_NOFUEL"))
return true
end
end

owner.components.inventory:ConsumeByName("petals", TUNING.SHADOWWAXWELL_FUEL_COST * 5)

--Ok you had everything. Make the image.

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)

owner.components.sanity:DoDelta(-TUNING.SANITY_TINY * 10)

inst.SoundEmitter:PlaySound("dontstarve/maxwell/shadowmax_appear")
return true
end
end

local function OnEquip(inst, owner)
owner.AnimState:OverrideSymbol("swap_object", "swap_pighat", "swap_pighat")
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()
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 hat
inst: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 inst
end
return Prefab("common/inventory/pighat", fn, assets)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...