Jump to content

[Help] Need help making a few character perks


Recommended Posts

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

-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 by rezecib
Link to comment
Share on other sites

	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

This is the modmain for the character picking and gaining sanity.

  1. PrefabFiles = {
  2. "sparky",
  3. }
  4.  
  5. Assets = {
  6.     Asset( "IMAGE", "images/saveslot_portraits/sparky.tex" ),
  7.     Asset( "ATLAS", "images/saveslot_portraits/sparky.xml" ),
  8.  
  9.     Asset( "IMAGE", "images/selectscreen_portraits/sparky.tex" ),
  10.     Asset( "ATLAS", "images/selectscreen_portraits/sparky.xml" ),
  11.  
  12.     Asset( "IMAGE", "images/selectscreen_portraits/sparky_silho.tex" ),
  13.     Asset( "ATLAS", "images/selectscreen_portraits/sparky_silho.xml" ),
  14.  
  15.     Asset( "IMAGE", "bigportraits/sparky.tex" ),
  16.     Asset( "ATLAS", "bigportraits/sparky.xml" ),
  17.  
  18. Asset( "IMAGE", "images/map_icons/sparky.tex" ),
  19. Asset( "ATLAS", "images/map_icons/sparky.xml" ),
  20.  
  21. Asset( "IMAGE", "images/avatars/avatar_sparky.tex" ),
  22.     Asset( "ATLAS", "images/avatars/avatar_sparky.xml" ),
  23.  
  24. Asset( "IMAGE", "images/avatars/avatar_ghost_sparky.tex" ),
  25.     Asset( "ATLAS", "images/avatars/avatar_ghost_sparky.xml" ),
  26.  
  27. }
  28.  
  29. local require = GLOBAL.require
  30. local STRINGS = GLOBAL.STRINGS
  31.  
  32. -- The character select screen lines
  33. STRINGS.CHARACTER_TITLES.sparky = "The silly wuff"
  34. STRINGS.CHARACTER_NAMES.sparky = "Sparky"
  35. STRINGS.CHARACTER_DESCRIPTIONS.sparky = "*Loves collecting\n*Is adorable\n*Loves berries"
  36. STRINGS.CHARACTER_QUOTES.sparky = "\"BERRIES!!!\""
  37.  
  38. -- Custom speech strings
  39. STRINGS.CHARACTERS.SPARKY = require "speech_sparky"
  40.  
  41. -- The character's name as appears in-game 
  42. STRINGS.NAMES.sparky = "Sparky"
  43.  
  44. -- The default responses of examining the character
  45. STRINGS.CHARACTERS.GENERIC.DESCRIBE.sparky = 
  46. {
  47. GENERIC = "It's sparky!",
  48. ATTACKER = "That sparky looks shifty...",
  49. MURDERER = "Murderer!",
  50. REVIVER = "sparky, friend of ghosts.",
  51. GHOST = "sparky could use a heart.",
  52. }
  53.  
  54. -- Let the game know character is male, female, or robot
  55. table.insert(GLOBAL.CHARACTER_GENDERS.MALE, "sparky")
  56.  
  57. local pick_sanity = {
  58.     berrybush = 5,
  59.     grass = 1,
  60.     sapling = 1,
  61.     reeds = 1
  62. }
  63.  
  64. for k, v in pairs(pick_sanity) do
  65.     AddPrefabPostInit(k, function(inst)
  66.         local old = inst.components.pickable.onpickedfn
  67.         inst.components.pickable.onpickedfn = function(inst, picker)
  68.             old(inst, picker)
  69.             if picker.prefab == "Sparky" then
  70.                 picker.components.sanity:DoDelta(v)
  71.             end
  72.         end
  73.     end)
  74. end
  75.  
  76. AddMinimapAtlas("images/map_icons/sparky.xml")
  77. AddModCharacter("sparky")

 

