Jump to content

Recommended Posts

Hello, friends. Like a lot of people here I've got Ideas for character mods but am fairly coding illiterate without a super detailed tutorial telling me how to do something. I've been messing with this file for a few hours now and am finally willing to admit I have no idea what I'm doing and start from scratch.

 

Basically, what I would like to do for this character is:

 - have his sanity level influence his damage multiplier/speed/hunger drain

 - have the sound files associated with his speech change depending on his sanity level

 - set doing science to give negative sanity instead of positive sanity

 

I'm definitely not asking for someone to just come in and write the whole code for me, but any helpful pointers or barebones code frameworks would be much appreciated! Thanks much.

Link to comment
https://forums.kleientertainment.com/forums/topic/30215-coding-help-please/
Share on other sites

All I'm going to say should be inside the file of your character at this place

local fn = function(Sim)    local inst = CreateEntity()    -- All code hereend

 

- have his sanity level influence his damage multiplier/speed/hunger drain

You should take use of an EventCallback

inst:ListenForEvent("sanitydelta", function(inst, data)    if data.newpercent >= 0.5 then        --DoSomething    else        --DoSomethingElse    endend)

You can find examples for everything you want to do inside the files. Changing damagemultiplier, sanity, hunger, health is basiclly all inside "wolfgang.lua" and he uses a similiar technique for his hunger.

 

- have the sound files associated with his speech change depending on his sanity level

In the same vein you'll be able to just change the sound by using for example

inst.soundname = "wonka_sane"

You can use the exact same function you used above.

 

- set doing science to give negative sanity instead of positive sanity

I'm less certain about this one. I'd suggest to do something like this

local oldUnlockRecipe = inst.components.builder.UnlockRecipeinst.components.builder.UnlockRecipe = function(recname)    oldUnlockRecipe(inst.components.builder, recname)    if self.inst.components.sanity then        self.inst.components.sanity:DoDelta(-TUNING.SANITY_MED * 2)    endend

Essentially taking off the sanity again and removing even more. You can choose any multiplier bigger than 1 to tune the amount of sanity loss.

@simplex Sorry to summon you here, but I'm really curious if I can do it lke this. I was also thinking of the idea to change things like CollectSomeActions to make interaction with different prefabs of the same component different. In fact I got the idea because of the 'Clockwork Tooth Trap'. So is there anything conflicting with this code?

Aaaaaalright, I think I am doing something very wrong here. I copied what you gave me and have been messing with it all day, trying to get it to do what I'd like -- I haven't even got to the science effect retooling because both the voice and the stats changes are stubbornly refusing to work. I think it may be something to do with the fact that I'm using custom voice files? Though I couldn't make it work with game voice files either -- if I tried that, the character was completely silent. I'm just going to put up what I have so far -- pardon the art assets being only half-done, everything that needs to be there should be there. Chances are it's some very obvious error that I'm just not seeing.

 

https://dl.dropboxusercontent.com/u/110262078/Other/Theo.zip

Well, you weren't supposed to create a new function, sorry for not being clear there... This code works just fine

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" ),		-- Don't forget to include your character's custom assets!        Asset( "ANIM", "anim/the.zip" ),}local prefabs = {}local fn = function(inst)        inst.MiniMapEntity:SetIcon( "wilson.png" )        inst.components.health:SetMaxHealth(150)        inst.components.hunger:SetMax(200)        inst.components.sanity:SetMax(100)	inst:ListenForEvent("sanitydelta", function(inst, data)		if data.newpercent <= .5 then                        inst.soundsname = "wendy"			inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.6)			inst.components.combat.damagemultiplier = 3		else			inst.soundsname = "wolfgang"			inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.2)			inst.components.combat.damagemultiplier = 1.5		end	end)endreturn MakePlayerCharacter("the", prefabs, assets, fn)

And you remap the sound events in modmain and don't have to remap on each sanitydelta. Just make sure you remap two different sound events, one for "theosane" and one for "theoinsane".

aaAAAAH okay! Thanks a lot, I tried putting it in that function before and I must have done it incorrectly because it decided not to like me.

 

How would I go about telling the two sound events what the conditions are for each event? Would it be a similar sort of function, just in the modmain.lua?

In modmain you would do somtehing like this

Assets = {    --other assets    Asset("SOUNDPACKAGE", "sound/theinsane.fev"),    Asset("SOUND", "sound/theinsane.fsb"),    Asset("SOUNDPACKAGE", "sound/thesane.fev"),    Asset("SOUND", "sound/thesane.fsb"),}RemapSoundEvent( "dontstarve/characters/theinsane/death_voice", "theinsane/theinsane/death_voice" )RemapSoundEvent( "dontstarve/characters/theinsane/hurt", "theinsane/theinsane/hurt" )RemapSoundEvent( "dontstarve/characters/theinsane/talk_LP", "theinsane/theinsane/talk_LP" RemapSoundEvent( "dontstarve/characters/thesane/death_voice", "thesane/thesane/death_voice" )RemapSoundEvent( "dontstarve/characters/thesane/hurt", "thesane/thesane/hurt" )RemapSoundEvent( "dontstarve/characters/thesane/talk_LP", "thesane/thesane/talk_LP" 

Now you have two sets of sound you can use by doing

inst.soundsname = "theinsane"--Orinst.soundsname = "thesane"

Yay, it worked! And now I'll be able to do all this again in future. Thanks so much.

 

edit: Also, I know you were wondering about the sanity tuning code for unlocking recipes: i just tried it and it crashed my game, but I'll continue messing with it and report back.

Edited by misterinkwell

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