• OnPlayerDeath Question
    9 replies, posted
Hey FP peeps. I have my OnPlayerDeath func ready. but theres one problem.... I want to execute a type of death_menu in cl_init, and... It says RunConsoleCommand cant be used there and when i use ply:ConCommand( "death_menu" ) (( yes i made cmd in cl_init)) it says it cant be found. Pl0x help <3
It would help if you posted the actual code. (are you sure this is being run on the client as well?)
So it just says 'unknown command: death_menu' when it tries to make you open the menu? Maybe there's an error in the menu function. I think concommand.Add refuses to add the function if it has a syntax error, or the whole script quits out and concommand.Add never gets run, or something like that. If this is for a gamemode then cl_init.lua should be fine. But if you're putting this into an addon make sure the files are always uniquely named or one will start overwriting the other. I don't know, I'm just trying to put forward some possible causes for it not working.
cl_init.lua [lua] function deathmenu() local death = vgui.Create( "DFrame" ) death:Center() death:SetSize( 250, 125 ) death:SetTitle( "You are dead" ) death:SetVisible( true ) death:SetDraggable( false ) death:SetFocus( true ) death:ShowCloseButton( false ) death:MakePopup() death.Paint = function() draw.SimpleText("Testtestrespawnpl0x","DefaultSmall",25,50,Color(0,0,0,255)) end concommand.Add( "death_menu", deathmenu ) local spawn = vgui.Create( "DButton" ) spawn:SetText( "Respawn" ) spawn:SetPos( 25, 95 ) spawn:SetSize( 50, 25 ) spawn.DoClick = function() RunConsoleCommand( "gm_spawn" ) spawn:Remove() end end [/lua] INIT.lua [lua] /*------------------------------------------------------------------------------------------------- Name: gamemode:DoPlayerDeath( ) Desc: Carries out actions when the player dies ---------------------------------------------------------------------------------------------------*/ function GM:DoPlayerDeath( ply, killer ) ply:RunConsoleCommand( "death_menu" ) ply:AddDeaths( 1 ) end [/lua]
Ok. There's several things wrong here. 1. Do NOT override DoPlayerDeath. Just hook into PlayerDeath. 2. RunConsoleCommand is both A. a clientside function and B. not a part of the player metatable, so just use ply:ConCommand. 3. Create the concommand ("death_menu") OUTSIDE of the deathmenu function, otherwise it will never be created. 4. Make sure you set the "spawn" button's parent to the frame. 5. gm_spawn is used to spawn props, it doesn't make you respawn. 6. Remove() is a function for entities, not derma panels. Plus, you want to close teh whole frame and not just the button. Use death:Close(). 7. You're overriding the death.Paint function without drawing the background. That means it will show some text and a close button, but be completely empty otherwise.
And you should really make the button a child of the panel, eg. local spawn = vgui.Create("DButton", death) It might even be technically required for the script not to have a fit and shout at you. Fuck I didn't notice you say that as point 4
It seems i have missed alot. might skip that part of the gamemode a great while.. I suck at derma/vgui so... But is it hook.Add( "PlayerDeath", "whenplayerdieslol" )
[lua] function myfunc(ply) end hook.Add("PlayerDeath", "UniqueHookName", myfunc) [/lua]
Ok so that part i know.. Is there any cmd for respawn player? That way it would be much cooler. I could skip this part. But it would look so neat.
player:Spawn() Thats not a console command, but its a function.
Sorry, you need to Log In to post a reply to this thread.