LlamaDom Posted February 24, 2021 Share Posted February 24, 2021 (edited) Hey! Im trying to make a character that changes form according to the full moon using this The gamestarts to load, then i just freeze at a white screen this is my code local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), Asset( "ANIM", "anim/wrigley.zip" ), Asset( "ANIM", "anim/werewrigley.zip" ), } -- Your character's stats TUNING.WRIGLEY_HEALTH = 175 TUNING.WRIGLEY_HUNGER = 200 TUNING.WRIGLEY_SANITY = 125 -- Custom starting inventory TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.WRIGLEY = { "berries","carrot","berries","carrot","berries","carrot","berries","carrot","berries","carrot" } local start_inv = {} for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do start_inv[string.lower(k)] = v.WRIGLEY end local prefabs = FlattenTree(start_inv, true) local isInSecondForm = false local function TurnBackToNormal(inst) inst:RemoveTag("werewrigley") inst:RemoveTag("insomniac") inst:AddTag("scarytoprey") inst.components.talker:Say("Oink!", 2.5,true) inst.SoundEmitter:PlaySound("dontstarve/pig/oink") local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get()) inst.components.eater.ignoresspoilage = false inst.components.eater.strongstomach = false inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1) inst.components.hunger.hungerrate = 1.2 * TUNING.WILSON_HUNGER_RATE inst.components.combat.damagemultiplier = 1 inst.components.sanity.dapperness = 0 inst.AnimState:SetBuild("wrigley") isInSecondForm = false end local function TurnIntoSecondForm(inst) inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/grunt") inst:AddTag("werewrigley") inst:AddTag("insomniac") inst:AddTag("scarytoprey") local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get()) inst.components.eater.ignoresspoilage = false inst.components.eater.strongstomach = false inst.components.combat.damagemultiplier = 2 inst.components.hunger.hungerrate = 2 * TUNING.WILSON_HUNGER_RATE inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2) inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE * (-1) inst.AnimState:SetBuild("werewrigley") isInSecondForm = true end local function OnPigMoon(inst, isfullmoon) if isfullmoon then TurnIntoSecondForm(inst) else TurnBackToNormal(inst) end end --for hunger drop changing local function OnHungerDrop(inst, data) --Make sure not to react while the player is dead. if inst:HasTag("playerghost") or inst.components.health and inst.components.health:IsDead() then return end if not isInSecondForm and inst.components.hunger.current < 25 then TurnIntoSecondForm(inst) -- Otherwise, if sanity gets back above 50, we become normal again. elseif isInSecondForm and inst.components.hunger.current > 50 then TurnBackToNormal(inst) end end -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when not a ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wrigley_speed_mod", 1) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "wrigley_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 -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "wrigley.tex" ) end -- This initializes for the server only. Components are added here. local master_postinit = function(inst) -- Set starting inventory inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default -- choose which sounds this character will play inst.soundsname = "willow" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(TUNING.WRIGLEY_HEALTH) inst.components.hunger:SetMax(TUNING.WRIGLEY_HUNGER) inst.components.sanity:SetMax(TUNING.WRIGLEY_SANITY) -- 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 --for hugner drop changing inst:ListenForEvent("hungerdelta", OnHungerDrop) --for full moon inst:WatchWorldState("isfullmoon", OnPigMoon) OnPigMoon(inst, TheWorld.state.isfullmoon) end return MakePlayerCharacter("wrigley", prefabs, assets, common_postinit, master_postinit, prefabs) Edited March 9, 2021 by LlamaDom Link to comment https://forums.kleientertainment.com/forums/topic/127375-solved-modding-changing-forms/ Share on other sites More sharing options...
Combustiblemon Posted February 24, 2021 Share Posted February 24, 2021 Can you give client_log.txt for more details? Link to comment https://forums.kleientertainment.com/forums/topic/127375-solved-modding-changing-forms/#findComment-1432340 Share on other sites More sharing options...
LlamaDom Posted February 25, 2021 Author Share Posted February 25, 2021 (edited) i just figured it out, but thanks! I ran into a slight issue of the general code of making it so you cant equipt hand,body, or head gearwhile transformed. Where would i find that? Along with this, I have night vision on when I transform and its night time. it works when Im transformed and then it turns night, but when im in standard form and it turns night, even if I transform, i dont have nightvision. What could be the problem here? Again, my code..not sure how to do the preview thing to make it smaller local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), Asset( "ANIM", "anim/wrigley.zip" ), Asset( "ANIM", "anim/werewrigley.zip" ), } -- Your character's stats TUNING.WRIGLEY_HEALTH = 175 TUNING.WRIGLEY_HUNGER = 200 TUNING.WRIGLEY_SANITY = 125 -- Custom starting inventory TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.WRIGLEY = { "berries","carrot","berries","carrot","berries","carrot","berries","carrot","berries","carrot" } local start_inv = {} for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do start_inv[string.lower(k)] = v.WRIGLEY end local prefabs = FlattenTree(start_inv, true) local isInSecondForm = false local isInWereForm = false --------------------------------------------------------------------------------------- local BEAVERVISION_COLOURCUBES = { day = "images/colour_cubes/beaver_vision_cc.tex", dusk = "images/colour_cubes/beaver_vision_cc.tex", night = "images/colour_cubes/beaver_vision_cc.tex", full_moon = "images/colour_cubes/beaver_vision_cc.tex", } local function UpdateNightVision(inst, phase) local enable = phase == "night" and inst.modnightvision:value() inst:DoTaskInTime(enable and 0 or 1, function(inst) inst.components.playervision:ForceNightVision(enable) inst.components.playervision:SetCustomCCTable(enable and BEAVERVISION_COLOURCUBES or nil) end) end local function OnInitNightVision(inst) if TheWorld.ismastersim or inst.HUD then inst:WatchWorldState("phase", UpdateNightVision) inst:ListenForEvent("modnightvisiondirty", UpdateNightVision) UpdateNightVision(inst, TheWorld.state.phase) end end ------------------------------------------------------------------------------------ local function TurnBackToNormal(inst) inst:RemoveTag("werewrigley") inst:RemoveTag("insomniac") inst:AddTag("scarytoprey") inst.modnightvision:set(false) inst.components.talker:Say("OINK!", 2.5,true) inst.SoundEmitter:PlaySound("dontstarve/pig/oink") local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get()) inst.components.eater.ignoresspoilage = false inst.components.eater.strongstomach = false inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst.components.combat.damagemultiplier = 1 inst.components.sanity.dapperness = 0 inst.AnimState:SetBuild("wrigley") inst.modnightvision:set(false) isInSecondForm = false isInWereForm = false end local function TurnIntoSecondForm(inst) --inst.modnightvision:set(true) inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/grunt") inst:AddTag("werewrigley") inst:AddTag("insomniac") inst:AddTag("scarytoprey") inst.components.talker:Say("darkpig", 2.5,true) local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get()) inst.components.combat:SetDefaultDamage(TUNING.WEREMOOSE_DAMAGE) inst.components.combat.bonusdamagefn = nil inst.components.pinnable.canbepinned = false inst.components.temperature.inherentinsulation = TUNING.INSULATION_LARGE inst.components.temperature.inherentsummerinsulation = TUNING.INSULATION_LARGE inst.components.moisture:SetInherentWaterproofness(TUNING.WATERPROOFNESS_LARGE) inst.components.catcher:SetEnabled(false) inst.components.eater.ignoresspoilage = false inst.components.eater.strongstomach = false inst.components.combat.damagemultiplier = 1 inst.components.hunger.hungerrate = 2 * TUNING.WILSON_HUNGER_RATE inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2) inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE * (-1) inst.AnimState:SetBuild("werewrigley") isInSecondForm = true isInWereForm = false end local function TurnIntoWereForm(inst) --inst.modnightvision:set(true) inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/grunt") inst:AddTag("werewrigley") inst:AddTag("insomniac") inst:AddTag("scarytoprey") inst.components.talker:Say("werepig", 2.5,true) local x, y, z = inst.Transform:GetWorldPosition() local fx = SpawnPrefab("maxwell_smoke") fx.Transform:SetPosition(x, y, z) inst.components.combat:SetDefaultDamage(TUNING.WEREMOOSE_DAMAGE) inst.components.combat.bonusdamagefn = nil inst.components.pinnable.canbepinned = false inst.components.temperature.inherentinsulation = TUNING.INSULATION_LARGE inst.components.temperature.inherentsummerinsulation = TUNING.INSULATION_LARGE inst.components.moisture:SetInherentWaterproofness(TUNING.WATERPROOFNESS_LARGE) inst.components.catcher:SetEnabled(false) inst.components.eater.ignoresspoilage = false inst.components.eater.strongstomach = false inst.components.combat.damagemultiplier = 1 inst.components.hunger.hungerrate = 2 * TUNING.WILSON_HUNGER_RATE inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2) inst.components.sanity.dapperness = TUNING.DAPPERNESS_LARGE * (-1) inst.AnimState:SetBuild("werewrigley") isInSecondForm = false isInWereForm = true end ------------------------------------------------------------------------------------------ --for hunger drop changing and fullmoon too local function OnHungerDrop(inst, data) --Make sure not to react while the player is dead. if inst:HasTag("playerghost") or inst.components.health and inst.components.health:IsDead() then return end --if in pig form, and less than 25 hunger, turn into dark form if not isInSecondForm and not isInWereForm and inst.components.hunger.current < 25 then inst.modnightvision:set(true) TurnIntoSecondForm(inst) inst.modnightvision:set(true) -- if in darkform and hunger is greater than 50, turn into normal form elseif isInSecondForm and not isInWereForm and inst.components.hunger.current > 50 then TurnBackToNormal(inst) inst.modnightvision:set(false) end end local function OnPigMoon(inst, isfullmoon) if isfullmoon then TurnIntoWereForm(inst) else TurnBackToNormal(inst) end end ----------------------------------------------------------------------------------- -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when not a ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wrigley_speed_mod", 1) end local function onbecamewerepig(inst) if inst:HasTag("playerghost") or inst.components.health and inst.components.health:IsDead() then return end inst.components.combat:SetDefaultDamage(TUNING.WEREMOOSE_DAMAGE) inst.components.combat.bonusdamagefn = nil inst.components.pinnable.canbepinned = false inst.components.temperature.inherentinsulation = TUNING.INSULATION_LARGE inst.components.temperature.inherentsummerinsulation = TUNING.INSULATION_LARGE inst.components.moisture:SetInherentWaterproofness(TUNING.WATERPROOFNESS_LARGE) inst.components.catcher:SetEnabled(false) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "wrigley_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 -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "wrigley.tex" ) inst.modnightvision = net_bool(inst.GUID, "player.modnightvision", "modnightvisiondirty") inst.modnightvision:set(false) inst:DoTaskInTime(0, OnInitNightVision) end -- This initializes for the server only. Components are added here. local master_postinit = function(inst) -- Set starting inventory inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default -- choose which sounds this character will play inst.soundsname = "willow" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(TUNING.WRIGLEY_HEALTH) inst.components.hunger:SetMax(TUNING.WRIGLEY_HUNGER) inst.components.sanity:SetMax(TUNING.WRIGLEY_SANITY) -- 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 --for hugner drop changing inst:ListenForEvent("hungerdelta", OnHungerDrop) --inst:ListenForEvent("hungerdelta", OnPigMoon) --for full moon inst:WatchWorldState("isfullmoon", OnPigMoon) --inst:WatchWorldState("isfullmoon", OnHungerDrop) OnPigMoon(inst, TheWorld.state.isfullmoon) --OnHungerDrop(inst, TheWorld.state.isfullmoon) end return MakePlayerCharacter("wrigley", prefabs, assets, common_postinit, master_postinit, prefabs) Edited February 25, 2021 by LlamaDom Link to comment https://forums.kleientertainment.com/forums/topic/127375-solved-modding-changing-forms/#findComment-1432546 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