Jump to content

How to force anim?


Recommended Posts

Hello, I need help :)... So, when my character goes insane he goes into this inst.AnimState:PlayAnimation("yawn") which I edited a texture to make it look like his roaring, now the problem's the anim won't play if his moving or it will cancel if he moves which makes me :(... Is there a way to force the inst.AnimState:PlayAnimation("yawn") anim to play no matter what until it finishes and even better get him to stop in place until it finishes? All help's extremely accepted & thank you so, so, so, so, so, so, so, so, MUCH for reading this :D:D:D!!!

Link to comment
Share on other sites

18 minutes ago, SuperDavid said:

Hello, I need help :)... So, when my character goes insane he goes into this inst.AnimState:PlayAnimation("yawn") which I edited a texture to make it look like his roaring, now the problem's the anim won't play if his moving or it will cancel if he moves which makes me :(... Is there a way to force the inst.AnimState:PlayAnimation("yawn") anim to play no matter what until it finishes and even better get him to stop in place until it finishes? All help's extremely accepted & thank you so, so, so, so, so, so, so, so, MUCH for reading this :D:D:D!!!

local function onstopyawn(inst)
    inst:RemoveEventCallback("animover", onstopyawn) -- stop listenng for animations being over
    if inst.components.playercontroller ~= nil then
        inst.components.playercontroller:Enable(true) -- reenable keypressing
    end

    inst.sg:GoToState("idle") -- go to idle
end


if inst.components.playercontroller ~= nil then--stop keypresses
    inst.components.playercontroller:Enable(false)
end

inst.components.locomotor:Stop() -- stop movement
inst.components.locomotor:Clear()
inst:ClearBufferedAction() -- and any actions you were going to do

inst.AnimState:PlayAnimation("yawn") -- play animation

inst:ListenForEvent("animover", onstopyawn) -- go to above function when this animation is done

 

Link to comment
Share on other sites

Aquaterion it works really well, thank you :D! I just have one more thing to ask is if you know if there's an way to stop the yawn sound from playing when he goes into inst.sg:GoToState("yawn")?

Link to comment
Share on other sites

4 minutes ago, SuperDavid said:

Aquaterion it works really well, thank you :D! I just have one more thing to ask is if you know if there's an way to stop the yawn sound from playing when he goes into inst.sg:GoToState("yawn")?

I think you'd have to edit the sound file or modify the volume while yawning(via code). but I thought you just wanted to play the animation, so why go to yawn state?

Link to comment
Share on other sites

4 minutes ago, SuperDavid said:

Because when he goes insane inst.sg:GoToState("idle") doesn't make him stop right in his place and yawn but inst.sg:GoToState("yawn") does but it makes a yawn sound :?...

isnt that what my code is suppose to do??

Link to comment
Share on other sites

I put this 

local function OnStopYawn(inst)
inst:RemoveEventCallback("animover", OnStopYawn)
if inst.components.playercontroller ~= nil then
inst.components.playercontroller:Enable(true)
end
inst.sg:GoToState("idle") -- this has to be changed into inst.sg:GoToState("yawn") for him to stop and yawn while moving but it makes a yawn sound :(
end
if inst.components.playercontroller ~= nil then
inst.components.playercontroller:Enable(false)
end
inst.components.locomotor:Stop()
inst.components.locomotor:Clear()
inst:ClearBufferedAction()
inst.AnimState:PlayAnimation("yawn")
inst:ListenForEvent("animover", OnStopYawn)

if i'm moving and go insane he just stops in place idling for a couple seconds, with this code he has to stand completely still for him to yawn.

if you change inst.sg:GoToState("idle") into inst.sg:GoToState("yawn") is the only way he stops in place and yawns but it makes a yawn sound...

Edited by SuperDavid
Link to comment
Share on other sites

6 minutes ago, SuperDavid said:

I put this 


local function OnStopYawn(inst)
inst:RemoveEventCallback("animover", OnStopYawn)
if inst.components.playercontroller ~= nil then
inst.components.playercontroller:Enable(true)
end
inst.sg:GoToState("idle") -- this has to be changed into inst.sg:GoToState("yawn") for him to stop and yawn but it makes a yawn sound :(
end
if inst.components.playercontroller ~= nil then
inst.components.playercontroller:Enable(false)
end
inst.components.locomotor:Stop()
inst.components.locomotor:Clear()
inst:ClearBufferedAction()
inst.AnimState:PlayAnimation("yawn")
inst:ListenForEvent("animover", OnStopYawn)

if i'm moving and go insane he just stops in place idling for a couple seconds, with this code he has to stand completely still for him to yawn.

if you change inst.sg:GoToState("idle") into inst.sg:GoToState("yawn") is the only way he stops in place and yawns but it makes a yawn sound...

if that isnt working then just using inst.sg:GoToState("yawn") is needed, the rest of the code was because I thought yawning automatically makes you sleepy

for overriding the yawn sound u can do

inst.yawnsoundoverride = "" -- put a sound file in there, not sure if you can just leave empty.

Edited by Aquaterion
Link to comment
Share on other sites

10 minutes ago, SuperDavid said:

Thank you, so, so, so much!!! Everything works perfectly now, you're so awesome Aquaterion :D!!!!!!

what you could do for the 2nd sound

inst:ListenForEvent("yawn", function()
	inst:DoTaskInTime(1, function() inst.SoundEmitter:PlaySound("sound2") end)
end)

listen for "yawn" event and calculate how long the first sound is, and change 1 with how long the first sound is, and sound2 with the second sound

Link to comment
Share on other sites

I did this and everything worked perfectly :)! And it's all thanks to you Aquaterion :D! Now I have a fully functional roar! Thanks so much Aquaterion your help was extremely critical for the roar to be roar-ish-er, i'm definitely giving you full credit for my character's roar because without you he wouldn't be able to roar, thanks so much :D!!!!

-- Stop everything then I can roar.
local function OnStopYawn(inst)
inst:RemoveEventCallback("animover", OnStopYawn)
if inst.components.playercontroller ~= nil then
inst.components.playercontroller:Enable(true)
end
inst.sg:GoToState("yawn")
inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/howl")
inst.SoundEmitter:PlaySound("dontstarve/creatures/worm/distant")
inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/grunt")
inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/vargr/howl")
-- Other players lose 50 sanity when I roar.
local x, y, z = inst.Transform:GetWorldPosition()
local players = FindPlayersInRange(x, y, z, (15), true)
for _, v in pairs(players)
do
if(v~=inst)
then
if(v.components and v.components.sanity)
then
v.components.health:DoDelta(-300)
end
end
end
end
if inst.components.playercontroller ~= nil then
inst.components.playercontroller:Enable(false)
end
inst.components.locomotor:Stop()
inst.components.locomotor:Clear()
inst:ClearBufferedAction()
inst.yawnsoundoverride = "dontstarve_DLC001/creatures/vargr/howl"
inst:ListenForEvent("animover", OnStopYawn)

 

Link to comment
Share on other sites

7 minutes ago, SuperDavid said:

I did this and everything worked perfectly :)! And it's all thanks to you Aquaterion :D! Now I have a fully functional roar! Thanks so much Aquaterion your help was extremely critical for the roar to be roar-ish-er, i'm definitely giving you full credit for my character's roar because without you he wouldn't be able to roar, thanks so much :D!!!!

 

I think this should work the same:

-- Stop everything then I can roar.
	inst.sg:GoToState("yawn")
	inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/howl")
	inst.SoundEmitter:PlaySound("dontstarve/creatures/worm/distant")
	inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/grunt")
	inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/vargr/howl")
-- Other players lose 50 sanity when I roar.
local x, y, z = inst.Transform:GetWorldPosition()
local players = FindPlayersInRange(x, y, z, (15), true)
for _, v in pairs(players) do
	if v ~= inst and v.components and v.components.sanity then
		v.components.health:DoDelta(-300)
	end
end

btw this lowers health by 300 not sanity by 50? intentional or what?

Edited by Aquaterion
Link to comment
Share on other sites

14 minutes ago, Aquaterion said:

btw this lowers health by 300 not sanity by 50? intentional or what?

Thanks for telling me that! I'll change it now :)! I was testing to see if dodelta was working properly, if you didn't point that out then my character would've had a death howl instead :shock:!!!

 

-- Stop everything then I can roar.
	inst.sg:GoToState("yawn")
	inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/howl")
	inst.SoundEmitter:PlaySound("dontstarve/creatures/worm/distant")
	inst.SoundEmitter:PlaySound("dontstarve/creatures/werepig/grunt")
    inst.yawnsoundoverride = "dontstarve_DLC001/creatures/vargr/howl"
	inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/vargr/howl")
-- Other players lose 50 sanity when I roar.
local x, y, z = inst.Transform:GetWorldPosition()
local players = FindPlayersInRange(x, y, z, (15), true)
for _, v in pairs(players) do
	if v ~= inst and v.components and v.components.sanity then
		v.components.sanity:DoDelta(-50)
	end
end

^Yes this code works even better, thanks Aquaterion again :D!

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