heckmate Posted October 29, 2018 Share Posted October 29, 2018 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! Link to comment https://forums.kleientertainment.com/forums/topic/97696-need-help-with-custom-character-item/ Share on other sites More sharing options...
K1NGT1GER609 Posted October 29, 2018 Share Posted October 29, 2018 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. Link to comment https://forums.kleientertainment.com/forums/topic/97696-need-help-with-custom-character-item/#findComment-1105825 Share on other sites More sharing options...
heckmate Posted October 29, 2018 Author Share Posted October 29, 2018 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! Link to comment https://forums.kleientertainment.com/forums/topic/97696-need-help-with-custom-character-item/#findComment-1106040 Share on other sites More sharing options...
heckmate Posted October 31, 2018 Author Share Posted October 31, 2018 Hi again, I've run into a problem. I'm not really sure how to declare a variable; a lot of my crashes are caused by undeclared variables (i.e. "variable light prefab not declared.") Is there a way to declare that? Link to comment https://forums.kleientertainment.com/forums/topic/97696-need-help-with-custom-character-item/#findComment-1106732 Share on other sites More sharing options...
K1NGT1GER609 Posted October 31, 2018 Share Posted October 31, 2018 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 Link to comment https://forums.kleientertainment.com/forums/topic/97696-need-help-with-custom-character-item/#findComment-1107008 Share on other sites More sharing options...
heckmate Posted October 31, 2018 Author Share Posted October 31, 2018 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!!!! Link to comment https://forums.kleientertainment.com/forums/topic/97696-need-help-with-custom-character-item/#findComment-1107137 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