Draukel Posted September 15, 2017 Share Posted September 15, 2017 Hey everyone, me again for the same thing: my character mod. I was testing once again the game with new codes and one moment, something happened. That mean the code with the "OnPhaseChanged" seem to face some troubles, and I think it's when mob kill other mob, but I don't know how to fix that. To see all of my codes, there is what i've actually made Quote local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), } local prefabs = {} -- Custom starting items local start_inv = { } -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "esctemplate_speed_mod", 1) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "esctemplate_speed_mod") end -- When loading or spawning the character 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 end local function OnPhaseChanged(inst) if TheWorld.state.isday then inst.components.sanity.rate = 1 elseif TheWorld.state.isdusk then inst.components.sanity.rate = 0 elseif TheWorld.state.isnight then inst.components.sanity.rate = -1 end end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "esctemplate.tex" ) end -- This initializes for the server only. Components are added here. local master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "maxwell" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(250) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(75) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst.OnLoad = onload inst.OnNewSpawn = onload inst.components.sanity.night_drain_mult = 0.5 inst.components.temperature.freezetemp = -10 inst.components.temperature.maxtemp = 60 inst.components.health.fire_damage_scale = 0 inst.components.eater.strongstomach = true inst:ListenForEvent("entity_death", function(wrld, data) if data.cause == inst.prefab then local delta = 10 -- amount inst.components.health:DoDelta(delta) inst.components.sanity:DoDelta(delta) end inst:ListenForEvent("phasechanged", OnPhaseChanged) end, GetWorld()) end return MakePlayerCharacter("esctemplate", prefabs, assets, common_postinit, master_postinit, start_inv) And I didn't know a way for this problem, somebody can help? Link to comment https://forums.kleientertainment.com/forums/topic/82041-a-crash-caused-by-a-special-code/ Share on other sites More sharing options...
RedHairedHero Posted September 29, 2017 Share Posted September 29, 2017 inst:ListenForEvent("phasechanged", OnPhaseChanged) So this event listener here isn't doing anything at the moment. What happens is when there's a phase change it will call a function that you setup. In this case you're trying to call a function called OnPhaseChanged, which doesn't exist in your code. If you want something to happen when the phase changes just create a function above your common_postinit function. local function OnPhaseChanged(inst) --Your code here end Link to comment https://forums.kleientertainment.com/forums/topic/82041-a-crash-caused-by-a-special-code/#findComment-959246 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