Jump to content

[Scripting] Talker


Recommended Posts

Hey yall, me again. I swear the amount of times I ask for help is very minute in comparison to all the things i've figured out by sweat xD

 

Anyways, so i've gotten this code to work when equipping my weapon. So I know it works.

 

 

inst:AddComponent("talker")

inst.components.talker:Say("At last! My arm is complete again!")
inst.components.talker.fontsize = 28 
inst.components.talker.font = TALKINGFONT
inst.components.talker.colour = Vector3(10, 0, 0, 0)
inst.components.talker.offset = Vector3(0,0,100)
inst.components.talker.symbol = "swap_object"

 

My character "transforms" when his sanity is <30. This works, but when he does to the <30 anim I wan't him to say something.

 

I've used this

 

 

 

 
local function becomebody(inst)
 
inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * .7)
inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD * 1.5)
inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.85 )
inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.85 )
inst.components.combat.damagemultiplier = 4
inst.AnimState:SetBuild("sweeneytodd2")
 

inst:AddComponent("talker")

inst.components.talker:Say("Who's up for a free shave?!")
inst.components.talker.fontsize = 28 
inst.components.talker.font = TALKINGFONT
inst.components.talker.colour = Vector3(10, 0, 0, 0)
inst.components.talker.offset = Vector3(0,0,100)
inst.components.talker.symbol = "swap_object"
 
end

 

And this

 

 

       if inst.components.sanity.current < 30 then

                becomebody(inst)
 

inst:AddComponent("talker")

inst.components.talker:Say("Who's up for a free shave?!")
inst.components.talker.fontsize = 28 
inst.components.talker.font = TALKINGFONT
inst.components.talker.colour = Vector3(10, 0, 0, 0)
inst.components.talker.offset = Vector3(0,0,100)
inst.components.talker.symbol = "swap_object"
 
inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_creepyforest")

 

 

Now, these both work.... but as you would expect from a talker set like this, the entire time i'm below 30 sanity it's talking and twitching around.... now this is a cool effect and all... but i'm trying to figure out how to make it say this only when it first transforms.

 

I realize I didn't put all the coding up here, but this should be enough to show you what I was doing.

 

I appreciate yalls help,

 

Vince

Link to comment
Share on other sites

... but i'm trying to figure out how to make it say this only when it first transforms.

well, thats why u shouldn't actually call becomebody all the time, just call it when he drops below 30 sanity. save his last sanity into a variable(eg inst.lastsanity) and then check if the current one is below 30 while the last one was above 30 and THEN call becomebody.

also, the whole thing looks a bit strange, u are adding the component in several spots and if what u say is correct, u also keep adding the component all the time?

can u attach the whole prefab, so we can have a look?

Link to comment
Share on other sites

well, thats why u shouldn't actually call becomebody all the time, just call it when he drops below 30 sanity. save his last sanity into a variable(eg inst.lastsanity) and then check if the current one is below 30 while the last one was above 30 and THEN call becomebody.

also, the whole thing looks a bit strange, u are adding the component in several spots and if what u say is correct, u also keep adding the component all the time?

can u attach the whole prefab, so we can have a look?

 

It looks that way because I was showing you two places I had put the component in, that gave the same results both times.

 

I'm gonna try and figure out how to do what you told me, I'm pretty sure I have an example lying around that I could decipher.

 

Thanks,

 

Vince

Link to comment
Share on other sites

@chupicabra,

well, first u should add components only once when creating the prefab, same for the settings like color and stuff(unless u have a specific reason to do otherwise).

second, u shouldnt add the talkercomponent at all, since characters have it by default.

third, just attach the prefab-file of your character(assuming this code is in your prefab) already.

Link to comment
Share on other sites

@chupicabra The problem lies here.

local function sanitychange(inst, data)	if inst.components.sanity.current < 30 then		becomebody(inst)		inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_creepyforest")	else		becomehed(inst)		inst.SoundEmitter:KillSound("dontstarve/music/gramaphone_creepyforest")	end end

You're not checking if the character already transformed, and calling the transformation again and again whenever sanity is changed.

 

Set a variable outside of the function to keep track of it.

local isBody = falselocal function sanitychange(inst, data)	if inst.components.sanity.current < 30 then		if not isBody then			becomebody(inst)			inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_creepyforest")			isBody = true		end	else		if isBody then			becomehed(inst)			inst.SoundEmitter:KillSound("dontstarve/music/gramaphone_creepyforest")			isBody = false		end	endend
Link to comment
Share on other sites

 

@chupicabra The problem lies here.

local function sanitychange(inst, data)	if inst.components.sanity.current < 30 then		becomebody(inst)		inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_creepyforest")	else		becomehed(inst)		inst.SoundEmitter:KillSound("dontstarve/music/gramaphone_creepyforest")	end end

You're not checking if the character already transformed, and calling the transformation again and again whenever sanity is changed.

 

Set a variable outside of the function to keep track of it.

local isBody = falselocal function sanitychange(inst, data)	if inst.components.sanity.current < 30 then		if not isBody then			becomebody(inst)			inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_creepyforest")			isBody = true		end	else		if isBody then			becomehed(inst)			inst.SoundEmitter:KillSound("dontstarve/music/gramaphone_creepyforest")			isBody = false		end	endend

Thanks mate! I was trying to script something out similarly, but I was missing the "if isbody"  part.... I just started a few days ago so I appreciate your help!

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...