dnjswns951 Posted December 12, 2014 Share Posted December 12, 2014 I just want to change the color of the forcefield for my mod character. for example, when my mod character gets hit by a monster, my mod hat creates the forcefield around. I want to change that color to bluish color.local assets={ Asset("ANIM", "anim/hat_fox.zip"), Asset("ATLAS", "images/inventoryimages/hat_fox.xml")}local function ruinshat_proc(inst, owner) inst:AddTag("forcefield") inst.components.armor:SetAbsorption(TUNING.FULL_ABSORPTION) local fx = SpawnPrefab("scripts/prefabs/forcefieldfx_blue") fx.entity:SetParent(owner.entity) fx.Transform:SetPosition(0, 0.2, 0) local fx_hitanim = function() fx.AnimState:PlayAnimation("hit") fx.AnimState:PushAnimation("idle_loop") end fx:ListenForEvent("blocked", fx_hitanim, owner) inst.components.armor.ontakedamage = function(inst, damage_amount) if owner then local sanity = owner.components.sanity if sanity then local unsaneness = damage_amount * TUNING.ARMOR_RUINSHAT_DMG_AS_SANITY sanity:DoDelta(-unsaneness, false) end end end inst.active = true owner:DoTaskInTime(--[[Duration]] TUNING.ARMOR_RUINSHAT_DURATION, function() fx:RemoveEventCallback("blocked", fx_hitanim, owner) fx.kill_fx(fx) if inst:IsValid() then inst:RemoveTag("forcefield") inst.components.armor.ontakedamage = nil inst.components.armor:SetAbsorption(TUNING.ARMOR_RUINSHAT_ABSORPTION) owner:DoTaskInTime(--[[Cooldown]] TUNING.ARMOR_RUINSHAT_COOLDOWN, function() inst.active = false end) end end)endlocal function tryproc(inst, owner) if not inst.active and math.random() < --[[ Chance to proc ]] TUNING.ARMOR_RUINSHAT_PROC_CHANCE then ruinshat_proc(inst, owner) endendlocal function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_hat", "hat_fox", "swap_hat") owner.AnimState:Show("HAT") owner.AnimState:Show("HAT_HAIR") owner.AnimState:Hide("HAIR_NOHAT") owner.AnimState:Hide("HAIR") owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAIR") inst.procfn = function() tryproc(inst, owner) end owner:ListenForEvent("attacked", inst.procfn)endlocal function onunequip(inst, owner) owner.AnimState:Hide("HAT") owner.AnimState:Hide("HAT_HAIR") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAIR") end owner:RemoveEventCallback("attacked", inst.procfn)endlocal function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() MakeInventoryPhysics(inst) inst:AddTag("hat") anim:SetBank("featherhat") anim:SetBuild("hat_fox") anim:PlayAnimation("anim") inst:AddComponent("inspectable") inst:AddTag("irreplaceable") inst:AddComponent("armor") inst.components.armor:InitCondition(TUNING.ARMOR_RUINSHAT, TUNING.ARMOR_RUINSHAT_ABSORPTION) --inst.components.armor:SetAbsorption(0) --inst.components.armor:SetCondition(100) inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/hat_fox.xml" inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.HEAD inst.components.equippable:SetOnEquip( onequip ) inst.components.equippable:SetOnUnequip( onunequip ) return instendreturn Prefab( "common/inventory/hat_fox", fn, assets) this is the code for my mod character's hat, andlocal assets = { Asset("ANIM", "anim/forcefield_blue.zip")}local function kill_fx(inst) inst.AnimState:PlayAnimation("close") inst.components.lighttweener:StartTween(nil, 0, .9, 0.9, nil, .2) inst:DoTaskInTime(0.6, function() inst:Remove() end) endlocal function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() anim:SetBank("forcefield") anim:SetBuild("forcefield_blue") anim:PlayAnimation("open") anim:PushAnimation("idle_loop", true) inst:AddComponent("lighttweener") local light = inst.entity:AddLight() inst.components.lighttweener:StartTween(light, 0, .9, 0.9, {1,1,1}, 0) inst.components.lighttweener:StartTween(nil, 3, .9, 0.9, nil, .2) inst.kill_fx = kill_fx sound:PlaySound("dontstarve/wilson/forcefield_LP", "loop") return instendreturn Prefab( "common/forcefieldfx_blue", fn, assets) and this is my lua file in my mod folder. when I try this, I got an error message saying "attempt index nil value ( fx) in line 11. Does anyone know how to do it? Link to comment https://forums.kleientertainment.com/forums/topic/46162-i-am-trying-to-change-the-color-of-the-forcefield-can-anyone-help-me/ Share on other sites More sharing options...
rezecib Posted December 13, 2014 Share Posted December 13, 2014 @dnjswns951, SpawnPrefab("scripts/prefabs/forcefieldfx_blue") should be SpawnPrefab("forcefieldfx_blue") But a nicer way to do this would probably be to use AnimState:SetAddColour(0,0,1,1) (the arguments are R, G, B, Alpha). This way you could vary the color more flexibly, although given the base color of red you won't have a full range of color. But this is the method by which pinecones become green when you're placing them, for example. Link to comment https://forums.kleientertainment.com/forums/topic/46162-i-am-trying-to-change-the-color-of-the-forcefield-can-anyone-help-me/#findComment-584638 Share on other sites More sharing options...
dnjswns951 Posted December 13, 2014 Author Share Posted December 13, 2014 @dnjswns951, SpawnPrefab("scripts/prefabs/forcefieldfx_blue") should be SpawnPrefab("forcefieldfx_blue") But a nicer way to do this would probably be to use AnimState:SetAddColour(0,0,1,1) (the arguments are R, G, B, Alpha). This way you could vary the color more flexibly, although given the base color of red you won't have a full range of color. But this is the method by which pinecones become green when you're placing them, for example.THANK YOU SO MUCH!! it works perfectly!! Link to comment https://forums.kleientertainment.com/forums/topic/46162-i-am-trying-to-change-the-color-of-the-forcefield-can-anyone-help-me/#findComment-584905 Share on other sites More sharing options...
chromiumboy Posted December 15, 2014 Share Posted December 15, 2014 You can combine this with the "colourtweener" component for more flexibility with your colouring. Link to comment https://forums.kleientertainment.com/forums/topic/46162-i-am-trying-to-change-the-color-of-the-forcefield-can-anyone-help-me/#findComment-586044 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