Jump to content

Recommended Posts

Hello,

so I'd like to preface this by saying: I'm a very novice coder. This is my first mod, and the first time I've ever really gotten to dabble in coding.

Disclaimer aside, I've finally gotten my custom character mod to work without crashing. I would really like to give him a staff that, when used over a character, gives that character a glow effect for a short amount of time (exactly like eating a glowberry). I'd also like it if, when he uses the staff, it takes away a good chunk of his sanity (a "large" chunk maybe?)

Here's what I've done so far

-Downloaded this staff template

-I'm not sure how to say this but I've... specified the wand in the mod main as a prefab? If that makes any sense.

That's about it. Right now my goal is to specify what the wand actually does (the light effect) and to have it drain sanity upon use. If anyone could point me in the right direction, that would be great. Thanks so much in advance! 

The spell caster component is a bit demanding for a lack of better words but for the most part but ill give a example for how it should work:

local function playerlightcaster(inst, target, lightprefab)
    
    if target and not target:HasTag("player") then --maybe an exception (players only) so you won't crash
    return
    end
    
    local caster = inst.components.inventoryitem.owner or target
    if target == nil then
        target = caster
    end

 -- if eater.wormlight ~= nil then --might be needed as its from wormlight lua
        -- if eater.wormlight.prefab == lightprefab then
            -- eater.wormlight.components.spell.lifetime = 0
            -- eater.wormlight.components.spell:ResumeSpell()
            -- return
        -- else
            -- eater.wormlight.components.spell:OnFinish()
        -- end
    -- end    


    if target and target:HasTag("player")  then
local light = SpawnPrefab(lightprefab)
    light.components.spell:SetTarget(target)
    if light:IsValid() then
        if light.components.spell.target == nil then
            light:Remove()
        else
            light.components.spell:StartSpell()
        end
    end

    end
    
    if caster ~= nil and caster.components.sanity ~= nil then
        caster.components.sanity:DoDelta(-40)
    end
end

 

local function fnab()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    inst.entity:AddNetwork()
    
    inst.AnimState:SetBank("pulltwo")
    inst.AnimState:SetBuild("pulltwo")
    inst.AnimState:PlayAnimation("idle")
    
    inst:AddComponent("reticule")
    inst.components.reticule.ease = true
    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
    
    inst:AddComponent("inspectable")
        
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/pulltwo.xml"
    
    inst.fxcolour = {104/255,40/255,121/255}
    inst:AddComponent("spellcaster")
    inst.components.spellcaster:SetSpellFn(playerlightcaster)
    inst.components.spellcaster.canuseontargets = true
    inst.components.spellcaster.canusefrominventory = false
    inst.components.spellcaster.canonlyuseonlocomotors = true
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
    
    return inst
end

whether it works or not it should give a decent idea of how to use the spell caster for a staff.

4 hours ago, K1NGT1GER609 said:

The spell caster component is a bit demanding for a lack of better words but for the most part but ill give a example for how it should work:

local function playerlightcaster(inst, target, lightprefab)
    
    if target and not target:HasTag("player") then --maybe an exception (players only) so you won't crash
    return
    end
    
    local caster = inst.components.inventoryitem.owner or target
    if target == nil then
        target = caster
    end

 -- if eater.wormlight ~= nil then --might be needed as its from wormlight lua
        -- if eater.wormlight.prefab == lightprefab then
            -- eater.wormlight.components.spell.lifetime = 0
            -- eater.wormlight.components.spell:ResumeSpell()
            -- return
        -- else
            -- eater.wormlight.components.spell:OnFinish()
        -- end
    -- end    


    if target and target:HasTag("player")  then
local light = SpawnPrefab(lightprefab)
    light.components.spell:SetTarget(target)
    if light:IsValid() then
        if light.components.spell.target == nil then
            light:Remove()
        else
            light.components.spell:StartSpell()
        end
    end

    end
    
    if caster ~= nil and caster.components.sanity ~= nil then
        caster.components.sanity:DoDelta(-40)
    end
end

 

local function fnab()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    inst.entity:AddNetwork()
    
    inst.AnimState:SetBank("pulltwo")
    inst.AnimState:SetBuild("pulltwo")
    inst.AnimState:PlayAnimation("idle")
    
    inst:AddComponent("reticule")
    inst.components.reticule.ease = true
    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
    
    inst:AddComponent("inspectable")
        
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/pulltwo.xml"
    
    inst.fxcolour = {104/255,40/255,121/255}
    inst:AddComponent("spellcaster")
    inst.components.spellcaster:SetSpellFn(playerlightcaster)
    inst.components.spellcaster.canuseontargets = true
    inst.components.spellcaster.canusefrominventory = false
    inst.components.spellcaster.canonlyuseonlocomotors = true
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
    
    return inst
end

whether it works or not it should give a decent idea of how to use the spell caster for a staff.

This is fantastic, thank you so much!!!! I’ll have to play around with this and see if I can get it to work!

Heh dam I was hoping that I'd get it right without testing it at this point but here this one works like you ate a glowberry (lasts 90 seconds):

local prefabs = 
{
"wormlight_light",
}

local function playerlightcaster(inst, target)
    
    if target and not target:HasTag("player") then --players only, who know what happens to mobs?
    return
    end


    if target and target:HasTag("player")  then
local light = SpawnPrefab("wormlight_light")
    light.components.spell:SetTarget(target)
    if light:IsValid() then
        if light.components.spell.target == nil then
            light:Remove()
        else
            light.components.spell:StartSpell()
        end
    end

    end
    
    local caster = inst.components.inventoryitem.owner or target
    if target == nil then
        target = caster
    end
    

    if caster ~= nil and caster.components.sanity ~= nil then
        caster.components.sanity:DoDelta(-40) --customizable number 
    end
end

 

4 hours ago, K1NGT1GER609 said:

Heh dam I was hoping that I'd get it right without testing it at this point but here this one works like you ate a glowberry (lasts 90 seconds):

local prefabs = 
{
"wormlight_light",
}

local function playerlightcaster(inst, target)
    
    if target and not target:HasTag("player") then --players only, who know what happens to mobs?
    return
    end


    if target and target:HasTag("player")  then
local light = SpawnPrefab("wormlight_light")
    light.components.spell:SetTarget(target)
    if light:IsValid() then
        if light.components.spell.target == nil then
            light:Remove()
        else
            light.components.spell:StartSpell()
        end
    end

    end
    
    local caster = inst.components.inventoryitem.owner or target
    if target == nil then
        target = caster
    end
    

    if caster ~= nil and caster.components.sanity ~= nil then
        caster.components.sanity:DoDelta(-40) --customizable number 
    end
end

 

THANK YOU SO MUCH!!! I just tested it and it worked like a charm!!! :'D Sanity drain and light effect work! You're awesome!!!!

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