Ragdolls and vehicles: JumpOut

[lua] local RagdollDamage = 0
-------------MALE SOUNDS
local Die1 = Sound(“vo/npc/male01/startle01.wav”)
local Die2 = Sound(“vo/npc/male01/startle02.wav”)

local Pain1 = Sound(“vo/npc/male01/imhurt01.wav”)
local Pain2 = Sound(“vo/npc/male01/imhurt02.wav”)
local Pain3 = Sound(“vo/npc/male01/pain01.wav”)
local Pain4 = Sound(“vo/npc/male01/pain02.wav”)
local Pain5 = Sound(“vo/npc/male01/pain03.wav”)
local Pain6 = Sound(“vo/npc/male01/pain04.wav”)
local Pain7 = Sound(“vo/npc/male01/pain05.wav”)
local Pain8 = Sound(“vo/npc/male01/pain06.wav”)
local Pain9 = Sound(“vo/npc/male01/pain07.wav”)
local Pain10 = Sound(“vo/npc/male01/pain08.wav”)
local Pain11 = Sound(“vo/npc/male01/pain09.wav”)

local Freefall1 = Sound(“vo/npc/male01/no02.wav”)
local Freefall2 = Sound(“vo/npc/male01/no01.wav”)
local Freefall3 = Sound(“vo/npc/male01/help01.wav”)
local Freefall4 = Sound(“vo/npc/male01/watchout.wav”)
local Freefall5 = Sound(“vo/npc/male01/uhoh.wav”)

----------------------------------FEMALE SOUNDS
local FDie1 = Sound(“vo/npc/female01/startle01.wav”)
local FDie2 = Sound(“vo/npc/female01/startle02.wav”)

local FPain1 = Sound(“vo/npc/female01/imhurt01.wav”)
local FPain2 = Sound(“vo/npc/female01/imhurt02.wav”)
local FPain3 = Sound(“vo/npc/female01/pain01.wav”)
local FPain4 = Sound(“vo/npc/female01/pain02.wav”)
local Aaah = Sound(“Bail/aaah.mp3”)
local FPain5 = Sound(“vo/npc/female01/pain03.wav”)
local FPain6 = Sound(“vo/npc/female01/pain04.wav”)
local FPain7 = Sound(“vo/npc/female01/pain05.wav”)
local FPain8 = Sound(“vo/npc/female01/pain06.wav”)
local FPain9 = Sound(“vo/npc/female01/pain07.wav”)
local FPain10 = Sound(“vo/npc/female01/pain08.wav”)
local FPain11 = Sound(“vo/npc/female01/pain09.wav”)

local FFreefall1 = Sound(“vo/npc/female01/no02.wav”)
local FFreefall2 = Sound(“vo/npc/female01/no01.wav”)
local FFreefall3 = Sound(“vo/npc/female01/help01.wav”)
local FFreefall4 = Sound(“vo/npc/female01/watchout.wav”)
local FFreefall5 = Sound(“vo/npc/female01/uhoh.wav”)

