Jump to content

Emote reaction?


Recommended Posts

local emotesay = {
	wilson = {
		research = "Yay", -- /joy
		emoteXL_annoyed = "Ugh", -- /no
	},
	willow = {
		research = "Fire", -- /joy
		emoteXL_annoyed = "Water", -- /no
	},
}

local function EmoteReact(inst, data)
	if data then
		local saytable = emotesay[inst.prefab]
		if saytable then
			local saying = saytable[data.anim]
			if saying and inst.components.talker then
				inst.components.talker:Say(saying)
			end
		end
	end
end

AddPlayerPostInit(function(inst)
	inst:ListenForEvent("emote", EmoteReact)
end)

You can see the rest of animations at emotes.lua.

Link to comment
Share on other sites

31 minutes ago, DarkXero said:

local emotesay = {
	wilson = {
		research = "Yay", -- /joy
		emoteXL_annoyed = "Ugh", -- /no
	},
	willow = {
		research = "Fire", -- /joy
		emoteXL_annoyed = "Water", -- /no
	},
}

local function EmoteReact(inst, data)
	if data then
		local saytable = emotesay[inst.prefab]
		if saytable then
			local saying = saytable[data.anim]
			if saying and inst.components.talker then
				inst.components.talker:Say(saying)
			end
		end
	end
end

AddPlayerPostInit(function(inst)
	inst:ListenForEvent("emote", EmoteReact)
end)

You can see the rest of animations at emotes.lua.

So if one wanted to do this for a mod character...?

Link to comment
Share on other sites

5 minutes ago, Lumina said:

replace "wilson" or "willow" by the name of your character i guess.

I dunno, how Xero has it set up feels like its own thing. Like a script only mod of some sort.

Then again, Xero could intend me (and anyone else) to put this in the character's prefab script. I'll try it out tomorrow, it's getting late for me.

Link to comment
Share on other sites

yes, you have to add your character prefab to this.
And also the emotes you want, at the moment it onyl contains "emoteXL_annoyed" and "research".
As he said, you can find the other emotes in emotes.lua.

BUT:
It is not that easy, the data.anim is not always a string. It can also be a table:
anim={"emoteXL_pre_dance0","emoteXL_loop_dance0"}
or even a "tabled" table:
anim={{"emote_pre_sit1","emote_loop_sit1"},{"emote_pre_sit3","emote_loop_sit3"}}

I already made a function to check this for my quest mod, you could use it:
 

-- all the emotes you can actively do at the moment. To add mod emotes, or emotes like research, add them the same way to that list, while "name" is a custom name you choose and also use in your emotesay
local emoteanims = {{name="Dance",anims={"emoteXL_pre_dance0","emoteXL_loop_dance0"}},{name="Kiss",anims={"emoteXL_kiss"}},{name="Bonesaw",anims={"emoteXL_bonesaw"}},{name="Angry",anims={"emoteXL_angry"}},{name="Happy",anims={"emoteXL_happycheer"}},{name="Pose",anims={"emote_strikepose"}},{name="Wave",anims={"emoteXL_waving1","emoteXL_waving2","emoteXL_waving3"}},{name="Facepalm",anims={"emoteXL_facepalm"}},{name="Joy",anims={"research"}},{name="Cry",anims={"emoteXL_sad"}},{name="Annoyed",anims={"emoteXL_annoyed"}},{name="Rude",anims={"emoteXL_waving4"}},{name="Sit",anims={"emote_pre_sit2","emote_loop_sit2","emote_pre_sit4","emote_loop_sit4"}},{name="Squat",anims={"emote_pre_sit1","emote_loop_sit1","emote_pre_sit3","emote_loop_sit3"}}}

local emotesay = {
	wilson = {
		Dance = "Yay", -- /joy
		Angry = "Ugh", -- /no
	},
	willow = {
		Dance = "Fire", -- /joy
		Angry = "Water", -- /no
	},
}

local function CheckWhichEmote(data)
    name = false
    if data then
        for i,anim in pairs(emoteanims) do
            if type(data.anim)=="string" and anim.anims[1] == data.anim then -- if data.anim is a string, we only need to check first.
                name = anim.name
            elseif type(data.anim)=="table" then -- check also if anim is a table
                for k,animstringdata in pairs(data.anim) do
                    if type(animstringdata)=="string" then   -- if it is now a string
                        for k2,animstring in pairs(anim.anims) do
                            if animstring == animstringdata then
                                name = anim.name
                            end
                        end
                    elseif type(animstringdata)=="table" then -- in case of sit and aquat it is again a table...
                        for q,stringdata in pairs(animstringdata) do
                            for k2,animstring in pairs(anim.anims) do
                                if animstring == stringdata then
                                    name = anim.name
                                end
                            end 
                        end
                    end
                end
            end
        end
    end
    return name -- returns the name of the emotion from your emoteanims table
