Jump to content

Recommended Posts

use in your postinit from your character
inst:ListenForEvent("onattackother", OnAttackOther)

Then you define your OnAttackOther(inst,data). data contains data.target So you can check if your target is a player and make him say sth.

Edited by Serpens
44 minutes ago, Augustusc said:

Will that work if i hit other creatures that speak (like a pigman for example)?

data.target is the thing you hit, it can be an animal, a structure or a player.
You have to check yourself what it is and if it has the "talker" component. If it has (I think pigs have it) then you can make it say something.

Put this in your character's OnLoad function:

inst:ListenForEvent("onattackother", OnHitEnemy)

Then add this function:

local function OnHitEnemy(inst, data)
	local saythese = {
		"Put words here",
		"And here",
		"Maybe here too",
	}
	
	local targ = data.target or nil
	if inst ~= nil and targ ~= nil then
		if targ.components.talker == nil then
			targ:AddComponent("talker")
		end
		targ.components.talker:Say( saythese[ math.random( 1, table.getn(saythese) ) ] )
		if targ.components.talker.offset == nil then
			targ.components.talker.offset = Vector3(0,
			((targ:HasTag("smallcreature") or targ:HasTag("small")) and -300)
			or (targ.components.explosiveresist and -900)
			or ((targ:HasTag("largecreature") or targ:HasTag("epic") or targ:HasTag("large")) and -700)
			or (-400), 0)
		end
	end
end

 

Edited by JohnWatson

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