• Print

Author Topic: Death display  (Read 5177 times)

0 Members and 1 Guest are viewing this topic.

Offline Suicidal Dog

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Death display
« on: February 13, 2017, 12:46:20 pm »
Hi, I am currently making a small but nice little addon for a server where a little display comes up at the centre bottom of their screen upon dying. Now this display is supposed to show a message at the top to show the name of the killer with their name. It is then supposed to show the weapon they were killed with and some extra stuff I can do myself. The problem I am having is with calling the players killers name and the weapon, I have no idea how to go about this and just want some help with how to go about getting the name and weapon and making them into not sure what this is but a "killer = killersname" and "killingweapon = killersweapon". Just so I can display those in a msg on the display. When you post a reply with some support, if you're giving some code that I can use could I get a full explanation as I wanna know how it works and see if I have any future application for future projects. The only real thing you guys needed was that as the code I have is currently just a little vgui and I doubt it'll be very helpful.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Death display
« Reply #1 on: February 13, 2017, 12:52:13 pm »
GM:PlayerDeath

That's probably the best place to look. It takes the player (victim), weapon (inflictor), and the killer (attacker), as arguments.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Suicidal Dog

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Re: Death display
« Reply #2 on: February 13, 2017, 02:45:14 pm »
How would I use this as I tried that before and removed it due to it just giving the error of "attempt to index GM(a nil value)" If you would mind could you give me an example of it as I have no clue about how to use that. Since before I had a complaint from someone for not asking, could you write an example of it being used in a VGui panel or just what I would actually need. I'm not completely brain dead and can put in variables into panel.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Death display
« Reply #3 on: February 13, 2017, 03:01:44 pm »
https://github.com/iViscosity/TTT-Death-Notifications/blob/master/Death%20Notify/lua/ulib/modules/TTTDeathNotify.lua#L14

An example of how I've used it

Code: Lua
  1. hook.Add( "PlayerDeath", "TTTDeathNotify", function( victim, weapon, attacker )
  2.  
  3.    if !attacker:IsPlayer() then
  4.      
  5.       ULib.tsayError( victim, "You were killed by the world." )
  6.  
  7.    elseif attacker == victim then
  8.      
  9.       ULib.tsayError( victim, "You just killed yourself..." )
  10.  
  11.    elseif attacker:GetRole() == ROLE_TRAITOR then
  12.      
  13.       ULib.tsayColor( victim, "", Color( 255, 255, 255 ), "You were killed by ", Color( 200, 25, 25 ), attacker:Nick(), Color( 255, 255, 255 ), " who was a ", Color( 200, 25, 25 ), "Traitor!" )
  14.  
  15.    elseif attacker:GetRole() == ROLE_INNOCENT then
  16.      
  17.       ULib.tsayColor( victim, "", Color( 255, 255, 255 ), "You were killed by ", Color( 25, 200, 25 ), attacker:Nick(), Color( 255, 255, 255 ), " who was an ", Color( 25, 200, 25 ), "Innocent!" )
  18.  
  19.    elseif attacker:GetRole() == ROLE_DETECTIVE then
  20.      
  21.       ULib.tsayColor( victim, "", Color( 255, 255, 255 ), "You were killed by ", Color( 25, 25, 200 ), attacker:Nick(), Color( 255, 255, 255 ), " who was a ", Color( 25, 25, 200 ), "Detective!" )
  22.  
  23.    end
  24.  
  25. end )
  26.  

This could also be written:

Code: Lua
  1. function TTTDeathNotify( victim, weapon, attacker )
  2.  
  3.    if !attacker:IsPlayer() then
  4.      
  5.       ULib.tsayError( victim, "You were killed by the world." )
  6.  
  7.    elseif attacker == victim then
  8.      
  9.       ULib.tsayError( victim, "You just killed yourself..." )
  10.  
  11.    elseif attacker:GetRole() == ROLE_TRAITOR then
  12.      
  13.       ULib.tsayColor( victim, "", Color( 255, 255, 255 ), "You were killed by ", Color( 200, 25, 25 ), attacker:Nick(), Color( 255, 255, 255 ), " who was a ", Color( 200, 25, 25 ), "Traitor!" )
  14.  
  15.    elseif attacker:GetRole() == ROLE_INNOCENT then
  16.      
  17.       ULib.tsayColor( victim, "", Color( 255, 255, 255 ), "You were killed by ", Color( 25, 200, 25 ), attacker:Nick(), Color( 255, 255, 255 ), " who was an ", Color( 25, 200, 25 ), "Innocent!" )
  18.  
  19.       elseif attacker:GetRole() == ROLE_DETECTIVE then
  20.      
  21.       ULib.tsayColor( victim, "", Color( 255, 255, 255 ), "You were killed by ", Color( 25, 25, 200 ), attacker:Nick(), Color( 255, 255, 255 ), " who was a ", Color( 25, 25, 200 ), "Detective!" )
  22.  
  23.    end
  24.  
  25. end
  26. hook.Add( "PlayerDeath", "TTTDeathNotify", TTTDeathNotify )
  27.  


PlayerDeath is a hook. If you're going to use it outside of a gamemode, you need to use hook.Add.




However, adding it to a VGUI panel would be a bit more complicated. You'd most likely need to use the Net Library or some other way to communicate the results of the hook to the client. Not sure if there's an easy way to do this, someone else may be able to help you in that case.
« Last Edit: February 13, 2017, 03:03:57 pm 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 display
« Reply #4 on: February 13, 2017, 03:20:53 pm »
I see what I did wrong, just overcomplicated it for myself. Thanks extremely helpful.

Offline Suicidal Dog

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Re: Death display
« Reply #5 on: February 13, 2017, 03:46:50 pm »
Right I am confused as I thought I had it working right now I got a

Code: [Select]
net.Receive( "death", function deathScreen( victim, weapon, attacker )
as I thought it may work the same way as I have also got

Code: [Select]
hook.Add( "PlayerDeath" , "DeathScreenShow" , deathScreen )
But when trying to call the "attacker" it just gives me an error of

Code: [Select]
[ERROR] lua/autorun/client/cl_rdm.lua:14: attempt to index upvalue 'attacker' (a nil value)
  1. unknown - lua/autorun/client/cl_rdm.lua:14

  • Print