• Print

Author Topic: Death Screen  (Read 5490 times)

0 Members and 1 Guest are viewing this topic.

Offline Suicidal Dog

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Death Screen
« on: February 22, 2017, 10:04:48 am »
I am trying to make a death screen appear when a player dies and want to use the PlayerDeath hook to get the killers name weapon and other such info. I am just asking someone to give me a little bit of code where a VGui appears on death and I can use the attacker, inflictor and victim parts of player death. My previous efforts haven't ended too well and just want someone to show me how I would do this by coding it, just an example of the attacker and other parts of the PlayerDeath hook being used.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Death Screen
« Reply #1 on: February 22, 2017, 11:31:58 am »
Use PlayerDeath to get the info you want and then send those to the player with a net message.

Then use a HUDPaint hook and a LocalPlayer():Alive() check to draw info to their screen when they're dead. The info you want needs to be sent from the server though.. here is a mockup..

this is VERY rough and probably (definitely) won't actually work..

SERVER CODE

Code: Lua
  1. util.AddNetworkString("send_death_info")
  2.  
  3.  
  4. function PlayerDies( ply, infl, attacter )
  5.         local killer = attacker:Nick()
  6.         local weapon = attacker:GetActiveWeapon():GetClass()
  7.        
  8.         net.Start( "send_death_info" )
  9.         net.WriteString( killer )
  10.         net.WriteString( weapon )
  11.         net.Send( ply )
  12. end
  13. hook.Add( "PlayerDeath", "MyPlayerDeathHook", PlayerDies )
  14.  


CLIENTSIDE CODE
Code: Lua
  1. AddCSLuaFile()
  2.  
  3. local killer = ""
  4. local weapon = ""
  5.  
  6. net.Receive( "send_death_info", function( ply, len )
  7.         killer = net.ReadString()
  8.         weapon = net.ReadString()
  9. end )
  10.  
  11. function DeathScreen()
  12.         if LocalPlayer():Alive() then return end
  13.         FANCY HUD CODE HERE TO DISPLAY THE STUFF YOU WANT TO DISPLAY...
  14. end
  15. hook.Add( "HUDPaint", "MyDeathScreen", DeathScreen )
  16.  


That will get you going.. anything more than that, and you're just asking someone to do it for you, in which case you should just come out and ask someone to do it for you...

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Death Screen
« Reply #2 on: February 23, 2017, 07:45:09 am »

Code: Lua
  1. function PlayerDies( ply, infl, attacter )
  2.  

Attacter? :)



EDIT: I just realized too, I don't think you need to do attacker:GetWeapon():GetClass() because 'inflictor' is the entity used to kill the person. Can't you just use inflictor:GetClass()? Also I think you'd need to check for if you fell or killed yourself because then the attacker wouldn't have a weapon, or the attacker == victim
« Last Edit: February 23, 2017, 10:42:52 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Suicidal Dog

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Re: Death Screen
« Reply #3 on: February 23, 2017, 08:46:58 am »
Use PlayerDeath to get the info you want and then send those to the player with a net message.

Then use a HUDPaint hook and a LocalPlayer():Alive() check to draw info to their screen when they're dead. The info you want needs to be sent from the server though.. here is a mockup..

this is VERY rough and probably (definitely) won't actually work..

SERVER CODE

Code: Lua
  1. util.AddNetworkString("send_death_info")
  2.  
  3.  
  4. function PlayerDies( ply, infl, attacter )
  5.         local killer = attacker:Nick()
  6.         local weapon = attacker:GetActiveWeapon():GetClass()
  7.        
  8.         net.Start( "send_death_info" )
  9.         net.WriteString( killer )
  10.         net.WriteString( weapon )
  11.         net.Send( ply )
  12. end
  13. hook.Add( "PlayerDeath", "MyPlayerDeathHook", PlayerDies )
  14.  


CLIENTSIDE CODE
Code: Lua
  1. AddCSLuaFile()
  2.  
  3. local killer = ""
  4. local weapon = ""
  5.  
  6. net.Receive( "send_death_info", function( ply, len )
  7.         killer = net.ReadString()
  8.         weapon = net.ReadString()
  9. end )
  10.  
  11. function DeathScreen()
  12.         if LocalPlayer():Alive() then return end
  13.         FANCY HUD CODE HERE TO DISPLAY THE STUFF YOU WANT TO DISPLAY...
  14. end
  15. hook.Add( "HUDPaint", "MyDeathScreen", DeathScreen )
  16.  


That will get you going.. anything more than that, and you're just asking someone to do it for you, in which case you should just come out and ask someone to do it for you...

Thanks man extremely helpful, glad this community exists.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Death Screen
« Reply #4 on: February 23, 2017, 02:04:04 pm »
Attacter? :)



EDIT: I just realized too, I don't think you need to do attacker:GetWeapon():GetClass() because 'inflictor' is the entity used to kill the person. Can't you just use inflictor:GetClass()? Also I think you'd need to check for if you fell or killed yourself because then the attacker wouldn't have a weapon, or the attacker == victim

Yeah, there are lots of things you'd need to do. This was just to give him an idea of which hooks to use and how to go about it. I didn't intend to have written out everything.

To rule out non-player attackers, you could always do
Code: [Select]
if not attacker:IsPlayer() then return end

  • Print