• Get Killer info for use in DLabel / DTextEntry
    3 replies, posted
I've search everywhere... This is what I have, I need the "self[5.1]" to have a "SetText" with the attacker who killed the local player. I've tried countless hooks and functions to achieve this, but i'm experiencing code block atm. Any suggestions, or tips would be much appreciated. [code] self[5.1] = vgui.Create('AustinTextEntry',self[2]) self[5.1]:SetFont('Austin24') self[5.1]:SetTextColor(Color(30,30,30)) self[5.1]:SetEditable(false) self[5.1]:SetDisabled(true) self[5.1]:SetText() [/code]
Here's a hook you can use. The info passed to the second argument should be exactly what you want. [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/DoPlayerDeath]GM:DoPlayerDeath[/url] Hook into it from the server, send a net message to the client with the name of the attacker, and when the client receives it, then call whatever function is creating your UI inside this net receiver.
[QUOTE=Z0mb1n3;52074778]Here's a hook you can use. The info passed to the second argument should be exactly what you want. [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/DoPlayerDeath]GM:DoPlayerDeath[/url] Hook into it from the server, send a net message to the client with the name of the attacker, and when the client receives it, then call whatever function is creating your UI inside this net receiver.[/QUOTE] Thank you for pointing me towards net, didn't think of that... This is what I came up with: VGUI file where the panel is created: [code] self[5.1] = vgui.Create('AustinTextEntry',self[2]) self[5.1]:SetFont('Austin24') self[5.1]:SetTextColor(Color(30,30,30)) self[5.1]:SetEditable(false) self[5.1]:SetDisabled(true) self[5.1].Think = function() net.Receive('GetDeathInfo', function(attacker) self[5.1]:SetText(attacker:Nick()) end) end [/code] Server file where the util.Addnetwork String and net.Start/Send are located [code] util.AddNetworkString('GetDeathInfo') hook.Add("PlayerDeath","WinterIsComing", function(ply,attacker,dmg) if attacker:IsValid() and attacker:IsPlayer() then net.Start("GetDeathInfo") net.Send(attacker) end end) [/code] Not getting anything in the box, no errors either?
[QUOTE=Richtofen;52074874]Thank you for pointing me towards net, didn't think of that... This is what I came up with: VGUI file where the panel is created: [code] self[5.1] = vgui.Create('AustinTextEntry',self[2]) self[5.1]:SetFont('Austin24') self[5.1]:SetTextColor(Color(30,30,30)) self[5.1]:SetEditable(false) self[5.1]:SetDisabled(true) self[5.1].Think = function() net.Receive('GetDeathInfo', function(attacker) self[5.1]:SetText(attacker:Nick()) end) end [/code] Server file where the util.Addnetwork String and net.Start/Send are located [code] util.AddNetworkString('GetDeathInfo') hook.Add("PlayerDeath","WinterIsComing", function(ply,attacker,dmg) if attacker:IsValid() and attacker:IsPlayer() then net.Start("GetDeathInfo") net.Send(attacker) end end) [/code] Not getting anything in the box, no errors either?[/QUOTE] You may want to look up how to actually use the net library. To send something over the net library: [code] net.Start("GetDeathInfo") net.WriteString(attacker:Name()) net.Send(ply) [/code] to receive [code] -- net.Receive is not a function you run to retrieve data. It listens for messages sent using this identifier, and when one is received, the callback function is called. net.Receive("GetDeathInfo", function(len) -- This callback function is executed when we receive the "GetDeathInfo" message local name = net.ReadString() -- Do whatever you want with the name of the player. -- If your UI panel is part of something larger, you may want to instead assign a global variable to the name received here. end)[/code]
Sorry, you need to Log In to post a reply to this thread.