Jump to content

Recommended Posts

Alright, I'm new here so if there is anything missing please tell me but, I'm currently working on a custom character that will transform when sanity is at, or below, 11. The problem is that whenever I enable the mod the game doesn't necessarily crash, but instead freezes. Any advice will be useful.

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/trent.zip" ),        Asset( "ANIM", "anim/ghost_trent_build.zip" ),		Asset( "ANIM", "anim/trent_form.zip" ),}local prefabs = {}local start_inv = {	"multitool_axe_pickaxe",	"goldenshovel",	"nightsword",	}local function becometrent(inst)        inst.AnimState:SetBuild("trent")         inst.components.health:SetMaxHealth(150)         inst.components.hunger:SetMax(200)         inst.components.sanity:SetMax(80)         inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)				inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1)				inst.components.sanity.night_drain_mult = 0.5				inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05)				inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05)end  local function becometrent_form(inst)        inst.AnimState:SetBuild("trent_form")				inst.Transform:SetScale(1.4, 1.4, 1.4)         inst.components.health:SetMaxHealth(200)         inst.components.hunger:SetMax(200)         inst.components.sanity:SetMax(133)         inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.25)				inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1.5)				inst.components.sanity.night_drain_mult = 0.5			inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.3)			inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.3)end local function sanitychange(inst, data)         if inst.components.sanity.current < 11 then                becomebody(inst)        else                becomehed(inst)        end end local fn = function(inst)-- This initializes for both clients and the hostlocal common_postinit = function(inst) 	-- Minimap icon	inst.MiniMapEntity:SetIcon( "trent.tex" )end-- This initializes for the host onlylocal master_postinit = function(inst)	-- choose which sounds this character will play	inst.soundsname = "trent"	-- Stats		inst.components.health:SetMaxHealth(150)	inst.components.hunger:SetMax(200)	inst.components.sanity:SetMax(80)	inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1)	inst.components.sanity.night_drain_mult = 0.5	inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05)	inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05)		inst:ListenForEvent("sanitydelta", sanitychange)endreturn MakePlayerCharacter("trent", prefabs, assets, common_postinit, master_postinit, start_inv)

 

 

Where are the becomebody and becomehed functions defined?

That's what fixed the freezing, since I changed it to becometrent and becometrent_form, but now I get a different error relating to common_postinit

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/trent.zip" ),        Asset( "ANIM", "anim/ghost_trent_build.zip" ),        Asset( "ANIM", "anim/trent_form.zip" ),}local prefabs = {}local start_inv = {	"multitool_axe_pickaxe",	"goldenshovel",	"nightsword",	}local function becometrent(inst)		inst.AnimState:SetBuild("trent") 		inst.components.health:SetMaxHealth(150) 		inst.components.hunger:SetMax(200) 		inst.components.sanity:SetMax(80) 		inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)				inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE				inst.components.sanity.night_drain_mult = 0.5				inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05)				inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05)end  local function becometrent_form(inst)        inst.AnimState:SetBuild("trent_form")				inst.Transform:SetScale(1.5, 1.5, 1.5) 		inst.components.health:SetMaxHealth(200) 		inst.components.hunger:SetMax(200) 		inst.components.sanity:SetMax(133) 		inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.25)				inst.components.sanity.dapperness = (TUNING.DAPPERNESS_HUGE * 1.5)				inst.components.sanity.night_drain_mult = 0.5			inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.3)			inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.3)end local function sanitychange(inst, data)        if inst.components.sanity.current < 10 then                becometrent_form(inst)        else                becometrent(inst)        end end local fn = function(inst)-- This initializes for both clients and the hostlocal common_postinit = function(inst) 	-- Minimap icon	inst.MiniMapEntity:SetIcon( "trent.tex" )	end	end-- This initializes for the host onlylocal master_postinit = function(inst)	-- choose which sounds this character will play	inst.soundsname = "trent"	-- Stats		inst.components.health:SetMaxHealth(150)		inst.components.hunger:SetMax(200)		inst.components.sanity:SetMax(80)		inst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE		inst.components.sanity.night_drain_mult = 0.5		inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.05)		inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.05)		inst:ListenForEvent("sanitydelta", sanitychange)endreturn MakePlayerCharacter("trent", nil, prefabs, assets, fn, common_postinit, master_postinit, start_inv)
1045: bad argument #1 to 'ipairs' (table expected, got function)

 There should be a filename just before this part of the error. This will tell you what file to look in, and that it's line 1045 in that file.

 

