Mitzimber Posted August 7, 2017 Share Posted August 7, 2017 Hello! I am working on redoing the code of an existing character mod, just for personal use, and I had some trouble with a code I am using. I tried to make it so that whenever the character used the sit emote she would slowly regain life, and sanity, as well as giving it off to those around her. This would be a bit like meditating. Here is the code I used: -- Emote for Meditating inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst:DoPeriodicTask(5.0, local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end end ) Unfortunately, this seems to crash my game. Here is the crash log: Thanks in advance to whoever helps me! Link to comment Share on other sites More sharing options...
AkaiNight Posted August 7, 2017 Share Posted August 7, 2017 1 hour ago, Mitzimber said: Hello! I am working on redoing the code of an existing character mod, just for personal use, and I had some trouble with a code I am using. I tried to make it so that whenever the character used the sit emote she would slowly regain life, and sanity, as well as giving it off to those around her. This would be a bit like meditating. Here is the code I used: -- Emote for Meditating inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst:DoPeriodicTask(5.0, local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end end ) Unfortunately, this seems to crash my game. Here is the crash log: Thanks in advance to whoever helps me! Error must be in spek.lua take a look at 110.line there must be something not necessary near local. Link to comment Share on other sites More sharing options...
Mitzimber Posted August 7, 2017 Author Share Posted August 7, 2017 Thanks for responding. Yeah, I took a look and line 110 is this line from the emote code: local x, y, z = inst.Transform:GetWorldPosition() I think this line is needed, but I'm not entirely sure, since right now in the code there is a line of code with local right after that line. Here is the code again: -- Emote for Meditating inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst:DoPeriodicTask(5.0, local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end end ) Link to comment Share on other sites More sharing options...
alainmcd Posted August 7, 2017 Share Posted August 7, 2017 Missing function() before that line. Link to comment Share on other sites More sharing options...
Mitzimber Posted August 7, 2017 Author Share Posted August 7, 2017 So like this? function() local x, y, z = inst.Transform:GetWorldPosition() Thanks so much for helping! Link to comment Share on other sites More sharing options...
Mitzimber Posted August 7, 2017 Author Share Posted August 7, 2017 Awesome, thanks. So that problem was fixed, however i have a new problem. The game is still crashing and had numerous other issues, which I was able to fix, however, this one has me stumped. Here is the crash log: Line 106 is this line from the emote code: inst:ListenForEvent("emote") function(inst, data) Link to comment Share on other sites More sharing options...
alainmcd Posted August 7, 2017 Share Posted August 7, 2017 inst:ListenForEvent("emote", function(inst, data) You had it right the first time. Not sure if that's the error displayed, though. Link to comment Share on other sites More sharing options...
Mitzimber Posted August 7, 2017 Author Share Posted August 7, 2017 I would have kept it that way, but then I got this error: Link to comment Share on other sites More sharing options...
Mitzimber Posted August 7, 2017 Author Share Posted August 7, 2017 Never mind, I fixed that issue, haha. Here is the issue I'm at now: Link to comment Share on other sites More sharing options...
alainmcd Posted August 7, 2017 Share Posted August 7, 2017 Without context it's impossible to know what is causing the error. Post the whole function or the whole file. Use spoilers if it's very long. Link to comment Share on other sites More sharing options...
AkaiNight Posted August 7, 2017 Share Posted August 7, 2017 Well i have no idea seems like there is no error but try to change -- Emote for Meditating inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst:DoPeriodicTask(5.0, local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end end ) this with this -- Emote for Meditating inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst:DoPeriodicTask(5.0, local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end end ) everything is seems like same but i change local x, y, z = inst.Transform:GetWorldPosition() this with same code in my mod it's all same but sometimes game does not accept code and when i change it with same thing it works so give a try. Link to comment Share on other sites More sharing options...
Mitzimber Posted August 9, 2017 Author Share Posted August 9, 2017 Sure! Here is the whole 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/spek.zip" ), Asset( "ANIM", "anim/speksum.zip" ), Asset( "ANIM", "anim/spekwin.zip" ), Asset( "ANIM", "anim/spekspr.zip" ), Asset( "ANIM", "anim/ghost_spek_build.zip" ), } local prefabs = {} local start_inv = { "fireflies", "fireflies", "fireflies", "fireflies", "fireflies", "fireflies", "fireflies", "fireflies", "fireflies", "fireflies", } local function onpreload(inst, data) if data then if data.level then inst.level = data.level applyupgrades(inst) --re-set these from the save data, because of load-order clipping issues if data.health and data.health.health then inst.components.health.currenthealth = data.health.health end if data.hunger and data.hunger.hunger then inst.components.hunger.current = data.hunger.hunger end if data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current end inst.components.health:DoDelta(0) inst.components.hunger:DoDelta(0) inst.components.sanity:DoDelta(0) end end end local function WatchSeason( inst, season ) if season == "summer" then inst.AnimState:SetBuild("speksum") elseif season == "winter" then inst.AnimState:SetBuild("spekwin") elseif season == "spring" then inst.AnimState:SetBuild("spekspr") else inst.AnimState:SetBuild("spek") end end local function sanityfn(inst) -- Function to determine sanity boost or drain based on precipitation / season local delta = 0 if TheWorld.state.iswinter and not TheWorld.state.israining then -- Winter sanity drain delta = (-1*TUNING.DAPPERNESS_TINY) elseif TheWorld.state.iswinter and TheWorld.state.israining and TheWorld.state.temperature > 0 then -- Winter and raining, so sanity boost delta = (TUNING.DAPPERNESS_MED*1.5*TheWorld.state.precipitationrate) + (TUNING.DAPPERNESS_TINY*5.3) elseif TheWorld.state.iswinter and TheWorld.state.israining and TheWorld.state.temperature < 0 then -- Winter and snowing, so sanity drain delta = (-1*TUNING.DAPPERNESS_TINY) elseif TheWorld.state.israining then -- Raining sanity boost delta = (TUNING.DAPPERNESS_MED*1.5*TheWorld.state.precipitationrate) + (TUNING.DAPPERNESS_TINY*5.3) end return delta -- TUNING end -- Emote for Meditating inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst:DoPeriodicTask(5.0, local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end end ) -- This initializes for both clients and the host local common_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "wendy" -- Minimap icon inst.MiniMapEntity:SetIcon( "spek.tex" ) end local function onsave(inst, data) data.level = inst.level data.charge_time = inst.charge_time end -- Stats local function master_postinit(inst) inst.components.sanity.custom_rate_fn = sanityfn -- Takes care of sanity boost/drain at all times inst.OnSave = onsave inst.OnPreLoad = onpreload inst.components.sanity:SetMax(150) inst.components.health:SetMaxHealth(100) inst.components.hunger:SetMax(50) inst.components.eater:SetDiet({FOODGROUP.OMNI}, {FOODGROUP.OMNI_NOMEAT}) inst:WatchWorldState("season", WatchSeason ) WatchSeason( inst, TheWorld.state.season ) local function updateHungerRate(inst, mult) inst.components.hunger:SetRate(mult*TUNING.WILSON_HUNGER_RATE) end inst:WatchWorldState( "startday", function() updateHungerRate(inst, -.5) end ) inst:WatchWorldState( "startdusk", function() updateHungerRate(inst, .3) end ) inst:WatchWorldState( "startnight", function() updateHungerRate(inst, 2) end ) local mult = 0 if TheWorld.state.isday then mult = -.5 elseif TheWorld.state.isnight then mult = 2 end updateHungerRate(inst, mult) end return MakePlayerCharacter("spek", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment Share on other sites More sharing options...
alainmcd Posted August 9, 2017 Share Posted August 9, 2017 The chunk of code you posted before belongs in the master_postinit function: local function master_postinit(inst) inst.components.sanity.custom_rate_fn = sanityfn -- Takes care of sanity boost/drain at all times inst.OnSave = onsave inst.OnPreLoad = onpreload inst.components.sanity:SetMax(150) inst.components.health:SetMaxHealth(100) inst.components.hunger:SetMax(50) inst.components.eater:SetDiet({FOODGROUP.OMNI}, {FOODGROUP.OMNI_NOMEAT}) inst:WatchWorldState("season", WatchSeason ) WatchSeason( inst, TheWorld.state.season ) local function updateHungerRate(inst, mult) inst.components.hunger:SetRate(mult*TUNING.WILSON_HUNGER_RATE) end inst:WatchWorldState( "startday", function() updateHungerRate(inst, -.5) end ) inst:WatchWorldState( "startdusk", function() updateHungerRate(inst, .3) end ) inst:WatchWorldState( "startnight", function() updateHungerRate(inst, 2) end ) local mult = 0 if TheWorld.state.isday then mult = -.5 elseif TheWorld.state.isnight then mult = 2 end updateHungerRate(inst, mult) -- Emote for Meditating inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst:DoPeriodicTask(5.0, function() local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end end) end end) end Link to comment Share on other sites More sharing options...
Mitzimber Posted August 9, 2017 Author Share Posted August 9, 2017 Thank you so much! The game is no longer crashing. Unfortunately, when I do the sit emote, my character is not regaining life nor sanity. Is there something wrong with the emote code? Thanks again for all the help, and patience. Link to comment Share on other sites More sharing options...
alainmcd Posted August 9, 2017 Share Posted August 9, 2017 Try this instead: inst:ListenForEvent("emote", function(inst, data) if inst:HasTag("sit") then inst.emotetask = inst:DoPeriodicTask(5.0, function(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"}) for _,v in pairs(ents) do v.components.health:DoDelta(1) v.components.sanity:DoDelta(1) end inst.components.health:DoDelta(#ents) inst.components.sanity:DoDelta(#ents) end) end end) inst:ListenForEvent("locomote", function(inst) if inst.emotetask ~= nil then inst.emotetask:Cancel() end end) Untested. I added the DoDelta's for the character's health and sanity. The second listener checks for movement to cancel the perks, otherwise your character would keep gaining sanity and health infinitely. Link to comment Share on other sites More sharing options...
Mitzimber Posted August 9, 2017 Author Share Posted August 9, 2017 Ugh, that doesn't seem to work either. Sorry that I can't be of more help, I'm totally stumped at this point. Link to comment Share on other sites More sharing options...
alainmcd Posted August 10, 2017 Share Posted August 10, 2017 As far as I can tell there's no "sit" tag, use this instead: if data.anim[1][1] == "emote_pre_sit2" then Link to comment Share on other sites More sharing options...
Mitzimber Posted August 11, 2017 Author Share Posted August 11, 2017 That doesn't seem to work either. (Note: Sorry for the late response, school has been keeping me busy.) Link to comment Share on other sites More sharing options...
alainmcd Posted August 12, 2017 Share Posted August 12, 2017 The code I posted doesn't heal you or give you sanity unless there are other players nearby. I tried it* and it works. I haven't managed to cancel the perk, the character keeps healing up forever, so there's something wrong there. *I started a new game as Wilson and used these two commands in the console, then used the sit emote: for k, v in pairs(Ents) do if v.prefab == "wilson" then wilson = v break end end wilson:ListenForEvent("emote", function(inst, data) if data.anim[1][1] == "emote_pre_sit2" then inst.emotetask = inst:DoPeriodicTask(1, function(inst) inst.components.health:DoDelta(10) end) end end) 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