Jump to content

Recommended Posts

Hello I am a terrible coder(well, no experience). I have all the art down and just ready to release it on the steam workshop but I just cant do the coding part.

 

I would like to request two things: 

When eating berries, berries heal more.

When you spawn for the 1st time, you begin with a life amulet.

 

If anyone can help me it'd be much appreciated, and credits for the coding.

Thank you~

 

 

When you spawn for the 1st time, you begin with a life amulet.
Add "amulet" to start_inv in your character's prefab file:
local start_inv ={	"amulet",}

 

When eating berries, berries heal more.
Add this to your master_postinit in the character prefab file:
local OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) and food.prefab:find("berries") then        food.components.edible.healthvalue = food.components.edible.healthvalue + 5    end    return OldEat(self, food)end

That should work for both cooked and raw berries. If you want just one of them, change the food.prefab:find() part to food.prefab == "berries" or "berries_cooked".

Add "amulet" to start_inv in your character's prefab file:

local start_inv ={	"amulet",}
 

 

Add this to your master_postinit in the character prefab file:

local OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) and food.prefab:find("berries") then        food.components.edible.healthvalue = food.components.edible.healthvalue + 5    end    return OldEat(self, food)end
That should work for both cooked and raw berries. If you want just one of them, change the food.prefab:find() part to food.prefab == "berries" or "berries_cooked".

 

Man I feel kinda derpy. Berry problem.

So yesterday I was pasting the code into the lua but nothing seems to have changed. Everything works, it's just the berry effect wasn't happening. I'm 100% sure its probably because I pasted it in the wrong area.

 

I tried looking at similar character mods that may also have the code so I can use that as an example, but i guess i didn't search hard enough.

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/sugar.zip" ),        Asset( "ANIM", "anim/ghost_sugar_build.zip" ),}local prefabs = {	"bugnet",}local start_inv = {	-- Custom starting items	"bugnet",}-- This initializes for both clients and the hostlocal common_postinit = function(inst) 	-- Minimap icon	inst.MiniMapEntity:SetIcon( "sugar.tex" )end-- This initializes for the host onlylocal master_postinit = function(inst)	-- choose which sounds this character will play	inst.soundsname = "willow"	-- Stats		inst.components.health:SetMaxHealth(200)	inst.components.hunger:SetMax(100)	inst.components.sanity:SetMax(200)	inst.components.locomotor.walkspeed = 5.5	inst.components.locomotor.runspeed = 7.5	inst.components.sanity.night_drain_mult = .6	inst.components.sanity.neg_aura_mult = 1.4	local OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) and food.prefab:find("berries") then        food.components.edible.healthvalue = food.components.edible.healthvalue + 50    end    return OldEat(self, food)endendreturn MakePlayerCharacter("sugar", prefabs, assets, common_postinit, master_postinit, start_inv)

Sorry for the inconvience, but if you could tell me how to properly place it, it'd be helpful.

@rons0n, That looks like it should be working to me... I added it to Wilson's prefab just now and it worked... 

 

For some reason my game hates me I guess x_x

 

Well to make sure it wasn't my character wasn't the cause i decided to go to Wilson's prefab and do the same thing. Nothing crashes but also the berry effect still wasnt taking place.

 

What I did was eat spoiled food to decrease his hunger than eat berries to see if it goes higher than usual, but i don't see much of a difference. That and I made the healthvalue + 500.

 

Maybe im overlooking something?

Add "amulet" to start_inv in your character's prefab file:

local start_inv ={	"amulet",}
Add this to your master_postinit in the character prefab file:
local OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) and food.prefab:find("berries") then        food.components.edible.healthvalue = food.components.edible.healthvalue + 5    end    return OldEat(self, food)end

That should work for both cooked and raw berries. If you want just one of them, change the food.prefab:find() part to food.prefab == "berries" or "berries_cooked".

 

can you also use this for say, monster meat(cooked and raw) and Monster lasagna? 

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
×
  • Create New...