LynxETurner Posted March 13, 2015 Share Posted March 13, 2015 Good evening, I've been searching for over an hour now but cant find what I need for 2 custom characters I'm working on. I need help with some perks. What I'm looking for are:-Code to gain sanity of 5 points when harvesting berries, 1 point when picking grass, sapling and reeds.-Code to gain sanity of 10 points on kill. Thanks for any help in advance. Link to comment Share on other sites More sharing options...
rezecib Posted March 13, 2015 Share Posted March 13, 2015 (edited) -Code to gain sanity of 5 points when harvesting berries, 1 point when picking grass, sapling and reeds.In your modmain:pick_sanity ={ berrybush = 5, grass = 1, sapling = 1, reeds = 1}for k,v in pairs(pick_sanity) do AddPrefabPostInit(k, function(inst) if not GLOBAL.TheWorld.ismastersim then return end local old_onpickedfn = inst.components.pickable.onpickedfn inst.components.pickable.onpickedfn = function(inst, picker) old_onpickedfn(inst, picker) if picker.prefab == "mycharprefab" then picker.components.sanity:DoDelta(v) end end end)end -Code to gain sanity of 10 points on kill. In your character's master_postinit:local function on_entity_death(world, data) if data.afflicter == inst then inst.components.sanity:DoDelta(10) endendinst:ListenForEvent("entity_death", on_entity_death, TheWorld) Edited March 13, 2015 by rezecib Link to comment Share on other sites More sharing options...
LynxETurner Posted March 13, 2015 Author Share Posted March 13, 2015 Unfortunately the Kill code crashed the mod the moment I enabled it and the other didn't seem to do anything. Sanity remained unaffected at harvesting any of the plants listed. Link to comment Share on other sites More sharing options...
DarkXero Posted March 13, 2015 Share Posted March 13, 2015 inst:ListenForEvent("killed", function(inst, data) if not data.victim:HasTag("wall") and inst.components.sanity then inst.components.sanity:DoDelta(5) end end)In your master_postinit also works. And rezecib pick code works, did you change the mycharprefab into your prefab's name?Like:local pick_sanity = { berrybush = 5, grass = 1, sapling = 1, reeds = 1}for k, v in pairs(pick_sanity) do AddPrefabPostInit(k, function(inst) local old = inst.components.pickable.onpickedfn inst.components.pickable.onpickedfn = function(inst, picker) old(inst, picker) if picker.prefab == "wilson" then picker.components.sanity:DoDelta(v) end end end)end Link to comment Share on other sites More sharing options...
rezecib Posted March 13, 2015 Share Posted March 13, 2015 @LynxETurner, Show us the files where you put the code, both of them definitely work if you place them correctly. Link to comment Share on other sites More sharing options...
LynxETurner Posted March 13, 2015 Author Share Posted March 13, 2015 This is the modmain for the character picking and gaining sanity.PrefabFiles = { "sparky", } Assets = { Asset( "IMAGE", "images/saveslot_portraits/sparky.tex" ), Asset( "ATLAS", "images/saveslot_portraits/sparky.xml" ), Asset( "IMAGE", "images/selectscreen_portraits/sparky.tex" ), Asset( "ATLAS", "images/selectscreen_portraits/sparky.xml" ), Asset( "IMAGE", "images/selectscreen_portraits/sparky_silho.tex" ), Asset( "ATLAS", "images/selectscreen_portraits/sparky_silho.xml" ), Asset( "IMAGE", "bigportraits/sparky.tex" ), Asset( "ATLAS", "bigportraits/sparky.xml" ), Asset( "IMAGE", "images/map_icons/sparky.tex" ), Asset( "ATLAS", "images/map_icons/sparky.xml" ), Asset( "IMAGE", "images/avatars/avatar_sparky.tex" ), Asset( "ATLAS", "images/avatars/avatar_sparky.xml" ), Asset( "IMAGE", "images/avatars/avatar_ghost_sparky.tex" ), Asset( "ATLAS", "images/avatars/avatar_ghost_sparky.xml" ), } local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS -- The character select screen lines STRINGS.CHARACTER_TITLES.sparky = "The silly wuff" STRINGS.CHARACTER_NAMES.sparky = "Sparky" STRINGS.CHARACTER_DESCRIPTIONS.sparky = "*Loves collecting\n*Is adorable\n*Loves berries" STRINGS.CHARACTER_QUOTES.sparky = "\"BERRIES!!!\"" -- Custom speech strings STRINGS.CHARACTERS.SPARKY = require "speech_sparky" -- The character's name as appears in-game STRINGS.NAMES.sparky = "Sparky" -- The default responses of examining the character STRINGS.CHARACTERS.GENERIC.DESCRIBE.sparky = { GENERIC = "It's sparky!", ATTACKER = "That sparky looks shifty...", MURDERER = "Murderer!", REVIVER = "sparky, friend of ghosts.", GHOST = "sparky could use a heart.", } -- Let the game know character is male, female, or robot table.insert(GLOBAL.CHARACTER_GENDERS.MALE, "sparky") local pick_sanity = { berrybush = 5, grass = 1, sapling = 1, reeds = 1 } for k, v in pairs(pick_sanity) do AddPrefabPostInit(k, function(inst) local old = inst.components.pickable.onpickedfn inst.components.pickable.onpickedfn = function(inst, picker) old(inst, picker) if picker.prefab == "Sparky" then picker.components.sanity:DoDelta(v) end end end) end AddMinimapAtlas("images/map_icons/sparky.xml") AddModCharacter("sparky") And the character LUA for the kill sanitylocal 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" ), -- Don't forget to include your character's custom assets! Asset( "ANIM", "anim/echo.zip" ), Asset( "ANIM", "anim/ghost_echo_build.zip" ), } local prefabs = {} local start_inv = { -- Custom starting items } -- This initializes for both clients and the host local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "echo.tex" ) end local function resetLocomotor(inst) inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2) inst.components.combat.damagemultiplier = 2 end local function updatestats(inst) if TheWorld.state.phase == "day" then inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * -5) elseif TheWorld.state.phase == "dusk" then inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 3) elseif TheWorld.state.phase == "night" then inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 8) end end local function on_entity_death(world, data) if data.afflicter == inst then inst.components.sanity:DoDelta(10) end end -- This initializes for the host only local master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "wilson" -- Stats inst.components.health:SetMaxHealth(300) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(100) inst.components.combat.damagemultiplier = 2 inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2) inst:ListenForEvent("ms_respawnedfromghost", resetLocomotor) inst:WatchWorldState( "startday", function(inst) updatestats(inst) end ) inst:WatchWorldState( "startdusk", function(inst) updatestats(inst) end ) inst:WatchWorldState( "startnight", function(inst) updatestats(inst) end ) updatestats(inst) return inst end inst:ListenForEvent("entity_death", on_entity_death, TheWorld) return MakePlayerCharacter("echo", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment Share on other sites More sharing options...
LynxETurner Posted March 13, 2015 Author Share Posted March 13, 2015 Looking back at the second code I prolly made the mistake of putting the last line AFTER the "end" part. Link to comment Share on other sites More sharing options...
rezecib Posted March 13, 2015 Share Posted March 13, 2015 @LynxETurner, Prefab names cannot have capital letters, so the sanity will never work because you are using "Sparky". I'd guess it should be "sparky". And you are correct, the inst:ListenForEvent should be inside the master_postinit (before the return statement, actually), not after it. The function on_entity_death also needs to be defined inside the master_postinit so it will have access to the "inst" variable. Link to comment Share on other sites More sharing options...
LynxETurner Posted March 13, 2015 Author Share Posted March 13, 2015 I corrected all my mistakes now and they both work perfectly now. Many thanks for your help. 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