• opening DFrame on death
    10 replies, posted
I have been trying to make a script for darkrp. concept: on dealth, derma menu pops up asking if you have been rdmed or not, if you click yes, then it will pm an admin that they have been rdmed, I have not gotten any response from in game this is one of a couple of my first attempts at using gmodlua. I fount a post 9 years ago about this topic, didn't seem to help me all that much. init.lua if SERVER then AddCSLuaFile("cl_init.lua") function dermamenu(ply, ent, attacker) end hook.Add("PlayerDeath", "UnquieName" , dermamenu) end cl_init.lua if CLIENT then function dermamenu() dmenu = vgui.Create( "DFrame" ) dmenu:SetPos (ScrW() / 2, ScrH() / 2)  dmenu:SetTitle("RDM MENU") dmenu:SetDraggable( false ) dmenu:SetText( "Were you RDM'ed" ) dmenu:SetVisible( true ) dmenu:SetDraggable( false ) dmenu:ShowCloseButton( false ) dmenu:MakePopup() local yesb = vgui.Create( "DButton", dmenu ) yesb:Dock(TOP) yesb:SetSize( 50, 50 ) yesb:SetText( "Yes" ) yesb.DoClick = function() RunConsoleCommand("say", "@Admin, I have been RDMed") end local nob = vgui.Create( "DButton", dmenu ) nob:Dock(TOP) nob:SetSize( 50, 50 ) nob:SetText( "No" ) nob.DoClick = function() dmenu:Close() end end end
You can't "say" when you're dead so you'll have to force them to respawn with a timer or something. Also if this is for DarkRP you don't need to include the "if CLIENT" statement or the "if SERVER" statement.
Hello, Here is all the things you will need: GM/PlayerDeath - To detect if a player dies(Remember, this needs to be on the server). Net Library Usage - To send the info that the player has died to the player so it opens the menu. If you are not sure on how to use the Net Libary, Code Blue has a great tutorial on that! https://www.youtube.com/watch?v=ODlGyS6lR1M
There's no need to network anything since this is possible without the server. You can just use gameevent.Listen with "entity_killed" and then check if the entity that died is equal to LocalPlayer then open the derma. Keep in mind that data.entindex_killed is a number, not an entity, so to get the entity you'd have to use Entity.
Oh didn't know about that, Neat!
@\\ Thank you so much, I played around with it, and it worked perfectly!!!
I'm having 1 script error, other than that the script works 100% its just that its giving me a server error whenever I die attempt to call global 'LocalPlayer' (a nil value) I have been trying to understand why its doing this. everything work?
if you altered the code you should post what you have. Also remember LocalPlayer() is a clientside only value: https://wiki.garrysmod.com/page/Global/LocalPlayer orange is client blue is server
gameevent.Listen( "entity_killed" ) hook.Add( "entity_killed", "entity_killed_example", function( data ) local inflictor_index = data.entindex_inflictor // Same as Weapon:EntIndex() / weapon used to kill victim local attacker_index = data.entindex_attacker // Same as Player/Entity:EntIndex() / person or entity who did the damage local damagebits = data.damagebits // DAMAGE_TYPE - use BIT operations to decipher damage types... local victim_index = data.entindex_killed // Same as Victim:EntIndex() / the entity / player victim // Called when a Player or Entity is killed if Entity(data.entindex_killed) == LocalPlayer() then local dmenu = vgui.Create( "DFrame" ) dmenu:SetPos (ScrW() / 2, ScrH() / 2)  dmenu:SetTitle("RDM MENU") dmenu:SetSize( 200, 200) dmenu:SetDraggable( false ) dmenu:SetText( "Were you RDM'ed" ) dmenu:SetVisible( true ) dmenu:SetDraggable( false ) dmenu:ShowCloseButton( false ) dmenu:MakePopup() local yesb = vgui.Create( "DButton", dmenu ) yesb:Dock(TOP) yesb:SetSize( 50, 50 ) yesb:SetText( "Yes" ) yesb.DoClick = function() RunConsoleCommand("say", "@Admin, I have been RDMed") dmenu:Close() end local nob = vgui.Create( "DButton", dmenu ) nob:Dock(TOP) nob:SetSize( 50, 50 ) nob:SetText( "No" ) nob.DoClick = function() dmenu:Close() end local otherb = vgui.Create( "DButton", dmenu ) otherb:Dock(TOP) otherb:SetSize( 50, 50 ) otherb:SetText( "Other" ) otherb.DoClick = function() Derma_StringRequest( "Other", "Explain", "", function( txt ) RunConsoleCommand( "say", "@ " .. txt ) dmenu:Close() end) end end end )
Is this server side? If so try the Victim entity instead of LocalPlayer()
I got it to work, I'm just a dumb ass, didn't put the file in autorun/client kill me
Sorry, you need to Log In to post a reply to this thread.