rons0n Posted April 5, 2015 Share Posted April 5, 2015 (edited) So I was just trying to make my character transform into a psycho after losing a certain amount of sanity. Its working flawlessly! Except two things: - I can't see her ghost(invisible)- Adding inst.entity.AddLight() on her 'local function becomearc(inst)' does nothing. I mostly just want the ghost fixed, but the glow fixed would also be grand!local MakePlayerCharacter = require "prefabs/player_common"local assets = { Asset( "ANIM", "anim/player_basic.zip" ), Asset( "ANIM", "anim/player_idles_shiver.zip" ), Asset( "ANIM", "anim/player_actions.zip" ), Asset( "ANIM", "anim/player_actions_axe.zip" ), Asset( "ANIM", "anim/player_actions_pickaxe.zip" ), Asset( "ANIM", "anim/player_actions_shovel.zip" ), Asset( "ANIM", "anim/player_actions_blowdart.zip" ), Asset( "ANIM", "anim/player_actions_eat.zip" ), Asset( "ANIM", "anim/player_actions_item.zip" ), Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ), Asset( "ANIM", "anim/player_actions_bugnet.zip" ), Asset( "ANIM", "anim/player_actions_fishing.zip" ), Asset( "ANIM", "anim/player_actions_boomerang.zip" ), Asset( "ANIM", "anim/player_bush_hat.zip" ), Asset( "ANIM", "anim/player_attacks.zip" ), Asset( "ANIM", "anim/player_idles.zip" ), Asset( "ANIM", "anim/player_rebirth.zip" ), Asset( "ANIM", "anim/player_jump.zip" ), Asset( "ANIM", "anim/player_amulet_resurrect.zip" ), Asset( "ANIM", "anim/player_teleport.zip" ), Asset( "ANIM", "anim/wilson_fx.zip" ), Asset( "ANIM", "anim/player_one_man_band.zip" ), Asset( "ANIM", "anim/shadow_hands.zip" ), Asset( "SOUND", "sound/sfx.fsb" ), Asset( "SOUND", "sound/wilson.fsb" ), Asset( "ANIM", "anim/beard.zip" ), Asset( "ANIM", "anim/arc.zip" ), Asset( "ANIM", "anim/ghost_arc_build.zip" ), Asset( "ANIM", "anim/arcBL.zip"),}local prefabs = {}local start_inv = { -- Custom starting items "arcwand", "meat", "meat", "meat", "meat",}-- This initializes for both clients and the hostlocal common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "arc.tex" )endlocal function applyForm(inst) if inst.form == "demonic" then inst.AnimState:SetBuild("arcBL") inst.components.combat.damagemultiplier = 1 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE) inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0.30 inst.components.sanity.night_drain_mult = 1.2 inst.components.sanity.neg_aura_mult = 1.2 inst:AddTag("insomniac") end if inst.form == "normal" then inst.AnimState:SetBuild("arc") inst.components.combat.damagemultiplier = 0.75 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 3) inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED * 1.25 inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * 1.25 inst.components.health.absorb = 0 inst.components.sanity.night_drain_mult = 0 inst.components.sanity.neg_aura_mult = 2 inst:RemoveTag("insomniac") end endlocal function becomenormal(inst, silent) if inst.form == "normal" then return end inst.form = "normal"endlocal function becomedemonic(inst, silent) if inst.form == "demonic" then return end inst.form = "demonic"endlocal function onsanitychange(inst, data, forcesilent) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end local silent = inst.sg:HasStateTag("silentmorph") or not inst.entity:IsVisible() or forcesilent if inst.form == "demonic" then if inst.components.sanity.current > (50) then becomenormal(inst, silent) end elseif inst.form == "normal" then if inst.components.sanity.current < (25) then becomedemonic(inst, silent) end end applyForm(inst)endlocal function onnewstate(inst) if inst._wasnomorph ~= inst.sg:HasStateTag("nomorph") then inst._wasnomorph = not inst._wasnomorph if not inst._wasnomorph then onsanitychange(inst) end endendlocal function onbecameghost(inst) if inst._wasnomorph ~= nil then inst.form = "normal" inst._wasnomorph = nil inst.talksoundoverride = nil inst.hurtsoundoverride = nil inst:RemoveEventCallback("sanitydelta", onsanitychange) inst:RemoveEventCallback("newstate", onnewstate) endendlocal function onbecamehuman(inst) if inst._wasnomorph == nil then inst.form = "normal" inst._wasnomorph = inst.sg:HasStateTag("nomorph") inst.talksoundoverride = nil inst.hurtsoundoverride = nil inst:ListenForEvent("sanitydelta", onsanitychange) inst:ListenForEvent("newstate", onnewstate) onsanitychange(inst, nil, true) end endlocal smallScale = 0.5local medScale = 0.7local largeScale = 1.1local function onkilled(inst, data) local victim = data.victim if not (victim:HasTag("prey") or victim:HasTag("veggie") or victim:HasTag("structure")) then local delta = victim.components.combat.defaultdamage * 0.25 inst.components.health:DoDelta(delta, false, "battleborn") inst.components.sanity:DoDelta(delta) if not victim.components.health.nofadeout and (victim:HasTag("epic") or math.random() < .1) then local time = victim.components.health.destroytime or 2 local x, y, z = victim.Transform:GetWorldPosition() local scale = (victim:HasTag("smallcreature") and smallScale) or (victim:HasTag("largecreature") and largeScale) or medScale end endendlocal function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) inst:ListenForEvent("killed", onkilled) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end-- This initializes for the host onlylocal master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "willow" -- Stats inst.components.health:SetMaxHealth(125) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(200) inst.form = "normal" inst._wasnomorph = nil inst.talksoundoverride = nil inst.hurtsoundoverride = nil local eater = inst.components.eater eater.ignoresspoilage = true inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) inst.components.eater.Eat_orig = inst.components.eater.Eatfunction inst.components.eater:Eat( food ) if self:CanEat(food) then if food.components.edible.sanityvalue < 0 then food.components.edible.sanityvalue = 1 end if food.components.edible.healthvalue < 0 then food.components.edible.healthvalue = 3 endendreturn inst.components.eater:Eat_orig(food)end inst.OnLoad = onload inst.OnNewSpawn = onloadendreturn MakePlayerCharacter("arc", prefabs, assets, common_postinit, master_postinit, start_inv) Edit: Well it took me all day but I found it. I placed the inst.AnimState:SetBuild in the completely wrong part of the code. What a derp I am. Edited April 5, 2015 by rons0n Link to comment Share on other sites More sharing options...
rons0n Posted April 6, 2015 Author Share Posted April 6, 2015 Sorry for bumping an already self-answered thread but since my next question kinda relates to this one I decided to bump it. Anyway, does anyone know how to make it so my character slowly drains her HP on transformation? (And of course, stops draining HP when reverting back to normal?) Anything would be nice, thanks! Link to comment Share on other sites More sharing options...
DarkXero Posted April 7, 2015 Share Posted April 7, 2015 (edited) -- in applyForm -- on becoming a demon inst.demontask = inst:DoPeriodicTask(2, function() if inst.components.health then inst.components.health:DoDelta(-1, true, "Curse") end end) -- on becoming normal, by dying or reverting if inst.demontask then inst.demontask:Cancel() inst.demontask = nil end Edited April 7, 2015 by DarkXero Link to comment Share on other sites More sharing options...
rons0n Posted April 7, 2015 Author Share Posted April 7, 2015 (edited) -- in applyForm-- on becoming a demoninst.demontask = inst:DoPeriodicTask(2, function() if inst.components.health then inst.components.health:DoDelta(-1, true, "Curse") endend-- on becoming normal, by dying or revertingif inst.demontask then inst.demontask:Cancel() inst.demontask = nilend You're a miracle worker DarkXero . Thanks! Edited April 7, 2015 by rons0n Link to comment Share on other sites More sharing options...
rons0n Posted April 7, 2015 Author Share Posted April 7, 2015 (edited) @DarkXero I know I said everything worked well, but it worked a bit TOO well. So the code you provided drains the living life out of my character(Literally!) So I changed the DoDelta(-1) to other digits and even though it did work, the health meter gradually got faster...and faster...and faster to a quick and hasty spiral to my death. How can I change the hunger on a set pace rather it going faster and faster as time goes by? Edited April 7, 2015 by rons0n Link to comment Share on other sites More sharing options...
DarkXero Posted April 7, 2015 Share Posted April 7, 2015 @rons0n, Well, I don't know how fast do you want to lose health. Wilson's freezing health damage is, more or less:inst.demontask = inst:DoPeriodicTask(0.03, function() if inst.components.health then inst.components.health:DoDelta(-0.0375, true, "Curse") endendThe only character where hunger rates vary is Wolfgang, it goes down faster when mighty, slower when wimpy.Wilson, the default, has a constant hunger rate, so he loses hunger on a set pace.Or maybe do you mean you want to change it to faster and faster as time goes by? Link to comment Share on other sites More sharing options...
rons0n Posted April 7, 2015 Author Share Posted April 7, 2015 (edited) @DarkXero, Sorry I should've clarified. As time goes by my health depletion doubles. So like every second instead of losing 2 hp per second, it would go 4 hp per second, then 8 hp per second, etc But I want it to have a set pace. Maybe its because I added a closing parenthesis at the last end?inst.demontask = inst:DoPeriodicTask (0.03, function() if inst.components.health then inst.components.health:DoDelta(-0.0375, true, "Curse") endend) --Added the closing parenthesisThis is what I did because the game kept crashing otherwise Even with the DoPeriodTask at (0.03) and DoDelta at (-0.0375) my health depletion still swiftly and quickly goes down. Imagine 150 to 0 in a matter of 20 seconds xD. Edited April 7, 2015 by rons0n Link to comment Share on other sites More sharing options...
DarkXero Posted April 7, 2015 Share Posted April 7, 2015 (edited) @rons0n, You are right, I missed the parenthesis (which is necessary), and it keeps growing.I read applyForm and thought it got executed on certain sanity thresholds. But it gets executed on each sanity delta, so it adds up fast, as a task gets made each time. The task and the cancelation should be moved to becomedemonic and becomehuman, respectively, and put after the returns, unless you want to make applyForm work a bit like becomedemonic and becomehuman, to avoid it setting up stats again and again. You could also put a DoDelta(-0.03) inside applyForm, but then each damage tick would be tied to sanity deltas, and not the form. Edited April 7, 2015 by DarkXero Link to comment Share on other sites More sharing options...
rons0n Posted April 7, 2015 Author Share Posted April 7, 2015 Your suggestion of moving the code into the becomedemonic and becomehuman was the fix! Atleast from my quick 1 min testing it is anyway. I still have to change the numbers a tad bit but overall i think this is the right solution.If something goes wrong i'll make sure to post in this thread.Thanks again for being so helpful! Link to comment Share on other sites More sharing options...
rons0n Posted April 7, 2015 Author Share Posted April 7, 2015 (edited) @DarkXero, I really wish I could delete my previous post lol. So upon revival(resurrection) the health drain is still active even though my character is back in her 'normal form'. Did I miss something?Also sorry for calling you back and fourth, I should really do intensive testing next time x_x. Code bit:local MakePlayerCharacter = require "prefabs/player_common"local assets = { Asset( "ANIM", "anim/player_basic.zip" ), Asset( "ANIM", "anim/player_idles_shiver.zip" ), Asset( "ANIM", "anim/player_actions.zip" ), Asset( "ANIM", "anim/player_actions_axe.zip" ), Asset( "ANIM", "anim/player_actions_pickaxe.zip" ), Asset( "ANIM", "anim/player_actions_shovel.zip" ), Asset( "ANIM", "anim/player_actions_blowdart.zip" ), Asset( "ANIM", "anim/player_actions_eat.zip" ), Asset( "ANIM", "anim/player_actions_item.zip" ), Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ), Asset( "ANIM", "anim/player_actions_bugnet.zip" ), Asset( "ANIM", "anim/player_actions_fishing.zip" ), Asset( "ANIM", "anim/player_actions_boomerang.zip" ), Asset( "ANIM", "anim/player_bush_hat.zip" ), Asset( "ANIM", "anim/player_attacks.zip" ), Asset( "ANIM", "anim/player_idles.zip" ), Asset( "ANIM", "anim/player_rebirth.zip" ), Asset( "ANIM", "anim/player_jump.zip" ), Asset( "ANIM", "anim/player_amulet_resurrect.zip" ), Asset( "ANIM", "anim/player_teleport.zip" ), Asset( "ANIM", "anim/wilson_fx.zip" ), Asset( "ANIM", "anim/player_one_man_band.zip" ), Asset( "ANIM", "anim/shadow_hands.zip" ), Asset( "SOUND", "sound/sfx.fsb" ), Asset( "SOUND", "sound/wilson.fsb" ), Asset( "ANIM", "anim/beard.zip" ), Asset( "ANIM", "anim/arc.zip" ), Asset( "ANIM", "anim/ghost_arc_build.zip" ), Asset( "ANIM", "anim/arcBL.zip"),}local prefabs = {}local start_inv = { -- Custom starting items "arcwand", "meat", "meat", "meat", "meat",}-- This initializes for both clients and the hostlocal common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "arc.tex" )endlocal function applyForm(inst) if inst.form == "demonic" then inst.components.combat.damagemultiplier = 1.25 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.7) inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED * 1.25 inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * 1.25 inst.components.health.absorb = 0.30 inst.components.sanity.night_drain_mult = 0 inst.components.sanity.neg_aura_mult = 2 inst:AddTag("insomniac") end if inst.form == "normal" then inst.components.combat.damagemultiplier = 1 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE) inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED inst.components.health.absorb = 0 inst.components.sanity.night_drain_mult = 1.2 inst.components.sanity.neg_aura_mult = 1.2 inst:RemoveTag("insomniac") end endlocal function becomenormal(inst, silent) if inst.form == "normal" then return end if inst.demontask then inst.demontask:Cancel() inst.demontask = nil end inst.form = "normal" inst.AnimState:SetBuild("arc") endlocal function becomedemonic(inst, silent) if inst.form == "demonic" then return end inst.demontask = inst:DoPeriodicTask (0.003, function() if inst.components.health then inst.components.health:DoDelta(-0.0375 * 0.2, true, "Curse") end end) inst.form = "demonic" inst.AnimState:SetBuild("arcBL") endlocal function onsanitychange(inst, data, forcesilent) if inst.sg:HasStateTag("nomorph") or inst:HasTag("playerghost") or inst.components.health:IsDead() then return end local silent = inst.sg:HasStateTag("silentmorph") or not inst.entity:IsVisible() or forcesilent if inst.form == "demonic" then if inst.components.sanity.current > (115) then becomenormal(inst, silent) end elseif inst.form == "normal" then if inst.components.sanity.current < (100) then becomedemonic(inst, silent) end end applyForm(inst)endlocal function onnewstate(inst) if inst._wasnomorph ~= inst.sg:HasStateTag("nomorph") then inst._wasnomorph = not inst._wasnomorph if not inst._wasnomorph then onsanitychange(inst) end endendlocal function onbecameghost(inst) if inst._wasnomorph ~= nil then inst.form = "normal" inst._wasnomorph = nil inst.talksoundoverride = nil inst.hurtsoundoverride = nil inst:RemoveEventCallback("sanitydelta", onsanitychange) inst:RemoveEventCallback("newstate", onnewstate) endendlocal function onbecamehuman(inst) if inst._wasnomorph == nil then inst.form = "normal" inst._wasnomorph = inst.sg:HasStateTag("nomorph") inst.talksoundoverride = nil inst.hurtsoundoverride = nil inst:ListenForEvent("sanitydelta", onsanitychange) inst:ListenForEvent("newstate", onnewstate) onsanitychange(inst, nil, true) end endlocal smallScale = 0.5local medScale = 1.1local largeScale = 1.1local function onkilled(inst, data) local victim = data.victim if not (victim:HasTag("prey") or victim:HasTag("veggie") or victim:HasTag("structure")) then local delta = victim.components.combat.defaultdamage * 0.25 inst.components.health:DoDelta(delta, false, "battleborn") inst.components.sanity:DoDelta(delta) if not victim.components.health.nofadeout and (victim:HasTag("epic") or math.random() < .1) then local time = victim.components.health.destroytime or 2 local x, y, z = victim.Transform:GetWorldPosition() local scale = (victim:HasTag("smallcreature") and smallScale) or (victim:HasTag("largecreature") and largeScale) or medScale end endendlocal function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end-- This initializes for the host onlylocal master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "willow" -- Stats inst.components.hunger:SetMax(125) inst.components.sanity:SetMax(200) inst.form = "normal" inst._wasnomorph = nil inst.talksoundoverride = nil inst.hurtsoundoverride = nil inst:ListenForEvent("killed", onkilled) local eater = inst.components.eater eater.ignoresspoilage = true inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) inst.components.eater.Eat_orig = inst.components.eater.Eatfunction inst.components.eater:Eat( food ) if self:CanEat(food) then if food.components.edible.sanityvalue < 0 then food.components.edible.sanityvalue = 1 end if food.components.edible.healthvalue < 0 then food.components.edible.healthvalue = 3 endendreturn inst.components.eater:Eat_orig(food)end inst.OnLoad = onload inst.OnNewSpawn = onloadendreturn MakePlayerCharacter("arc", prefabs, assets, common_postinit, master_postinit, start_inv) Edited April 7, 2015 by rons0n Link to comment Share on other sites More sharing options...
DarkXero Posted April 7, 2015 Share Posted April 7, 2015 @rons0n, The task doesn't cancel because you go from demon to normal passing through ghost, and becomenormal doesn't get called. You can call becomenormal from onbecomehuman, or from onbecomeghost, to cancel the task. Link to comment Share on other sites More sharing options...
rons0n Posted April 7, 2015 Author Share Posted April 7, 2015 (edited) How many times have i said thanks? Prolly a lot. Does it matter if i call to both onbecomehuman and onbecomeghost, or should I just have it only on onbecomehuman?Either way it still works, I'm just curious Edited April 7, 2015 by rons0n Link to comment Share on other sites More sharing options...
DarkXero Posted April 8, 2015 Share Posted April 8, 2015 @rons0n,it doesn't matter. You are deleting the task at either the beginning or the end of your ghost time. I would delete it on onbecomeghost, to avoid having a task running pointlessly during ghost time until resurrection. 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