And the character LUA for the kill sanity

  1. local MakePlayerCharacter = require "prefabs/player_common"
  2.  
  3.  
  4. local assets = {
  5.  
  6. Asset( "ANIM", "anim/player_basic.zip" ),
  7. Asset( "ANIM", "anim/player_idles_shiver.zip" ),
  8. Asset( "ANIM", "anim/player_actions.zip" ),
  9. Asset( "ANIM", "anim/player_actions_axe.zip" ),
  10. Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
  11. Asset( "ANIM", "anim/player_actions_shovel.zip" ),
  12. Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
  13. Asset( "ANIM", "anim/player_actions_eat.zip" ),
  14. Asset( "ANIM", "anim/player_actions_item.zip" ),
  15. Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
  16. Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
  17. Asset( "ANIM", "anim/player_actions_fishing.zip" ),
  18. Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
  19. Asset( "ANIM", "anim/player_bush_hat.zip" ),
  20. Asset( "ANIM", "anim/player_attacks.zip" ),
  21. Asset( "ANIM", "anim/player_idles.zip" ),
  22. Asset( "ANIM", "anim/player_rebirth.zip" ),
  23. Asset( "ANIM", "anim/player_jump.zip" ),
  24. Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
  25. Asset( "ANIM", "anim/player_teleport.zip" ),
  26. Asset( "ANIM", "anim/wilson_fx.zip" ),
  27. Asset( "ANIM", "anim/player_one_man_band.zip" ),
  28. Asset( "ANIM", "anim/shadow_hands.zip" ),
  29. Asset( "SOUND", "sound/sfx.fsb" ),
  30. Asset( "SOUND", "sound/wilson.fsb" ),
  31. Asset( "ANIM", "anim/beard.zip" ),
  32.  
  33. -- Don't forget to include your character's custom assets!
  34. Asset( "ANIM", "anim/echo.zip" ),
  35. Asset( "ANIM", "anim/ghost_echo_build.zip" ),
  36. }
  37. local prefabs = {}
  38. local start_inv = {
  39. -- Custom starting items
  40. }
  41.  
  42. -- This initializes for both clients and the host
  43. local common_postinit = function(inst)
  44. -- Minimap icon
  45. inst.MiniMapEntity:SetIcon( "echo.tex" )
  46. end
  47.  
  48. local function resetLocomotor(inst)
  49. inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2)
  50. inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2)
  51. inst.components.combat.damagemultiplier = 2
  52. end
  53.  
  54. local function updatestats(inst)
  55.  
  56. if TheWorld.state.phase == "day" then
  57. inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * -5)
  58.  
  59. elseif TheWorld.state.phase == "dusk" then
  60. inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 3)
  61.  
  62. elseif TheWorld.state.phase == "night" then
  63. inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 8)
  64.  
  65. end
  66.  
  67. end
  68.  
  69. local function on_entity_death(world, data)
  70.     if data.afflicter == inst then
  71.         inst.components.sanity:DoDelta(10)
  72.     end
  73. end
  74.  
  75.  
  76. -- This initializes for the host only
  77. local master_postinit = function(inst)
  78. -- choose which sounds this character will play
  79. inst.soundsname = "wilson"
  80. -- Stats
  81. inst.components.health:SetMaxHealth(300)
  82. inst.components.hunger:SetMax(200)
  83. inst.components.sanity:SetMax(100)
  84. inst.components.combat.damagemultiplier = 2
  85. inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2)
  86. inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2)
  87. inst:ListenForEvent("ms_respawnedfromghost", resetLocomotor)
  88. inst:WatchWorldState( "startday", function(inst) updatestats(inst) end )
  89. inst:WatchWorldState( "startdusk", function(inst) updatestats(inst) end )
  90. inst:WatchWorldState( "startnight", function(inst) updatestats(inst) end )
  91. updatestats(inst)
  92. return inst
  93. end
  94.  
  95. inst:ListenForEvent("entity_death", on_entity_death, TheWorld)
  96.  
  97. return MakePlayerCharacter("echo", prefabs, assets, common_postinit, master_postinit, start_inv)
Link to comment
Share on other sites

@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...