red1500z Posted May 30, 2021 Share Posted May 30, 2021 Hello I wanted to ask for help because I wanted to know how to make the transformation skin reload (this because when leaving the world and connecting again the character skin is not saved) i used this code local function onmoonphasechange(inst, phase) if not inst:HasTag("playerghost") then --only apply if the player is alive local health_max = 110 local damagemult = 1 if phase == "new" then health_max = 50 damagemult = 1.0 inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 7 inst.components.health:StartRegen(3 , 4) inst.sg:GoToState("electrocute") inst.AnimState:SetBuild("red1500") inst.components.talker:Say("me siento horrible", 2.5,true) local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) elseif phase == "quarter" then health_max = 65 damagemult = 1 inst.components.locomotor.walkspeed = 8 inst.components.locomotor.runspeed = 8 inst.components.health:StartRegen(4 , 4) inst.sg:GoToState("electrocute") inst.AnimState:SetBuild("red1500moon") inst.components.talker:Say("hoy se asoma la luna", 2.5,true) local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) elseif phase == "half" then health_max = 80 damagemult = 1.2 inst.components.locomotor.walkspeed = 9 inst.components.locomotor.runspeed = 9 inst.components.health:StartRegen(5 , 3) inst.sg:GoToState("electrocute") inst.AnimState:SetBuild("red1500moon1") inst.components.talker:Say("me siento extraño", 2.5,true) local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) elseif phase == "threequarter" then health_max = 95 damagemult = 1.3 inst.components.locomotor.walkspeed = 9 inst.components.locomotor.runspeed = 9 inst.components.health:StartRegen(6 , 3) inst.sg:GoToState("electrocute") inst.AnimState:SetBuild("red1500moon2") inst.components.talker:Say("mis propios huesos me lastiman", 2.5,true) local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) elseif phase == "full" then damagemult = 1.5 inst.components.locomotor.walkspeed = 9 inst.components.locomotor.runspeed = 9 health_max = 110 inst.components.health:StartRegen(6 , 2) inst.sg:GoToState("electrocute") inst.AnimState:SetBuild("red1500moon3") inst.components.talker:Say("la luna llena es perfecta", 2.5,true) local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) end --SetMaxHealth set the current health to the max, so use this workaround to keep the current percentage local health_percent = inst.components.health:GetPercent() inst.components.health:SetMaxHealth(health_max) inst.components.health:SetPercent(health_percent, true) --we do this check in case there are other multipliers applied local newdamagemult = (inst.components.combat.damagemultiplier or 1) / (inst.moonphasedamagemult or 1) * damagemult inst.components.combat.damagemultiplier = newdamagemult inst.moonphasedamagemult = damagemult end end Link to comment Share on other sites More sharing options...
zetake Posted June 24, 2021 Share Posted June 24, 2021 I guess add your function to function OnLoad in your prefab. inst.OnLoad = function() onmoonphasechange(inst, GLOBAL.GetClock():GetMoonPhase()) end Don't know if this will work, but you should get there. Link to comment Share on other sites More sharing options...
red1500z Posted June 26, 2021 Author Share Posted June 26, 2021 On 6/24/2021 at 2:13 AM, zetake said: I guess add your function to function OnLoad in your prefab. inst.OnLoad = function() onmoonphasechange(inst, GLOBAL.GetClock():GetMoonPhase()) end Don't know if this will work, but you should get there. Where in the code do I put it, I get lost very easily (and thanks for the help ) you mean something like that? local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end inst.OnLoad = function() onmoonphasechange(inst, GLOBAL.GetClock():GetMoonPhase()) end end (and thanks again) Link to comment Share on other sites More sharing options...
zetake Posted June 27, 2021 Share Posted June 27, 2021 No, just put the code that I've written in your prefab function which should be named fn. local fn = function(inst) --your other code can be here inst.OnLoad = function() --your other code can be here onmoonphasechange(inst, GLOBAL.GetClock():GetMoonPhase()) --your other code can be here end --your other code can be here end I mean the function you pass to MakePlayerCharacter: OnLoad is called only once when game loads character into world. 55 minutes ago, red1500z said: inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end Which means this code makes no sense to be there. I didn't offered OnSave, because you would need to save things that don't save and then load them. Which would be a lot of work. Instead you can just load again transformation after entering world. Link to comment Share on other sites More sharing options...
red1500z Posted June 27, 2021 Author Share Posted June 27, 2021 2 hours ago, zetake said: No, just put the code that I've written in your prefab function which should be named fn. local fn = function(inst) --your other code can be here inst.OnLoad = function() --your other code can be here onmoonphasechange(inst, GLOBAL.GetClock():GetMoonPhase()) --your other code can be here end --your other code can be here end I mean the function you pass to MakePlayerCharacter: OnLoad is called only once when game loads character into world. Which means this code makes no sense to be there. I didn't offered OnSave, because you would need to save things that don't save and then load them. Which would be a lot of work. Instead you can just load again transformation after entering world. uff I can't find "fn" butt this is the code i am using red1500.lua Link to comment Share on other sites More sharing options...
zetake Posted June 27, 2021 Share Posted June 27, 2021 Function fn is in Don't Starve. And I was giving code for it. In Don't Starve Together there is common_postinit and master_postinit. Oh, you have already OnLoad. Not sure how your mod works, but I think you should take onmoonphasechange from here: --monn xdd inst:WatchWorldState("moonphase", onmoonphasechange) --onmoonphasechange(inst, TheWorld.state.moonphase) and put it here. -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when not a ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "red1500_speed_mod", 1.1) onmoonphasechange(inst, TheWorld.state.moonphase) end Because function onbecamehuman is called from OnLoad and it's also called from Event Listener, which makes sense now, my bad. Link to comment Share on other sites More sharing options...
red1500z Posted June 27, 2021 Author Share Posted June 27, 2021 1 hour ago, zetake said: Function fn is in Don't Starve. And I was giving code for it. In Don't Starve Together there is common_postinit and master_postinit. Oh, you have already OnLoad. Not sure how your mod works, but I think you should take onmoonphasechange from here: --monn xdd inst:WatchWorldState("moonphase", onmoonphasechange) --onmoonphasechange(inst, TheWorld.state.moonphase) and put it here. -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when not a ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "red1500_speed_mod", 1.1) onmoonphasechange(inst, TheWorld.state.moonphase) end Because function onbecamehuman is called from OnLoad and it's also called from Event Listener, which makes sense now, my bad. I did what you told me but I think it did not work or more likely I did it wrong but thank you very much for the help (I leave you the code there in case you have done something wrong and I am sorry for the inconvenience) red1500.lua Link to comment Share on other sites More sharing options...
zetake Posted June 27, 2021 Share Posted June 27, 2021 No need for fn. Function onmoonphasechange is not declared before function onbecamehuman. That's why error. Try this red1500.lua Link to comment Share on other sites More sharing options...
red1500z Posted June 27, 2021 Author Share Posted June 27, 2021 12 hours ago, zetake said: No need for fn. Function onmoonphasechange is not declared before function onbecamehuman. That's why error. Try this red1500.lua I can't understand what happened (I think my code is a real spaghetti) Link to comment Share on other sites More sharing options...
zetake Posted June 27, 2021 Share Posted June 27, 2021 My bad, I didn't use brackets in an array. red1500.lua Link to comment Share on other sites More sharing options...
red1500z Posted June 27, 2021 Author Share Posted June 27, 2021 44 minutes ago, zetake said: My bad, I didn't use brackets in an array. red1500.lua 5.68 kB · 0 downloads Friend, you are great, it works perfectly, thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.