Jump to content

Spellcaster Function not being Called


Recommended Posts

So I've been trying to give the ice and fire staves a secondary attack; basically the AoE ice/fire attack the no-eyed deer performs during Klaus. I've looked at the code for the meteor and healing staff from The Forge as well as a few examples from the workshop and I hacked together this.

local SpawnPrefab = GLOBAL.SpawnPrefab
local TUNING = GLOBAL.TUNING

AddPrefabPostInit("icestaff", function(inst)

    local function oncastfn(inst, doer, pos) -- the function that is supposed to be called but isn't
        local spell = SpawnPrefab("deer_ice_circle")
        spell.Transform:SetPosition(pos.x, pos.y, pos.z)
        print("Cast Attempt.")
    end

    inst:AddComponent("aoetargeting") -- gets a circle to show up like the meteor staff and the healing staff in the Forge.
    inst.components.aoetargeting.reticule.reticuleprefab = "reticuleaoe"
    inst.components.aoetargeting.reticule.pingprefab = "reticuleaoeping"
    inst.components.aoetargeting.reticule.targetfn = ReticuleTargetFn
    inst.components.aoetargeting.reticule.validcolour = { 1, .75, 0, 1 }
    inst.components.aoetargeting.reticule.invalidcolour = { .5, 0, 0, 1 }
    inst.components.aoetargeting.reticule.ease = true
    inst.components.aoetargeting.reticule.mouseenabled = true

    inst:AddComponent("spellcaster") -- actually makes the staff into a spellcaster. that small ice projectile thingy is not a spell.
    inst.components.spellcaster:SetSpellFn(oncastfn) -- defines the function to be called upon right click cast. i think.
    inst.components.spellcaster.canusefrominventory = true
    inst.entity:SetPristine()

end)

The game doesn't crash upon loading the mod, so there's that I suppose. When I right click, the "aoetargeting" circle shows up, but when I left click, nothing happens. The circle is still there, as if I never clicked anything. It leads me to believe that no function was called instead of the function being called and nothing happening, right?

 

Why is this happening?

Thanks in advance.

Link to comment
Share on other sites

On 1.12.2018 at 11:45 PM, RatherAzure said:

So I've been trying to give the ice and fire staves a secondary attack; basically the AoE ice/fire attack the no-eyed deer performs during Klaus. I've looked at the code for the meteor and healing staff from The Forge as well as a few examples from the workshop and I hacked together this.


local SpawnPrefab = GLOBAL.SpawnPrefab
local TUNING = GLOBAL.TUNING

AddPrefabPostInit("icestaff", function(inst)

    local function oncastfn(inst, doer, pos) -- the function that is supposed to be called but isn't
        local spell = SpawnPrefab("deer_ice_circle")
        spell.Transform:SetPosition(pos.x, pos.y, pos.z)
        print("Cast Attempt.")
    end

    inst:AddComponent("aoetargeting") -- gets a circle to show up like the meteor staff and the healing staff in the Forge.
    inst.components.aoetargeting.reticule.reticuleprefab = "reticuleaoe"
    inst.components.aoetargeting.reticule.pingprefab = "reticuleaoeping"
    inst.components.aoetargeting.reticule.targetfn = ReticuleTargetFn
    inst.components.aoetargeting.reticule.validcolour = { 1, .75, 0, 1 }
    inst.components.aoetargeting.reticule.invalidcolour = { .5, 0, 0, 1 }
    inst.components.aoetargeting.reticule.ease = true
    inst.components.aoetargeting.reticule.mouseenabled = true

    inst:AddComponent("spellcaster") -- actually makes the staff into a spellcaster. that small ice projectile thingy is not a spell.
    inst.components.spellcaster:SetSpellFn(oncastfn) -- defines the function to be called upon right click cast. i think.
    inst.components.spellcaster.canusefrominventory = true
    inst.entity:SetPristine()

end)

The game doesn't crash upon loading the mod, so there's that I suppose. When I right click, the "aoetargeting" circle shows up, but when I left click, nothing happens. The circle is still there, as if I never clicked anything. It leads me to believe that no function was called instead of the function being called and nothing happening, right?

 

Why is this happening?

Thanks in advance.

Try this

 

Spoiler

AddPrefabPostInit("icestaff",  function (inst)
if GLOBAL.TheWorld.ismastersim then


inst:AddComponent("spellcaster")    
    inst.components.spellcaster.CanCast = (function (inst, target, pos)
        return true
    end)
    inst.components.spellcaster:SetSpellFn((function (inst, target, pos) 
    local caster = inst.components.inventoryitem.owner
                    
                    if pos~=nil then --the point on map that has been targeted to cast spell there
                        --put a spell effect here                        
                    end    
                                        
    end))
    inst.components.spellcaster.canuseontargets = true --retains the default functionality of ice staff
    inst.components.spellcaster.canuseonpoint = true  --adds aoe spell
end    
end )

 

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...