I want to have a Chat message be displayed on a player when he for example is burning, got crushed, basically everything thats possible from this list DMG Enumerations
And to get the Information if the damage creator is one of one in the list i can use Category
All inside the hook ENTITY/OnTakeDamage
The problem im having is, i see no way of getting the attacked/victim returned. There is a function to return the ATTACKER, but i need the attacked person that is taking the damage, not making it.
I need that so i can send a network message to that player, so only he gets the chat message
(Different chat messages for burning, crushed, etc.)
Because without that i could only make a chat message be printed for everyone, which is not what i need..
Is there a way to get the Entitie that is being attacked? I dont really understand why there is a way to get the ATTACKER, but not the ATTACKED...or i am missing something
CTakeDamageInfo/GetAttacker
Where CTakeDamageInfo is the one and only argument to the hook.
Yea i was thinking the same, but then theres the problem, how do i define the ENTITY? Its in a hook, can i put the player name in there?
next problem is this hook is serverside, means LocalPlayer() doesnt even exist
The only way I've ever used ENTITY hooks is in the entity's code itself, such as
function ENT:PhysCollide()
so the only way I would know how to use ENTITY:OnTakeDamage would be to edit the player's entity code or something, which is a risky task.
If you're dead set on using that hook instead of GM:EntityTakeDamage, you'll have to wait for someone a little more qualified to tell you actually how to go upon using it.
And yeah since LocalPlayer() doesn't exist on the server, you'd have to network the victim/attacker/whichever player you want the message to appear to.
Nah, im fine with whatever is possible. I tryd the hook you showed me, and i quickly ended up with this
if SERVER then
util.AddNetworkString("PlayerTookDamage")
hook.Add("EntityTakeDamage", "DifferentDamages", function(ply , dmginfo)
local damagetype = dmginfo:GetDamageType()
net.Start("PlayerTookDamage")
net.WriteInt(damagetype,16)
net.Send(ply)
end)
else
net.Receive("PlayerTookDamage",function()
local damagetype = net.ReadInt(16)
if damagetype == 2 then
chat.AddText("BOT: You just got shot.")
elseif damagetype == 4 then
chat.AddText("BOT: Something just cut you!")
elseif damagetype == 8 then
chat.AddText("BOT: Hot! Your Burning! Im Burning!")
elseif damagetype == 32 then
chat.AddText("BOT: You broke your Legs. Amazing...")
end
end)
end
And it works PERFECT. Just EXACLY what i needed. Depending on the damage type the player gets a specific message.
Im gonna add more numbers since the damage type list is longer. If there is a way to make the huge amount of if/elseif statements shorter and less code i would appreciate the hint. I tryd out a for k, v in pairs loop, by making a table that contains the different damage type numbers.
But that just makes the same amount of if statements, just in a loop. Means its executed EVEN MORE
Tables are powerful.
You could do
local dmgtypes = {
[2] = "BOT: You just got shot.",
[4] = ""BOT: Something just cut you!",
etc, then
chat.AddText( dmgtypes[damagetype] )
i know i could do that, but since there are several damage types im gonna need a huuuuge amount of if statements
while i wrote this i realized what you mean. damn thats smart..thx
Sorry, you need to Log In to post a reply to this thread.