Edit: But your problem is here:

MakePlayerCharacter("trent", nil, prefabs, assets, fn, common_postinit, master_postinit, start_inv)

 

Go look at the arguments to the MakePlayerCharacter function in scripts/prefabs/player_common. You have too many there.

Edited by rezecib

 There should be a filename just before this part of the error. This will tell you what file to look in, and that it's line 1045 in that file.

 

Edit: But your problem is here:

 

 

 

Go look at the arguments to the MakePlayerCharacter function in scripts/prefabs/player_common. You have too many there.

Yes. I know but, in there all it says is

 if starting_inventory ~= nil then        for i, v in ipairs(starting_inventory) do            table.insert(prefabs, v)        end    end 
and I'm not sure what to do with this.

@ELEMENTALCRAFTER009, Yes, so that's where it's crashing. But scroll up and you'll see this, which is what I told you to look at.

local function MakePlayerCharacter(name, customprefabs, customassets, common_postinit, master_postinit, starting_inventory)
Edited by rezecib

 

@ELEMENTALCRAFTER009, Yes, so that's where it's crashing. But scroll up and you'll see this, which is what I told you to look at.

local function MakePlayerCharacter(name, customprefabs, customassets, common_postinit, master_postinit, starting_inventory)

Alright, now it doesn't crash immediately. However, it does crash whenever I join a world and shows this error screen.post-402862-0-59090700-1423270443_thumb. 

 

@ELEMENTALCRAFTER009, Try using Wolfgang's method of setting max health instead.

I used Wolfgang's method for setting stats and it doesn't change the stats at all

 

local health_max = 150
 
local hunger_max = 200
 
local sanity_max = 80
 
I also tried (TUNING.WILSON_insertstat)

@ELEMENTALCRAFTER009, Hmm, well, it's not obvious to me why it's running into a stack overflow like that, but you can certainly reduce the number of times your function is running by a huge margin, if you change your code to this:

local function sanitychange(inst, data)        if inst.components.sanity.current < 10 and not inst.trentform then                becometrent_form(inst)        elseif inst.trentform then                becometrent(inst)        end end

Then, at the beginning of becometrent set inst.trentform = false, and at the beginning of becometrent_form, set inst.trentform = true. This means that it'll only run the transformation functions when the sanitychange means that he should be switching.

 

That being said, it's probably a good idea to have "stickiness" to the transition, by setting the threshold for trent->trentform a little lower than the threshold for trentform -> trent. This way you don't run into any flickering at the transition point.

 

But I'm not very confident this will solve the immediate issue...

 

Edit: You probably also want to be setting the scale in both transformation functions, otherwise your character will become irreversibly stuck at 1.5 scale.

Edited by rezecib

@ELEMENTALCRAFTER009, Hmm, well, it's not obvious to me why it's running into a stack overflow like that, but you can certainly reduce the number of times your function is running by a huge margin, if you change your code to this:

local function sanitychange(inst, data)        if inst.components.sanity.current < 10 and not inst.trentform then                becometrent_form(inst)        elseif inst.trentform then                becometrent(inst)        end end

Then, at the beginning of becometrent set inst.trentform = false, and at the beginning of becometrent_form, set inst.trentform = true. This means that it'll only run the transformation functions when the sanitychange means that he should be switching.

 

That being said, it's probably a good idea to have "stickiness" to the transition, by setting the threshold for trent->trentform a little lower than the threshold for trentform -> trent. This way you don't run into any flickering at the transition point.

 