—ConsoleCommand
—Disable Ragdoll Damage
if(SERVER)then
function ARRDisableRagdollDamage(player,command,args)
if player:IsPlayer() then
if player:IsAdmin() or player:IsSuperAdmin( ) then
RagdollDamage = RagdollDamage + 1

			if RagdollDamage > 1 then
			RagdollDamage = 0
			end

				if RagdollDamage == 0 then
				Msg("Ragdoll Damage Enabled 

")
end

					if RagdollDamage == 1 then
					Msg("Ragdoll Damage Disabled 

")
end

	end				
end

if not(player:IsPlayer()) then
Msg("!!!Something that wasn't a player executed the WindShieldCannon command!!! 

“)
Msg(”|||It could be CONSOLE or if you are unlucky a player hacking the server|||
")

		RagdollDamage = RagdollDamage + 1

			if RagdollDamage > 1 then
			RagdollDamage = 0
			end

				if RagdollDamage == 0 then
				Msg("Ragdoll Damage Enabled 

")
end

					if RagdollDamage == 1 then
					Msg("Ragdoll Damage Disabled 

")
end
end

end
concommand.Add(“RagdollDamage”,ARRDisableRagdollDamage)
end


local function RanSound(ply, SNDtype)
local Male = true

if string.find(ply:GetModel(), "alyx.mdl") or string.find(ply:GetModel(), "mossman.mdl") or string.find(ply:GetModel(), "female_01.mdl") or string.find(ply:GetModel(), "female_02.mdl") or string.find(ply:GetModel(), "female_03.mdl") or string.find(ply:GetModel(), "female_04.mdl") or string.find(ply:GetModel(), "female_05.mdl") or string.find(ply:GetModel(), "female_06.mdl") or string.find(ply:GetModel(), "female_07.mdl") then
	Male = false
end


if (SERVER) then 

	if Male == true then
		if SNDtype == 1 then
			local RanSound = 	math.random(3,11)

			if RanSound == 1 then
				ply:EmitSound(Pain1)
			end

			if RanSound == 2 then
				ply:EmitSound(Pain2)
			end
			
			if RanSound == 3 then
				ply:EmitSound(Pain3)
			end

			if RanSound == 4 then
				ply:EmitSound(Pain4)
			end

			if RanSound == 5 then
				ply:EmitSound(Pain5)
			end
			
			if RanSound == 6 then
				ply:EmitSound(Pain6)
			end

			if RanSound == 7 then
				ply:EmitSound(Pain7)
			end
			
			if RanSound == 8 then
				ply:EmitSound(Pain8)
			end

			if RanSound == 9 then
				ply:EmitSound(Pain9)
			end
			
			if RanSound == 6 then
				ply:EmitSound(Pain10)
			end	
			
			if RanSound == 6 then
				ply:EmitSound(Pain11)
			end	
		end

				if SNDtype == 2 then
					local RanSound = 	math.random(1,5)

					if RanSound == 1 then
						ply:EmitSound(Freefall1)
					end

					if RanSound == 2 then
						ply:EmitSound(Freefall2)
					end
					
					if RanSound == 3 then
						ply:EmitSound(Freefall3)
					end
	
					if RanSound == 4 then
						ply:EmitSound(Freefall4)
					end
	
					if RanSound == 5 then
						ply:EmitSound(Freefall3)
					end
	
				end	

							if SNDtype == 3 then
								local RanSound = 	math.random(1,2)

									if RanSound == 1 then
										ply:EmitSound(Die1)
									end

									if RanSound == 2 then
										ply:EmitSound(Die2)
									end

							end	
	end

	if Male == false then
		if SNDtype == 1 then
			local RanSound = 	math.random(3,11)

			if RanSound == 1 then
				ply:EmitSound(FPain1)
			end

			if RanSound == 2 then
				ply:EmitSound(FPain2)
			end
			
			if RanSound == 3 then
				ply:EmitSound(FPain3)
			end

			if RanSound == 4 then
				ply:EmitSound(FPain4)
			end

			if RanSound == 5 then
				ply:EmitSound(FPain5)
			end
			
			if RanSound == 6 then
				ply:EmitSound(FPain6)
			end

			if RanSound == 7 then
				ply:EmitSound(FPain7)
			end
			
			if RanSound == 8 then
				ply:EmitSound(FPain8)
			end

			if RanSound == 9 then
				ply:EmitSound(FPain9)
			end
			
			if RanSound == 6 then
				ply:EmitSound(FPain10)
			end	
			
			if RanSound == 6 then
				ply:EmitSound(FPain11)
			end	
		end

				if SNDtype == 2 then
					local RanSound = 	math.random(1,5)

					if RanSound == 1 then
						ply:EmitSound(FFreefall1)
					end

					if RanSound == 2 then
						ply:EmitSound(FFreefall2)
					end
					
					if RanSound == 3 then
						ply:EmitSound(FFreefall3)
					end
	
					if RanSound == 4 then
						ply:EmitSound(FFreefall4)
					end
	
					if RanSound == 5 then
						ply:EmitSound(FFreefall3)
					end
	
				end	

							if SNDtype == 3 then
								local RanSound = 	math.random(1,2)

									if RanSound == 1 then
										ply:EmitSound(FDie1)
									end

									if RanSound == 2 then
										ply:EmitSound(FDie2)
									end

							end	
	end





end

end
--------------------------------Main Code
hook.Add(“PlayerLeaveVehicle”,“ARRThrowOut”,
function(ply,ent)

local Dont = ent:GetNetworkedBool( “ARRDontThrowOut” )
local WinRag = ent:GetNetworkedBool( “ARRWinThrowOut”)

if Dont == true then
		ent:SetNetworkedBool( "ARRDontThrowOut", false )
		--Creating a ragdoll
		local ragdoll = ents.Create( "prop_ragdoll" )
		if WinRag ~= true then
		ragdoll:SetPos( ply:GetPos() + Vector(0,0,50) )
		ragdoll:SetModel( ply:GetModel() )
		ragdoll:SetAngles(Angle((ply:GetAngles().p+90), (ply:GetAngles().y-90), ply:GetAngles().r+90))
		ragdoll:Spawn()
		end

		local Speed = 0
		local Veh = ply.ARRveh

		if WinRag == true then
		ent:SetNetworkedBool( "ARRWinThrowOut", false)
		local  VehPos = (((Veh:GetForward()) * 30) + ((Veh:GetUp()) * 60)) + Veh:GetPos()
		Speed = ent:GetNetworkedInt("ARRLaunchSpeed")
		Speed = Speed * (Veh:GetForward())
		ragdoll:SetPos( VehPos )
		ragdoll:SetModel( ply:GetModel() )
		ragdoll:SetAngles(Angle((ply:GetAngles().p+90), (ply:GetAngles().y-90), ply:GetAngles().r+90))
		ragdoll:Spawn()
		end
		
	
			--Moving some bones so it won't look like a mingebag
			local bones = ragdoll:GetPhysicsObjectCount()
				for i=0,bones-1 do
					if WinRag ~= true then
					ragdoll:GetPhysicsObjectNum(i):SetVelocity( ent:GetVelocity())
					end
					if WinRag == true then
					ragdoll:GetPhysicsObjectNum(i):SetVelocity( ent:GetVelocity() + Speed)
					end
					
					ragdoll:GetPhysicsObjectNum(i):AddAngleVelocity( Vector( math.random(-1000,1000), math.random(-1000,1000), math.random(-1000,1000)) )
					end 

								--Saving weapons
								local weps={}
								for k, v in pairs(ply:GetWeapons()) do
									table.insert(weps,v:GetClass())
								end

											ply.ARRLOLOLOL = false
											local Easteregg = math.random(1,500)
											if Easteregg == 88 then
											ply.ARRLOLOLOL = true												
											end
									--Setting some values on the player
								    ply.ARRHaveDied = true
									ply.ARRIsRagdoll = true
									ply.ARRFallSound = true
									ply.ARRDieOnce = true
								    ply.ARRSoundDel = CurTime()
									ply.ARRBailRagdoll = ragdoll
									ply.ARRSpawnDel = CurTime()+4
									ply.ARRWeps = weps
									ply.ARRLostHp = 0
									ply.ARRCurHP = ply:Health()
									ply:SetParent( ragdoll )
									ply:StripWeapons()
									ply:Spectate( OBS_MODE_CHASE )
									ply:SpectateEntity( ragdoll )
									ply:ConCommand("hidehud 1

")

									if (CLIENT) then
									ply.ARRThaRagdoll = ragdoll
									end

	end		

end)

hook.Add(“Think”,“ARRBailRagdoll”,
function()
for k, v in pairs(player.GetAll()) do
if v.ARRBailRagdoll and (SERVER) then

		--Fetching usable values
		local angle = v:EyeAngles():Forward( )
		local ragdoll = v.ARRBailRagdoll
		local Vel = ragdoll
		Vel = Vel:GetPhysicsObject():GetVelocity():Length()
		local Del = v.ARRSpawnDel

			--  if the velocity is below 200 then the spawn delay won't change.
			if Vel > 200 then
				v.ARRSpawnDel = CurTime()+4
				Del = v.ARRSpawnDel
			end

			-- If the speed is over 1000 the ragdoll will scream once
			if Vel > 1000 and v.ARRFallSound == true then
				RanSound(ragdoll, 2)
					v.ARRSoundDel = CurTime() + 2
				v.ARRFallSound = false
			end
							
			local health = v.ARRCurHP - (v.ARRLostHp/10)
			--Hmm i wonder why i set the health on the player like that?
	
			if health > 1 then
				--making the ragdoll move in the direction you look at
					ragdoll:GetPhysicsObjectNum( 10 ):ApplyForceCenter( Vector(angle.x, angle.y, 0)* 100 )
						ragdoll:GetPhysicsObjectNum( 5 ):ApplyForceCenter( Vector(angle.x, angle.y, 0)* 50 )
				ragdoll:GetPhysicsObjectNum( 6 ):ApplyForceCenter( Vector(angle.x, angle.y, 0)* 50 )
			end

			if health < 1 and (Del-1) > CurTime() then
				--making the ragdoll reach his/her hands towards the sky
					ragdoll:GetPhysicsObjectNum( 5 ):ApplyForceCenter( Vector(0, 0, 50) )
					ragdoll:GetPhysicsObjectNum( 6 ):ApplyForceCenter( Vector(0, 0, 50) )
			end
			
			--I use <= 1 because sometimes hl2 rounds the health in a weird way which makes it possible to spawn an "undead" player.(the player has no hp and can't move but can still shoot)
			if health <= 1 and v.ARRDieOnce == true then
				RanSound(ragdoll, 3)
				v.ARRDieOnce = false
				v:SetParent()
				v:Kill()
				v.ARRIsRagdoll = false
				v:ConCommand("hidehud 0

")
if v[“DeathRagdolls”] then
v.ARRBailRagdoll:Remove()
v.ARRBailRagdoll = nil
end

			end
			--LOLOLOLOL!
			if v.ARRLOLOLOL == true and v.ARRSoundDel < CurTime() then
			v:EmitSound(Aaah)
			v.ARRSoundDel = CurTime() + 10.83				
			end

							--Spawning the player
							if Del < CurTime() then

												local pos = v.ARRBailRagdoll:GetPos()
												pos.z = pos.z + 10 										

											if health > 1 then																						
											v.ARRHaveDied = false
											v:SetParent()
											v.ARRIsRagdoll = false
											v.ARRLOLOLOL = false
											v.ARRBailRagdoll:Remove()
											v.ARRBailRagdoll = nil 
											v:Spawn()	
											v:SetPos(pos)	
											v:ConCommand("hidehud 0

")
v:SetHealth( health )
v:StripWeapons()
local wep = v.ARRWeps
for i=1, #wep, 1 do
v:Give(wep*)
end

										end
							end


			end

	end

end)

hook.Add(“EntityTakeDamage”,“ARRDamageRagdoll”,
function(ent,inf,att,ammount,dmginfo)

-- Usually ragdolls don't take damage but with this code it can.
for k, v in pairs(player.GetAll()) do
	if v.ARRBailRagdoll ==  ent and v.ARRIsRagdoll == true and(SERVER)then 
	
		local count = v.ARRBailRagdoll:GetPhysicsObjectCount()
			ranbone =	math.random(0,(count-1))
				v.ARRBailRagdoll:GetPhysicsObjectNum( ranbone):ApplyForceCenter( Vector(0, 0, 2000) ) -- Make it bounce a little when it hurts

			if v.ARRLOLOLOL == true then
				v.ARRBailRagdoll:GetPhysicsObject():ApplyForceCenter( Vector(math.random(-500000,500000), math.random(-500000,500000), 500000) )				
			end

		if v.ARRLOLOLOL == false and RagdollDamage == 0 then
		 v.ARRLostHp = v.ARRLostHp + ammount
			local CurHealth = v.ARRCurHP - (v.ARRLostHp/10)
				v:SetHealth( CurHealth )
		end
				
		if ammount > 1 and v.ARRSoundDel < CurTime() then --OUCH!
			RanSound(ent, 1)
			v.ARRSoundDel = CurTime() + 2
		end
	end
end

end)


hook.Add(“CanPlayerEnterVehicle”,“ARRDontGoIn”,
function(ply,ent)

if ply.ARRHaveDied == true then return false end --If the player is a ragdoll he/she shouldn’t be able to enter a vehicle
end)

hook.Add(“PlayerSpawn”,“ARRPreventBailGlitches”,
function(ply)
if ply.ARRBailRagdoll then
ply.ARRBailRagdoll:Remove()
ply.ARRBailRagdoll = nil
ply.ARRHaveDied = false
end
end)

hook.Add(“PlayerDeath”,“ARRRemovesDeathRagdoll”,
function(ply)

–We don’t want to have a ragdoll spawned when the player dies since the player already is a ragdoll so we remove it before it’s spawned (sort of)
if ply.ARRHaveDied == true then
ply.ARRHaveDied = false

if not ply[“DeathRagdolls”] then
ply:GetRagdollEntity():Remove()
end
end
end)

hook.Add(“CanTool”,“ARRPreventToolingOfBailRagdoll”,
function(ply,tr,tool) – Don’t play around with the fucking ragdoll!
local ent=tr.Entity
if ent.ARRBailRagdoll then
return false
end
end)

hook.Add(“PhysgunPickup”,“ARRNoPhysgunPhysgun”,
function(ply,ent) – Don’t play around with the fucking ragdoll!
if ent.ARRBailRagdoll then
return false
end
end)

hook.Add(“PlayerDisconnected”,“ARRDontLeaveBailRagdoll”,
function(ply) – Don’t leave shit.
if ply.ARRBailRagdoll then
ply.ARRBailRagdoll:Remove()
end
end)[/lua]

Here’s the problem, a guy made the script called JumpOut.
Here’s what I want to do:
All I want to do is to edit the script so you don’t have to be in a vehicle to ‘jumpout’.

I’m pretty shit at lua, yeah.
I think it has something to do with “PlayerLeaveVehicle”, but there was no details on the hook on the wiki.

You should try ask the maker himself. his name is Sakarias. He should help you better than any one else.

Wow, that is some really bad coding, the lack of tables saddens me.

Yeah, you could’ve really shortened it down with tables.

Yeah I totally could becaue I’m so good with lua… :v:

Let’s do something like this for example: (This is only possible because you named it so nicely :p)
Your code:
[lua]
if SNDtype == 1 then
local RanSound = math.random(3,11)

			if RanSound == 1 then
				ply:EmitSound(Pain1)
			end

			if RanSound == 2 then
				ply:EmitSound(Pain2)
			end
			
			if RanSound == 3 then
				ply:EmitSound(Pain3)
			end

			if RanSound == 4 then
				ply:EmitSound(Pain4)
			end

			if RanSound == 5 then
				ply:EmitSound(Pain5)
			end
			
			if RanSound == 6 then
				ply:EmitSound(Pain6)
			end

			if RanSound == 7 then
				ply:EmitSound(Pain7)
			end
			
			if RanSound == 8 then
				ply:EmitSound(Pain8)
			end

			if RanSound == 9 then
				ply:EmitSound(Pain9)
			end
			
			if RanSound == 6 then
				ply:EmitSound(Pain10)
			end	
			
			if RanSound == 6 then
				ply:EmitSound(Pain11)
			end	
		end

[/lua]
My help: (:D)
[lua] if SNDType == 1 then
ply:EmitSound(Pain…math.random(3,11))
end
[/lua]
I win :smiley: Do that for all the other stuff and see how much nicer that looks, as for your actual problem, I have no idea. :O, so for that I apologize.

I have no idea what the heck you did, I’m not familiar with lua and it is not my code.

ah, nevermind then.

I made it shorter though…

Basically it creates a random number and put’s it like this:
ply:EmitSound(Pain#)