Feything Posted August 30, 2015 Share Posted August 30, 2015 Hi, I've been wanting to make it so that a couple of characters are able to toggle and switch on and off a forcefield shield. So far I was able to make it so that they can activate and spawn the forcefieldfx when pressing a key in the game without a problem. But when I try to turn off or remove the forcefieldfx, instead of removing the effect. I end up getting another forcefieldfx stacking on top of the one I toggled.local function Shielding(player) if player.Light:IsEnabled() then player.Light:Enable(false) player:RemoveTag("forcefield") player.kill_fx = ("forcefieldfx") player.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-2) player.components.sanity.night_drain_mult = 2 player.components.health.absorb = (0) player.components.combat.damagemultiplier = .75 player.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * .2) player.components.locomotor.walkspeed = 5 player.components.locomotor.runspeed = 7 player.sg:PushEvent("powerdown") player.SoundEmitter:PlaySound("dontstarve/creatures/bishop/charge") player.AnimState:ClearBloomEffectHandle() player.task:Cancel() else player.Light:Enable(true) player:AddTag("forcefield") local fx = GLOBAL.SpawnPrefab("forcefieldfx") fx.entity:SetParent(player.entity) fx.Transform:SetPosition(0, 0.2, 0) player.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-5) player.components.sanity.night_drain_mult = 3 player.components.health.absorb = (1) player.components.combat.damagemultiplier = .25 player.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 10) player.components.locomotor.walkspeed = 5 player.components.locomotor.runspeed = 7 player.AnimState:SetBloomEffectHandle("shaders/anim.ksh") player.sg:PushEvent("powerup") player.SoundEmitter:PlaySound("dontstarve/creatures/bishop/shoot") player.components.talker:Say("Activating Shields!") player.task = player:DoPeriodicTask(1, function(inst) inst.Light:SetRadius(3) if inst.components.hunger.current < 1 then inst.components.health:DoDelta(-0.5) end end)endend AddModRPCHandler(modname, "Shielding", Shielding) GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_Z, function()local player=GLOBAL.ThePlayerif player and player.prefab=="nefarious" and not GLOBAL.IsPaused() and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_CTRL) and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_SHIFT) and not player.HUD:IsChatInputScreenOpen() and not player.HUD:IsConsoleScreenOpen()then SendModRPCToServer(MOD_RPC[modname]["Shielding"])endend) Link to comment Share on other sites More sharing options...
DarkXero Posted August 31, 2015 Share Posted August 31, 2015 @RoboticMasterMind, here you go:local function Shielding(player) if player.prefab == "nefarious" then -- Check so non nefarious players cant cheat with RPCs for free shielding if player.shielding then -- Use shielding variable so we don't depend on light player.shielding = nil player.Light:Enable(false) player:RemoveTag("forcefield") player.forcefieldfx:kill_fx() -- This is how we access the kill_fx method of the forcefieldfx prefab player.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-2) player.components.sanity.night_drain_mult = 2 player.components.health.absorb = (0) player.components.combat.damagemultiplier = .75 player.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * .2) player.components.locomotor.walkspeed = 5 player.components.locomotor.runspeed = 7 player.sg:GoToState("powerdown") -- Changed this so it goes directly to state without waiting for idle anims to end player.SoundEmitter:PlaySound("dontstarve/creatures/bishop/charge") player.AnimState:ClearBloomEffectHandle() player.task:Cancel() else player.shielding = true player.Light:Enable(true) player.Light:SetRadius(3) -- No need to setup it constantly in the task player:AddTag("forcefield") player.forcefieldfx = GLOBAL.SpawnPrefab("forcefieldfx") -- "Attach" the fx to the player player.forcefieldfx.entity:SetParent(player.entity) -- So we don't have to loop through the children to find it later to kill it player.forcefieldfx.Transform:SetPosition(0, 0.2, 0) player.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-5) player.components.sanity.night_drain_mult = 3 player.components.health.absorb = (1) player.components.combat.damagemultiplier = .25 player.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 10) player.components.locomotor.walkspeed = 5 player.components.locomotor.runspeed = 7 player.AnimState:SetBloomEffectHandle("shaders/anim.ksh") player.sg:GoToState("powerup") -- Changed this so it goes directly to state without waiting for idle anims to end player.SoundEmitter:PlaySound("dontstarve/creatures/bishop/shoot") player.components.talker:Say("Activating Shields!") player.task = player:DoPeriodicTask(1, function(inst) if inst.components.hunger.current < 1 then inst.components.health:DoDelta(-0.5) end end) end endendAddModRPCHandler(modname, "Shielding", Shielding) GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_Z, function() local player = GLOBAL.ThePlayer local noextrakeys = not GLOBAL.IsPaused() and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_CTRL) and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_SHIFT) local nochatorcon = not player.HUD:IsChatInputScreenOpen() and not player.HUD:IsConsoleScreenOpen() if player and player.prefab == "nefarious" and noextrakeys and nochatorcon then SendModRPCToServer(MOD_RPC[modname]["Shielding"]) endend) Link to comment Share on other sites More sharing options...
Feything Posted August 31, 2015 Author Share Posted August 31, 2015 @RoboticMasterMind, here you go:local function Shielding(player) if player.prefab == "nefarious" then -- Check so non nefarious players cant cheat with RPCs for free shielding if player.shielding then -- Use shielding variable so we don't depend on light player.shielding = nil player.Light:Enable(false) player:RemoveTag("forcefield") player.forcefieldfx:kill_fx() -- This is how we access the kill_fx method of the forcefieldfx prefab player.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-2) player.components.sanity.night_drain_mult = 2 player.components.health.absorb = (0) player.components.combat.damagemultiplier = .75 player.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * .2) player.components.locomotor.walkspeed = 5 player.components.locomotor.runspeed = 7 player.sg:GoToState("powerdown") -- Changed this so it goes directly to state without waiting for idle anims to end player.SoundEmitter:PlaySound("dontstarve/creatures/bishop/charge") player.AnimState:ClearBloomEffectHandle() player.task:Cancel() else player.shielding = true player.Light:Enable(true) player.Light:SetRadius(3) -- No need to setup it constantly in the task player:AddTag("forcefield") player.forcefieldfx = GLOBAL.SpawnPrefab("forcefieldfx") -- "Attach" the fx to the player player.forcefieldfx.entity:SetParent(player.entity) -- So we don't have to loop through the children to find it later to kill it player.forcefieldfx.Transform:SetPosition(0, 0.2, 0) player.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-5) player.components.sanity.night_drain_mult = 3 player.components.health.absorb = (1) player.components.combat.damagemultiplier = .25 player.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 10) player.components.locomotor.walkspeed = 5 player.components.locomotor.runspeed = 7 player.AnimState:SetBloomEffectHandle("shaders/anim.ksh") player.sg:GoToState("powerup") -- Changed this so it goes directly to state without waiting for idle anims to end player.SoundEmitter:PlaySound("dontstarve/creatures/bishop/shoot") player.components.talker:Say("Activating Shields!") player.task = player:DoPeriodicTask(1, function(inst) if inst.components.hunger.current < 1 then inst.components.health:DoDelta(-0.5) end end) end endendAddModRPCHandler(modname, "Shielding", Shielding) GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_Z, function() local player = GLOBAL.ThePlayer local noextrakeys = not GLOBAL.IsPaused() and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_CTRL) and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_SHIFT) local nochatorcon = not player.HUD:IsChatInputScreenOpen() and not player.HUD:IsConsoleScreenOpen() if player and player.prefab == "nefarious" and noextrakeys and nochatorcon then SendModRPCToServer(MOD_RPC[modname]["Shielding"]) endend) Thank you so much, it works! ^^ Link to comment 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