But I'm not very confident this will solve the immediate issue...

 

Edit: You probably also want to be setting the scale in both transformation functions, otherwise your character will become irreversibly stuck at 1.5 scale.

So I would change

local function becometrent_form(inst)        inst.AnimState:SetBuild("trent_form")				inst.Transform:SetScale(1.5, 1.5, 1.5)

to

local function becometrent_form(inst)		inst.trentform = true        inst.AnimState:SetBuild("trent_form")				inst.Transform:SetScale(1.5, 1.5, 1.5)

for both becometrent and becometrent_form.

 

EDIT: and is inst.trentform supposed to be inst.trent_form or not? Also, stats are still not functioning properly so should I add this somewhere?

 

inst.components.health:SetMaxHealth(health_max)

inst.components.hunger:SetMaxHunger(hunger_max)
inst.components.sanity:SetMaxSanity(sanity_max)
Edited by ELEMENTALCRAFTER009
EDIT: and is inst.trentform supposed to be inst.trent_form or not?
 It shouldn't matter, you just have to give it a name and make sure you use the same name for that boolean value everywhere.

 

As for the stats, I think you have them everywhere you need them.

 It shouldn't matter, you just have to give it a name and make sure you use the same name for that boolean value everywhere.

 

As for the stats, I think you have them everywhere you need them.

 

Is there anything that could fix the stats then?

 

EDIT: New bug when sanity is below the set value, it flickers back and forth between trent and trent_form regardless if it is at or below.

Edited by ELEMENTALCRAFTER009
  • Developer
Hmm, well, it's not obvious to me why it's running into a stack overflow like that,

 

Hmmm, seems to me that sanity change message causes sanitychange to be called, which causes one of the setform's to be called which sets maxsanity, which calls sanity:DoDelta which fires a sanity change message, which calls sanitychange, which.....and down the rabbithole we go.

 

You should only call setform if the oldpercentage is one one side of the treshold and the new on the other, or indeed as you suggested, check the form beforehand.

 

I know your suggestion works, but just wanted to point out the stack overflow seems logical to me.

 

That being said, it's probably a good idea to have "stickiness" to the transition, by setting the threshold for trent->trentform a little lower than the threshold for trentform -> trent. This way you don't run into any flickering at the transition point.

Now how would I go about doing this? since , again,  I'm new to DST and especially modding. And thank you for all the help you've given me

Edited by ELEMENTALCRAFTER009
  • Developer

By having a treshold for going into the form, and another one for going out of it. The range inbetween the character will stay whatever he was when entering that range. So if sanity fluctuates around one of the treshold the character doesn't transform back and forth.

local becomeformtreshold = 10local unbecomeformtreshold = 20if inst.components.sanity.current < becomeformtreshold and not inst.trentform then        becometrent_form(inst)elseif inst.components.sanity.current > unbecomeformtreshold and inst.trentform then        becometrent(inst)end

 

 

By having a treshold for going into the form, and another one for going out of it. The range inbetween the character will stay whatever he was when entering that range. So if sanity fluctuates around one of the treshold the character doesn't transform back and forth.

local becomeformtreshold = 10local unbecomeformtreshold = 20if inst.components.sanity.current < becomeformtreshold and not inst.trentform then        becometrent_form(inst)elseif inst.components.sanity.current > unbecomeformtreshold and inst.trentform then        becometrent(inst)end

Variable 'inst' is not declared.

 

EDIT: Nvm fixed it XD

 

Edited by ELEMENTALCRAFTER009
Variable 'inst' is not declared.
Then you made a mistake somewhere, and aren't passing inst to the function or something. But "inst is not declared" is not something that can arise from that code, because it would run into "attempt to index inst" first. Also, try not to type your replies inside of the quote... it's a bit confusing. 

New bug again. trent will transform into trent_from and then will turn back to trent at the unbecomeformtreshold, but won't transform back into trent_form at the becomeformtreshold again.

Edited by ELEMENTALCRAFTER009

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