• Spawn/Loadout menu
    5 replies, posted
Basically what I want to do is to have a menu where after the player dies, he will go to. From there he needs to choose a loadout, the only thing I need is how can I show the player, a second after he dies ~, the menu(its a full screen menu with a bar down that you can choose from). He will have a button to spawn back inside. Right now I have the default death, die and stay ragdolled on the ground until you press Enter/Space.
So you could use the [url=http://wiki.garrysmod.com/page/GM/PlayerDeath]PlayerDeath[/url] hook with a [url=http://wiki.garrysmod.com/page/timer/Simple]simple timer[/url] in it that sends the player a net message after one second to open the menu. I think you have to override the [url=http://wiki.garrysmod.com/page/GM/PlayerDeathThink]PlayerDeathThink[/url] hook to prevent the player from spawning any other way (ie. pressing keys or clicking). I think the best method to check when the player is ready to spawn is have the player send a net message to the server to tell it, probably in the button.DoClick. [lua] -- Set the network strings util.AddNetworkString( "PlayerReadyToRespawn" ) -- Client to server message util.AddNetworkString( "PlayerOpenLoadout" ) -- Server to client message net.Receive( "PlayerReadyToRespawn", function( len, ply ) ply.ReadyToRespawn = true -- Set the variable on the player end ) function GM:PlayerDeathThink( ply ) if ply.ReadyToRespawn then ply:Spawn() end -- If the player is ready to respawn then respawn them return false end function GM:PlayerDeath( ply ) ply.ReadyToRespawn = false -- Set/Reset the variable on the player timer.Simple( 1, function() -- Wait one second net.Start( "PlayerOpenLoadout" ) -- Send the player the message net.Send( ply ) end ) end [/lua]
[QUOTE=Internet1001;44596274]So you could use the [url=http://wiki.garrysmod.com/page/GM/PlayerDeath]PlayerDeath[/url] hook with a [url=http://wiki.garrysmod.com/page/timer/Simple]simple timer[/url] in it that sends the player a net message after one second to open the menu. I think you have to override the [url=http://wiki.garrysmod.com/page/GM/PlayerDeathThink]PlayerDeathThink[/url] hook to prevent the player from spawning any other way (ie. pressing keys or clicking). I think the best method to check when the player is ready to spawn is have the player send a net message to the server to tell it, probably in the button.DoClick. [lua] -- Set the network strings util.AddNetworkString( "PlayerReadyToRespawn" ) -- Client to server message util.AddNetworkString( "PlayerOpenLoadout" ) -- Server to client message net.Receive( "PlayerReadyToRespawn", function( len, ply ) ply.ReadyToRespawn = true -- Set the variable on the player end ) function GM:PlayerDeathThink( ply ) if ply.ReadyToRespawn then ply:Spawn() end -- If the player is ready to respawn then respawn them return false end function GM:PlayerDeath( ply ) ply.ReadyToRespawn = false -- Set/Reset the variable on the player timer.Simple( 1, function() -- Wait one second net.Start( "PlayerOpenLoadout" ) -- Send the player the message net.Send( ply ) end ) end [/lua][/QUOTE] Thank you so much, though I have one more question. I dont want to have the menu when the player is dead at the background. I want to set the "camera" facing another direction, such as the skies or maybe a view from above of the map. Would like a link to the wiki or just an easy implementation of it in the code.
Use the [url=http://wiki.garrysmod.com/page/GM/CalcView]CalcView[/url] hook. [lua]hook.Add( "CalcView", "DeathView", function( ply, pos, ang, fov ) -- This hook modifies the camera's view/position if not ply:Alive() then -- and menu:IsValid() to make sure this only appears with the loadout menu open -- also make sure the menu isn't local or localize it outside a function local view = {} -- CamData table ([url]http://wiki.garrysmod.com/page/Structures/CamData[/url]) view.origin = ply:GetPos() +Vector( 0, 0, 1000 ) -- Set the camera to 1000 units above the player's position -- It's a bad idea to set a fixed position because of variations in map heights etc view.angles = Angle( 90, 0, 0 ) -- Set the player's view downward -90 will look upward view.fov = 120 -- Set the player's FOV wider, so they can see more return view end end )[/lua]
[QUOTE=Internet1001;44597628]Use the [url=http://wiki.garrysmod.com/page/GM/CalcView]CalcView[/url] hook. [lua]hook.Add( "CalcView", "DeathView", function( ply, pos, ang, fov ) -- This hook modifies the camera's view/position if not ply:Alive() then -- and menu:IsValid() to make sure this only appears with the loadout menu open -- also make sure the menu isn't local or localize it outside a function local view = {} -- CamData table ([url]http://wiki.garrysmod.com/page/Structures/CamData[/url]) view.origin = ply:GetPos() +Vector( 0, 0, 1000 ) -- Set the camera to 1000 units above the player's position -- It's a bad idea to set a fixed position because of variations in map heights etc view.angles = Angle( 90, 0, 0 ) -- Set the player's view downward -90 will look upward view.fov = 120 -- Set the player's FOV wider, so they can see more return view end end )[/lua][/QUOTE] [CODE]function DrawSpawnMenu( data ) end usermessage.Hook( "SpawnMenuOpen" ,DrawSpawnMenu) local function OriginCam() local CamData = {} CamData.angles = Angle(90,LocalPlayer():EyeAngles().yaw,0) CamData.origin = LocalPlayer():GetPos()+Vector(0,0,500) CamData.x = 0 CamData.y = 0 CamData.w = ScrW() CamData.h = ScrH() render.RenderView( CamData ) end hook.Add("HUDPaint", "OriginCam", OriginCam)[/CODE] I have this code, but it shows the aerial view even when I'm not dead. How can I fix it so only when I die it shows the aerial view? and when I press a button for example it goes back to normal.
Right after OriginCam add: [lua]// If the player isn't valid, we can't do anything so return // OR the player is valid and the player is alive; then return as well if ( !IsValid( LocalPlayer( ) ) || ( IsValid( LocalPlayer( ) ) && LocalPlayer( ):Alive( ) ) then return; end[/lua] That'll make it so that if the player is valid, and dead, it'll do that view.
Sorry, you need to Log In to post a reply to this thread.