Jump to content

Hey there! Inexperienced modder in need of help.


Recommended Posts

I've picked up a bunch from various tutorial videos on what to do to make a character, and over the past few days i've been making textures and setting stats, finally coming to the point where i am entirely stuck on how to handle this.

 

my problem? eating rocks. But not just rocks, gems, red blue purple, etc. gold and moonstone too. I'd like to make my character level up after eating one of five items,

 

*Red Gem

*Blue Gem

*Purple Gem

*Moonstone

*Gold Nugget

 

The item doesnt need to nourish me in any way beyond leveling me up- of which i've already set up using lvlup code similar to wx78's (although i'd definately appreciate it if someone could help me with that), but i've come to the point where i'm stumped and cannot work out how to make it work.

 

tl:dr need help allowing my character to level up from eating rocks. i've handled the lvlup system but cant get him to eat specific items that a normal character otherwise couldnt eat. Can anyone help?

 

Again, i'm reasonably new to modding so if replies could be dumbed down for me, that'd be great. 

 

Thanks in advance.

Link to comment
Share on other sites

@Neil2251, all of the things you mentioned are FOODTYPE.ELEMENTAL.

 

So the easiest way would be to add:

-- outside master_postinitlocal leveleritems = {	redgem = true,	bluegem = true,	purplegem = true,	moonrocknugget = true,	goldnugget = true,}local function oneat(inst, food)	if food and leveleritems[food.prefab] then		inst.level = inst.level + 1	endend-- now inside master_postinitinst.components.eater:SetOnEatFn(oneat)inst.components.eater:SetDiet({ FOODGROUP.OMNI, FOODTYPE.ELEMENTAL })

Your character could be able to eat rocks and nitre, but those wouldn't level him up.

 

 

If you want to go an extra mile and make only those edible for your character, then:

-- all of this in modmain-- our charlocal mychar = "wilson"-- the valid level up items (prefabs)local leveleritems = {	redgem = true,	bluegem = true,	purplegem = true,	moonrocknugget = true,	goldnugget = true,}-- The action that will take place when eating-- Thing being eaten is destroyed, guy eating levels up-- This special eating will be called PROCESSlocal function ProcessFn(act)	if act.doer and act.doer.prefab == mychar then		local obj = act.target or act.invobject		if leveleritems[obj.prefab] then			obj:Remove()			act.doer.level = act.doer.level + 1			return true		end	endendAddAction("PROCESS", "Eat", ProcessFn)local ACTIONS = GLOBAL.ACTIONSlocal ActionHandler = GLOBAL.ActionHandler-- We will use the meat eating animation for displaying the action-- The meat eating animation is used on the "eat" state of the wilson stategraph-- All chars use the wilson stategraphlocal processhandler = ActionHandler(ACTIONS.PROCESS, "eat")AddStategraphActionHandler("wilson", processhandler)-- We need to give the process action to these items when they are in inventory-- We can create a unique component and attach it to all the objects-- But since they have the inspectable component, we may as well hook to itlocal function EatLevelers(inst, doer, actions)	if inst and leveleritems[inst.prefab] then		if doer and doer.prefab == mychar then			table.insert(actions, ACTIONS.PROCESS)		end	endendAddComponentAction("INVENTORY", "inspectable", EatLevelers)
Link to comment
Share on other sites

Brilliant! only one question though; what is "-- outside master_postinit"? i'm just a bit confused because I see that term mentioned a lot but don't actually know what it is, or where it's located. Does it tend to go by a different name?

 

 

Again, thanks in advance.

Link to comment
Share on other sites

@Neil2250, master_postinit is the name of a function.

http://steamcommunity.com/sharedfiles/filedetails/?id=361202313

Here's the template most people use for DST.

 

The character's prefab lua file has that function with that name.

 

Character prefabs need to import the base code of a character.

This is done getting the function supplied by the file player_common:

local MakePlayerCharacter = require("prefabs/player_common")

This function takes parameters:

MakePlayerCharacter(name, -- The prefab name, e.g "wilson"customprefabs, -- The prefabs that have to be loaded with yours, e.g "beardhair"customassets, -- The assets of your character, e.g Asset("ANIM", "anim/wilson.zip")common_postinit,-- This function will run server side and client side on the prefab generation-- Needed for net variables, so client can access a net variable to get info,-- and the server can edit it to propagate infomaster_postinit, -- This function will run server side only-- You edit stuff like sanity or hunger rates, only the server needs to know-- Because it does the calculations itselfstarting_inventory) -- The items your character will start with

It's kept as master_postinit as a reference for people.

So they know where to put the code, in the server side only function, of the character they are working with.

 

It's not mandatory to name it that, Wolfgang has one named master_init, for example.

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...