Jump to content

Custom Character Scripting Help


Recommended Posts

I'm working on a custom character for a friend and ultimately will be making one for myself and was wondering if anyone could help me come up with a few scripts for perks.

 

The character has 3 perks

-------------------------------

Perk #1: Wild Carnivore: Ability to consume raw foods for an extra increase on health and hunger,

but with a decrease on sanity. This applies to meat based foods only, while plant matter will harm health and sanity while still filling hunger.

 

Perk #2: Cat Nap: While sleeping in a bedroll this character has half the normal hunger drain,

and bedrolls can be used twice instead of once. Random chance of passing out due to low sanity

with hunger and health decrease without a bedroll.

 

Perk #3: Hunter: Ok this will flat out with no doubt be the hardest to do. Allows hunting and catching rabbits barehand no traps. Allows for character to get close to animals and prey without sending them screaming away. Chance of catching birds barehanded ~15%-20% chance.

-----------------------------

I'm not gonna lie I'm new to coding and scripting. I've had some experience with similar languages ie. python, But this is different never made a character mod like this before any help is much appreciated

 

-Arashi

Link to comment
Share on other sites

Perk #1: Wild Carnivore
 Adding this to your character's master_postinit should do it:
local OldEat = inst.components.eater.Eatinst.components.eater.Eat = function(self, food)    if self:CanEat(food) then        if food:HasTag("meat") and not( food.prefab:find("cooked") or food.prefab:find("dried") ) then            food.components.edible.hungervalue = 1.1*food.components.edible.hungervalue            food.components.edible.healthvalue = food.components.edible.healthvalue + 10        elseif food:HasTag("veggie") then            food.components.edible.healthvalue = -10            food.components.edible.sanityvalue = -10        end    end    return OldEat(self, food)end

You might want to change the math depending on the specifics of how you want the increases/penalties to work.

 

Perk #2: Cat Nap:
This honestly looks pretty hard to implement, and like it would be very messy-- you'd have to adjust the SGWilson stategraph states, add custom saving information to bedrolls, etc...

 

Perk #3: Hunter:
I think this one is easy. Just put this in the common_postinit:
inst:RemoveTag("scarytoprey")

I'm kinda thinking this character needs some downsides, though :p

Link to comment
Share on other sites

Thank you. I've got the code in, but I can not seem to get either perk to work is there something I'm missing?

 

[/script][codesyntax]-- This initializes for both clients and the host

local common_postinit = function(inst)
-- Minimap icon
inst.MiniMapEntity:SetIcon( "machete.tex" )
-- Hunter Perk
inst:RemoveTag("scarytoprey")
end

-- This initializes for the host only
local master_postinit = function(inst)
-- choose which sounds this character will play
inst.soundsname = "wolfgang"
-- Stats
inst.components.health:SetMaxHealth(200)
inst.components.hunger:SetMax(150)
inst.components.sanity:SetMax(250)
--Wild Carnivore Perk
local OldEat = inst.components.eater.Eat
inst.components.eater.Eat = function(self, food)
if self:CanEat(food) then
if food:HasTag("meat") and not( food.prefab:find("cooked") or food.prefab:find("dried") ) then
food.components.edible.hungervalue = 1.1*food.components.edible.hungervalue
food.components.edible.healthvalue = food.components.edible.healthvalue + 10
elseif food:HasTag("veggie") then
food.components.edible.healthvalue = -25
food.components.edible.sanityvalue = -25
end
end
return OldEat(self, food)
end

end[/codesyntax]

Link to comment
Share on other sites

@ArashiOtter, Try changing this line


elseif food:HasTag("veggie") then

to this:

elseif food.components.edible.foodtype == FOODTYPE.VEGGIE then

Edit: Oh, hmm... looks like birds specifically check for both the player and scarytoprey tag (also the monster tag). I'm not really familiar with modifying brains...

Edited by rezecib
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...