end

local function EmoteReact(inst, data)
    if data then
        name = CheckWhichEmote(data)
        if name then
            local saytable = emotesay[inst.prefab]
            if saytable then
                local saying = saytable[name]
                if saying and inst.components.talker then
                    inst.components.talker:Say(saying)
                end
            end
        end
	end
end

AddPlayerPostInit(function(inst)
	inst:ListenForEvent("emote", EmoteReact)
end)

this should work, but I did not tested if I made a typo somewhere. So if it crashes, please post error message.

Again you add your character prefabs.
And also add new emotes, if they are not already in the emoteanims list.

Edited by Serpens
Link to comment
Share on other sites

12 hours ago, icantevenname said:

So if one wanted to do this for a mod character...?

Say your character prefab is "walton", then you would go like:

local emotesay = {
	walton = {
		research = "Yay", -- /joy
		emoteXL_annoyed = "Ugh", -- /no
	},
}

local function EmoteReact(inst, data)
	if data then
		local saytable = emotesay[inst.prefab]
		if saytable then
			local saying = saytable[data.anim]
			if saying and inst.components.talker then
				inst.components.talker:Say(saying)
			end
		end
	end
end

AddPlayerPostInit(function(inst)
	inst:ListenForEvent("emote", EmoteReact)
end)
10 hours ago, icantevenname said:

I dunno, how Xero has it set up feels like its own thing. Like a script only mod of some sort.

Then again, Xero could intend me (and anyone else) to put this in the character's prefab script. I'll try it out tomorrow, it's getting late for me.

Since you said "characters" (plural) in your main post, I made it so anybody with data on the table would have the strings. This way not only you can make a table to include many mod characters all in one, you can also include the official characters as well. It's a general solution that you can modify to suit your needs.

It goes on modmain, because it makes use of AddPlayerPostInit.

 

You can even make "character specific" code for your prefab file like this:

local saytable = {
	research = "Yay", -- /joy
	emoteXL_annoyed = "Ugh", -- /no
}

local function EmoteReact(inst, data)
	if data then
		local saying = saytable[data.anim]
		if saying and inst.components.talker then
			inst.components.talker:Say(saying)
		end
	end
end

-- inside your master_postinit function

local function master_postinit(inst)
	inst:ListenForEvent("emote", EmoteReact)
end

You skip the prefab checks (since it's just for your character) and just react to the emote animations.

Link to comment
Share on other sites

7 minutes ago, icantevenname said:

I keep looking at the code I have in the modmain and what you told me originally. I still don't see what I did wrong. I need some elaboration.

It was clear, you have a file named "modmian.lua" instead of "modmain.lua". So it can't work.

Link to comment
Share on other sites

you have all the code you need. Just copy paste it (there might be typos in it so it could still crash, but then we need to know your code + error message)
So what is the problem? (the last versin with "modmian" does not contain code that could produce the error you reported)

It is not a choice "DarkXero or Serps code" it is both. DarkXero gave the basic and I added code to also be able to deal with more complex emotes.

Edited by Serpens
Link to comment
Share on other sites

5 minutes ago, Serpens said:

you have all the code you need. Just copy paste it (there might be typos in it so it could still crash, but then we need to know your code + error message)
So what is the problem? (the last versin with "modmian" does not contain code that could produce the error you reported)

It is not a choice "DarkXero or Serps code" it is both. DarkXero gave the basic and I added code to also be able to deal with more complex emotes.

I see.

I figured out what was wrong, but the emotes with variants still don't have a reaction. Which makes me sad, since Dance is one of those emotes...

Emote react.zip

Link to comment
Share on other sites

the best thing you can do is to add "print()" statements in the code.
I did it and noticed that there is no name returned when the dance is done, so obviously my function does something wrong. I will work now to fix it ;)

Link to comment
Share on other sites

Fixed my code, it was just two times ".anims" that was missing in the CheckWhichEmote function.
So just copy paste the corrected CheckWhichEmote function from my previous post into your mod and it works (tested) :)

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