Recognising when a player get shot in the head???

Hi again. I’m looking for some code that when the play shoots someone in the head it displays on the screen “HEADSHOT!”

I have been using this to print text but only on spawn.

local seconds = 5
timer.Create(“stupidtimer”, 0.1, (seconds / 0.1), function () pl:PrintMessage (HUD_PRINTCENTER, "You are on the offensive side. Go get them "…pl:Nick())
end)
If there is anything on the wiki that could help please shoot. (I tried looking but didn’t know where really to start.)

Adam,

[lua]function GM:ScalePlayerDamage(ply, attacker, dmginfo, hitgroup)
if (hitgroup == HITGROUP_HEAD) then
for k, v in pairs(player.GetAll()) do
PrintMessage( HUD_PRINTCENTER, string.upper( attacker:Nick() ) … " HEADSHOT" )
end
end
end [/lua]

Hah, that was simpler then what I thought it would be. So are there hit points all over the body with similar names.

Yes, check out the following link.

Would this work with NPC’s just so I can test it without making a server?

I’m guessing this:

[lua] function GM:ScaleNPCDamage(npc, attacker, dmginfo, hitgroup)
if (hitgroup == HITGROUP_HEAD) then
for k, v in pairs(player.GetAll()) do
PrintMessage( HUD_PRINTCENTER, string.upper( attacker:Nick() ) … " HEADSHOT" )
end
end
end [/lua]

That ^ there didn’t work :stuck_out_tongue:

snip

delete please

Is this code going in an addon or a gamemode? If it’s an addon you need to use hook.Add rather than overwrite the gamemode function directly.

According to the Wiki page for ScaleNPCDamage, the arguments are npc, hitgroup, dmginfo, which isn’t what you have.

Also, in the example you’re using, the global version of PrintMessage already prints to all players. No need to put it in a loop going through all the players.

**[Gamemode.PlayerTraceAttack

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerTraceAttack)**

When used on client it will only work when the LocalPlayer() was the attacker.

It should be exactly what you need.

Just use my code and click create multiplayer then spawn a bot by typing bot in the console, and shoot the bot in the head

Thanks c-unit even though it seems you are banned now but cheers, Shame… you seemed quite helpful :smiley:

:downs:

c-unit note the disagree and funny rates :stuck_out_tongue:

How would you “convert” this script to work so that it only detects the headshot when the player dies

[editline]26th December 2010[/editline]

nvm I found a way with playerdeath :slight_smile: ill post it soon

function gethitgroup(ply, attacker, dmg, hitgroup)
return hitgroup
end
hook.Add(“ScalePlayerDamage”, “gethitgroup”, gethitgroup)
function GM:PlayerDeath( victim, weapon, killer )
if gethitgroup() == HITGROUP_HEAD then
PrintMessage( HUD_PRINTCENTER, string.upper( killer:Nick() ) … " got a HEADSHOT" )
end
end

Why does it matter if people think I’m wrong? Or think it’s funny that he said I’m correct. All that matters was that I helped the OP.

Haters make me famous.

[editline]26th December 2010[/editline]

Also seth showed me your little conversation you had, I lol’d.

Fakest convo ever…

SteveUK banned c-unit for 1 Day in HeroModV1 with the reason “Replied just to say they reported a post”
4 Days ago
mahalis banned c-unit for 1 Day in Remote Server Crashing with the reason “Trolling / image macro”
6 Days ago
JohnnyMo1 banned c-unit for 12 Hours in I’m addicted to jacking off with the reason “Contentless thread”
JohnnyMo1 closed c-unit’s thread called I’m addicted to jacking off in General Discussion with the reason “Crap thread”
12 Days ago
mahalis banned c-unit for 3 Days in Amnesia: The Dark Descent oil lamp SWEP with the reason “Trolling”
24 Days ago
birkett moved c-unit’s thread titled “Front Jacks” from Hardware and Software to Technical Support
1 Month ago
Grea$eMonkey banned c-unit for 7 Days in DDoS Protection? with the reason “Troll”
Greeman banned c-unit for 3 Days in ConVar to set player running speed? with the reason “Flaming”
SteveUK banned c-unit for 3 Days in Velocity with the reason “Meme/flaming”
2 Months ago
Dragon banned c-unit for 1 Day in Trooper Mini-Hack with the reason “Image macro”
GunFox banned c-unit for 3 Days in The story of how I am dating a suicidal bitch with the reason “meme shit”
3 Months ago
Benji banned c-unit for 1 Day in SLog Problem with the reason “Flaming”
6 Months ago
Benji closed c-unit’s thread called What do you do when you’re bored? in General Discussion
Benji banned c-unit for 3 Days in What do you do when you’re bored? with the reason “Fast threads”
7 Months ago
Perfumly banned c-unit for 12 Hours in Requesting a cool photoshop picture with the reason “Missed the Creative Works Request Thread”
Perfumly closed c-unit’s thread called Requesting a cool photoshop picture in Creationism Corner
SteveUK banned c-unit for 7 Days in Hypderdesk Darkmatter Quadrilogy with the reason “Asking for warez”
SteveUK closed c-unit’s thread called Hypderdesk Darkmatter Quadrilogy in Windows
SteveUK banned c-unit for 1 Day in Is this program safe? with the reason “Not programming”
SteveUK closed c-unit’s thread called Is this program safe? in Programming
birkett closed c-unit’s thread called New programming language in Programming with the reason “Crap”
birkett banned c-unit for 1 Day in New programming language with the reason “Crap thread / no research”
Benji closed c-unit’s thread called New programming language? in General Discussion
Benji banned c-unit for 1 Day in New programming language? with the reason “Wrong section”
garry closed c-unit’s thread called We are under siege in LUA Scripting
8 Months ago
Grea$eMonkey banned c-unit for 7 Days in My gmod is deaf with the reason “Trolling”
9 Months ago
Grea$eMonkey moved c-unit’s thread titled “Client-Sided Lua Addon” from Questions to Requests
mahalis banned c-unit for 1 Day in Group Looking For VGUI Scripter with the reason “Why reply?”
Mr. Gestapo banned c-unit for 7 Days in I request a little-kid detector and pitch changer with the reason “Racism”
10 Months ago
Terrenteller banned c-unit for 1 Day in Needed team for mapping with the reason “Flaming Hypocrisy”

Are you asking for another ban?

Stop threatening me, and it’s not fake. I was teamviewing Seth when you were talking to him, he was showing me his website.

I removed seth a year ago, and if you haven’t noticed, Seth is a troll

Only to people he doesn’t like, we are friends so he showed me this picture of how dumb you are.

That would not suffice. Also, why are you putting arguments in to a return function?

[lua]function ScaleThePlayersDamageYo( pl, hitgroup, dmginfo )
if( hitgroup == HITGROUP_HEAD ) then
local attacker = dmginfo:GetAttacker();
attacker = attacker:Nick() or “”;

             PrintMessage( 4, attacker .. " got a headshot!" ); //Printmessage without an argument in the front will print to all players. (getting all players is a waste of time)
     end

end
hook.Add( “ScalePlayerDamage”, “ScaleThePlayersDamageYo”, ScaleThePlayersDamageYo )[/lua]
Note: Sometimes functions don’t work with hooks because Gmod lua is very inferior to other languages