Valkyrie19k Posted September 23, 2015 Share Posted September 23, 2015 I'm fairly new to the modding community in DST and this would be my 2nd mod. I've done pretty much the basic of the basic coding but I am having problems with making my character fit with these perks.Here is the code: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/jet.zip" ), Asset( "ANIM", "anim/ghost_jet_build.zip" ),}local prefabs = { "beardhair",}local function common_postinit(inst) inst:AddTag("ghostwithhat") --bearded (from beard component) added to pristine state for optimization inst:AddTag("bearded")endlocal function OnResetBeard(inst) inst.AnimState:ClearOverrideSymbol("beard")end--tune the beard economy...local BEARD_DAYS = { 4, 8, 16 }local BEARD_BITS = { 1, 3, 9 }local function OnGrowShortBeard(inst) inst.AnimState:OverrideSymbol("beard", "beard", "beard_short") inst.components.beard.bits = BEARD_BITS[1]endlocal function OnGrowMediumBeard(inst) inst.AnimState:OverrideSymbol("beard", "beard", "beard_medium") inst.components.beard.bits = BEARD_BITS[2]endlocal function OnGrowLongBeard(inst) inst.AnimState:OverrideSymbol("beard", "beard", "beard_long") inst.components.beard.bits = BEARD_BITS[3]endlocal function master_postinit(inst) inst:AddComponent("beard") inst.components.beard.onreset = OnResetBeard inst.components.beard.prize = "beardhair" inst.components.beard:AddCallback(BEARD_DAYS[1], OnGrowShortBeard) inst.components.beard:AddCallback(BEARD_DAYS[2], OnGrowMediumBeard) inst.components.beard:AddCallback(BEARD_DAYS[3], OnGrowLongBeard)endlocal start_inv = {}-- Custom starting itemslocal start_inv = {}-- When the character is revived from humanlocal function onbecamehuman(inst) -- Set speed when loading or reviving from ghost (optional) inst.components.locomotor.walkspeed = 4endlocal function updatespeed(inst, phase) if phase == "day" then inst.components.locomotor.runspeed = 7 elseif phase == "dusk" then inst.components.locomotor.runspeed = 5 elseif phase == "night" then inst.components.locomotor.runspeed = 3 endend-- When loading or spawning the characterlocal function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) if not inst:HasTag("playerghost") then onbecamehuman(inst) endend-- This initializes for both the server and client. Tags can be added here.local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "jet.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 = "wolfgang" -- Stats inst.components.health:SetMaxHealth(175) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(175) -- Sanity draims inst.components.sanity.night_drain_mult = 1 -- Damage multiplier (optional)local function onchange(inst) local currenthunger = inst.components.hunger.current local full = 150 local hungry = 75 if currenthunger >= full then inst.components.combat.damagemultiplier = 3 elseif (currenthunger < full) and (currenthunger >= hungry) then inst.components.combat.damagemultiplier = 2 elseif (currenthunger < hungry) then inst.components.combat.damagemultiplier = 1 end end -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE -- Ignore spoilage inst.components.eater.ignoresspoilage = false -- Can Eat Raw inst.components.eater:SetCanEatRaw() -- Can Eat Monster Meat inst.components.eater.strongstomach = true inst.OnLoad = onload inst.OnNewSpawn = onloadendreturn MakePlayerCharacter("jet", prefabs, assets, common_postinit, master_postinit, start_inv)Both function updatespeed and function onchange does't work. I've looked and hopped from one thread to the next without avail of fixing the problem. Maybe someone here could help?Perks I wanted:Moves fast at daytimeMoves normal at duskMoves slow at night Hunger >= 150 (x3 damage)Hunger >= 75 (x2 damage)Hunger < 75 (x1 damage)I haven't tried the beard part yet, not really that important.Thanks for those who could answer. Link to comment https://forums.kleientertainment.com/forums/topic/58075-need-help-with-codes-that-do-not-work-please/ Share on other sites More sharing options...
DrSmugleaf Posted September 23, 2015 Share Posted September 23, 2015 Your main problems were a messy lua file and not using your functions.You needed to assign your functions to a worldstate or event, like this: inst:WatchWorldState("daytime", function(inst) updatespeed(inst) end , TheWorld) inst:WatchWorldState("dusktime", function(inst) updatespeed(inst) end , TheWorld) inst:WatchWorldState("nighttime", function(inst) updatespeed(inst) end , TheWorld)inst:ListenForEvent("hungerdelta", onhungerdelta)jet.lua Link to comment https://forums.kleientertainment.com/forums/topic/58075-need-help-with-codes-that-do-not-work-please/#findComment-675534 Share on other sites More sharing options...
Valkyrie19k Posted September 23, 2015 Author Share Posted September 23, 2015 Your main problems were a messy lua file and not using your functions.You needed to assign your functions to a worldstate or event, like this: inst:WatchWorldState("daytime", function(inst) updatespeed(inst) end , TheWorld) inst:WatchWorldState("dusktime", function(inst) updatespeed(inst) end , TheWorld) inst:WatchWorldState("nighttime", function(inst) updatespeed(inst) end , TheWorld)inst:ListenForEvent("hungerdelta", onhungerdelta)Thanks, I've just tried it and the event for hunger works perfectly. I do apologize for having a messy lua file. I just started coding yesterday so I'm still learning. A little bit trouble with the updatespeed right now and I am trying to solve it. Thank you for the wonderful help @DrSmugleaf Link to comment https://forums.kleientertainment.com/forums/topic/58075-need-help-with-codes-that-do-not-work-please/#findComment-675568 Share on other sites More sharing options...
DrSmugleaf Posted September 23, 2015 Share Posted September 23, 2015 No problem! If you have trouble organizing things look at a base game file. If the updatespeed function is giving you trouble, try adding GLOBAL. before every TheWorld:local function updatespeed(inst) if GLOBAL.TheWorld.state.isday then inst.components.locomotor.runspeed = 7 elseif GLOBAL.TheWorld.state.isdusk then inst.components.locomotor.runspeed = 5 elseif GLOBAL.TheWorld.state.isnight then inst.components.locomotor.runspeed = 3 endendMostly because with the mod env I don't remember where GLOBAL.'s go Link to comment https://forums.kleientertainment.com/forums/topic/58075-need-help-with-codes-that-do-not-work-please/#findComment-675569 Share on other sites More sharing options...
Valkyrie19k Posted September 24, 2015 Author Share Posted September 24, 2015 No problem! If you have trouble organizing things look at a base game file. If the updatespeed function is giving you trouble, try adding GLOBAL. before every TheWorld:local function updatespeed(inst) if GLOBAL.TheWorld.state.isday then inst.components.locomotor.runspeed = 7 elseif GLOBAL.TheWorld.state.isdusk then inst.components.locomotor.runspeed = 5 elseif GLOBAL.TheWorld.state.isnight then inst.components.locomotor.runspeed = 3 endendMostly because with the mod env I don't remember where GLOBAL.'s goI tried doing this but the game crashes with the log saying that GLOBAL is undeclared or something. I'll try fixing it way later. Haven't slept yet and still have classes in about an hour. Haha. (*It seems the speed set during daytime works since I've tried changing the value to 1 and my character moved like a snail. I'm guessing it is not reading dusk and night.)I really appreciate the help though. Thank you very much. Link to comment https://forums.kleientertainment.com/forums/topic/58075-need-help-with-codes-that-do-not-work-please/#findComment-675588 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