• First person player death. Some help needed! [Lua game mode]
    2 replies, posted
So I am currently trying to develop a game mode. This is a private script that I am using to enhance my knowledge of Lua, and will also serve as a reference once I start developing a game mode to be released. With that said, I am currently working on the player's death. When the player dies, the client side ragdoll is removed and a serverside entity ( "prop_ragdoll" ) is created. The serverside ragdoll is set up like so: (in the PlayerDeath hook) [CODE] local DeadPlayer = ents.Create("prop_ragdoll") DeadPlayer.chardata = ply.chardata DeadPlayer:SetPos( ply:GetPos() ) DeadPlayer:SetModel( ply:GetModel() ) DeadPlayer:SetAngles( ply:GetAngles() ) DeadPlayer:Spawn() DeadPlayer:Activate() DeadPlayer:GetPhysicsObject():SetVelocity( ply:GetVelocity()*10 ) DeadPlayer.owner = ply:Nick() DeadPlayer.Timer = timer.Simple( 120, function() local penis = math.Rand( 1, 99999 ) DeadPlayer.dicks = 0 DeadPlayer.Timer = timer.Create( tostring(penis), 0.1, 100, function() DeadPlayer.dicks = DeadPlayer.dicks+1 if DeadPlayer:IsValid() then DeadPlayer:SetRenderMode( RENDERMODE_TRANSALPHA ) DeadPlayer:SetColor( Color( 255, 255, 255, 255-DeadPlayer.dicks*2.5) ) if DeadPlayer.dicks >= 100 then DeadPlayer:Remove() end end end ) end) [/CODE] Please excuse the variables "penis" and "dicks". Those are temporary names. Now, this works. The DeadPlayer ragdoll entity has all of the information that is needed and will be removed after two minutes. It has flaws, and I am aware of that, but for now it functions and I am using it just fine. chardata is the game mode's character data table. The problem is when I want to set the player's view to the ragdoll's view. I have experimented with two different methods: using ply:SetViewEntity( DeadPlayer ). This has flaws: No matter what command I use, the player's camera snaps to Angle( 0, 0, 0 ). ply:SetEyeAngles() doesn't do anything, and ply:SnapEyeAngles() no longer works (returns an error). My second method is using calcview. CalcView is only clientside, and I can't pass the entity to the client. I have tried. One method I even tried was to use ents.FindByClass( "prop_ragdoll" ) and assign some sort of integer to the ragdoll from the server side of things, and then search through the table provided by ents.FindByClass( "prop_ragdoll" ) on the client side, comparing the two integers until one matched (server side int was also networked to the client). This did not work either because the most current ragdoll was not found by ents.FindByClass( "prop_ragdoll" ). My final question would be: How would I go about this? Attaching the player's camera to the ragdoll when the player has died. I would much rather have this be done completely on the server but any method will do. I am not asking for pasted script, I only want some guidance. Thank you for reading through that, and I hope somebody will know what to do!
Use [url=http://wiki.garrysmod.com/page/Net_Library_Usage]the net library[/url] to network the newly created ragdoll to the client, then CalcView everything clientside.
I had tried that previously and it didn't work. I looked back into it though, and found that while networking entities, you have to have a timer.Simple() set for 0.1 seconds before sending it out. I found this in a thread on facepunch. I have it working. Thank you.
Sorry, you need to Log In to post a reply to this thread.