Augustusc Posted May 4, 2017 Share Posted May 4, 2017 Hello! I need to make it so when my character hits something, they will say something. I don't want to make it so that when any character hits something, it says "example", Only this one character Link to comment Share on other sites More sharing options...
Serpens Posted May 4, 2017 Share Posted May 4, 2017 (edited) 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 May 5, 2017 by Serpens Link to comment Share on other sites More sharing options...
Augustusc Posted May 4, 2017 Author Share Posted May 4, 2017 Will that work if i hit other creatures that speak (like a pigman for example)? Link to comment Share on other sites More sharing options...
Serpens Posted May 4, 2017 Share Posted May 4, 2017 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. Link to comment Share on other sites More sharing options...
Augustusc Posted May 5, 2017 Author Share Posted May 5, 2017 My lack of coding experience is making this seemingly simple task be as challenging as a mountain climb.. Any way you could put some code down to point me in the right direction? Link to comment Share on other sites More sharing options...
JohnWatson Posted May 5, 2017 Share Posted May 5, 2017 (edited) 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 May 5, 2017 by JohnWatson Link to comment Share on other sites More sharing options...
Augustusc Posted May 5, 2017 Author Share Posted May 5, 2017 I got a crash.. i think i put something in the wrong place.. onit.lua Link to comment Share on other sites More sharing options...
CarlZalph Posted May 5, 2017 Share Posted May 5, 2017 30 minutes ago, Augustusc said: I got a crash.. i think i put something in the wrong place.. inst:ListenForEvent("onattackother", OnHitEnemy) Should be after OnHitEnemy declaration. So swap line 63 and 87. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now