Help with lua Knock out script

hey guys i am making a lua knockout script so when your heath gets to 20 you be ragdolled can someone tell me how to make the ragdoll take damage e.g if i jump on its head alot it will die.
thanks
|ERP| Enzo

Here’s some help

[lua]if ply:Health > 21 then[/lua]

You or someone else figure the rest.

thanks but tha realy not gunna help me much

Are you coding this yourself? If so you should visit the wiki, wiki.garrysmod.com (I think that should work).

If you aren’t coding this then I guess someone else could do it for you.

But on the wiki in the search bar look for Player, or anything that you think might help you. It will tell you certain functions you can use and how to use it.

If I have some free time today I might work on it.

[lua]
function Knockoutply(ply, time, unknockout)
if not time then time = GetGlobalInt(“knockouttime”) end
unknockout = unknockout or 1
if ply:Alive() and not ply:GetNWBool(“knockedout”) then
local ragdoll = ents.Create(“prop_ragdoll”)
ragdoll:SetPos(ply:GetPos())
ragdoll:SetAngles(Angle(0,ply:GetAngles().Yaw,0))
ragdoll:SetModel(ply:GetModel())
ragdoll:Spawn()
ragdoll:Activate()
ragdoll:SetVelocity(ply:GetVelocity())

	ply:StripWeapons()
	ply:ConCommand("pp_motionblur 1")
	ply:ConCommand("pp_motionblur_addalpha 0.05")
	ply:ConCommand("pp_motionblur_delay 0.035")
	ply:ConCommand("pp_motionblur_drawalpha 1.00")
	
	ply:SetNWEntity("ragdoll", ragdoll)
	ply:SetNWBool("knockedout", true)
	Notify(ply, 1, 4, "You have been knocked out for "..time.." seconds!")
end
if unknockout then timer.Simple(time, UnKnockoutply, ply) end
return ""

end

function UnKnockoutply(ply)
if ply:Alive() and ply:GetNWBool(“knockedout”) then
local ragdoll = ply:GetNWEntity(“ragdoll”)
ply:Spawn()
ply:SetPos(ragdoll:GetPos())
ply:SetAngles(Angle(0,ragdoll:GetPhysicsObjectNum(10):GetAngles().Yaw,0))
ply:UnSpectate()
ply:StripWeapons()
ply:ConCommand(“pp_colormod 0”)
ply:ConCommand(“pp_motionblur 0”)
GAMEMODE:plyLoadout(ply)
ragdoll:Remove()

	ply:SetNWBool("knockedout", false)
	ply:SetNWEntity("ragdoll", nil)
	ply:SelectWeapon("keys")
end

end
[/lua]

[lua]SetGlobalInt(“knockouttime”, 20)[/lua]

[lua]function GM:CalcView(ply, pos, ang, fov)

local death_ragdoll = ply:GetRagdollEntity()
local ko_ragdoll = ply:GetNWEntity("Ragdoll")

if not ply:Alive() and ValidEntity(death_ragdoll) and GetGlobalInt("firstpersondeaths") == 1 then

	local eyes = death_ragdoll:GetAttachment(death_ragdoll:LookupAttachment("eyes"))
	return self.BaseClass:CalcView(ply, eyes.Pos, eyes.Ang, fov)
	
elseif ply:GetNWBool("knockedout") and ValidEntity(ko_ragdoll) then

	local eyes = ko_ragdoll:GetAttachment(ko_ragdoll:LookupAttachment("eyes"))
	return self.BaseClass:CalcView(ply, eyes.Pos, eyes.Ang, fov)
	
else
	return self.BaseClass:CalcView(ply, pos, ang, fov)
end

end[/lua]

[lua]
function GM:CanPlayerSuicide(ply)
if ply:GetNWBool(“knockedout”) then
Notify(ply, 4, 4, “Your currently knocked out.!”)
return false
end
return true
end[/lua]

Something I ripped out of EpicRP

thanks but now i get this error 49: attempt to index global ‘GM’ (a nil value)

replace all the GM:function() stuff with hook and a function

[lua]
function playerHadDied(ply)
if ply:GetNWBool(“knockedout”) then
Notify(ply, 4, 4, “Your currently knocked out.!”)
return false
end
return true
end
hook.Add(“CanPlayerSuicide”, “omgidied”, playerHasDied)
[/lua]
^ Like that

ok i have dosne what mcd1992 said but it still dosent work :S here is the code


 
function Knockoutply(ply, time, unknockout)
	if not time then time = GetGlobalInt("knockouttime") end
	unknockout = unknockout or 1
	if ply:Alive() and not ply:GetNWBool("knockedout") then
		local ragdoll = ents.Create("prop_ragdoll")
		ragdoll:SetPos(ply:GetPos())
		ragdoll:SetAngles(Angle(0,ply:GetAngles().Yaw,0))
		ragdoll:SetModel(ply:GetModel())
		ragdoll:Spawn()
		ragdoll:Activate()
		ragdoll:SetVelocity(ply:GetVelocity())
		
		ply:StripWeapons()
		ply:ConCommand("pp_motionblur 1")
		ply:ConCommand("pp_motionblur_addalpha 0.05")
		ply:ConCommand("pp_motionblur_delay 0.035")
		ply:ConCommand("pp_motionblur_drawalpha 1.00")
		
		ply:SetNWEntity("ragdoll", ragdoll)
		ply:SetNWBool("knockedout", true)
		Notify(ply, 1, 4, "You have been knocked out for "..time.." seconds!")
	end
	if unknockout then timer.Simple(time, UnKnockoutply, ply) end
	return ""
end
hook.Add("Knockoutplayer", "ko", playerHasbeenko)
concommand.add("ko_enzo", Knockoutply)

function UnKnockoutply(ply)
	if ply:Alive() and ply:GetNWBool("knockedout") then
		local ragdoll = ply:GetNWEntity("ragdoll")
		ply:Spawn()
		ply:SetPos(ragdoll:GetPos())
		ply:SetAngles(Angle(0,ragdoll:GetPhysicsObjectNum(10):GetAngles().Yaw,0))
		ply:UnSpectate()
		ply:StripWeapons()
		ply:ConCommand("pp_colormod 0")
		ply:ConCommand("pp_motionblur 0")
		GAMEMODE:plyLoadout(ply)
		ragdoll:Remove()
		
		ply:SetNWBool("knockedout", false)
		ply:SetNWEntity("ragdoll", nil)
		ply:SelectWeapon("keys")
	end
end
hook.Add("UNKnockoutplayer", "unko", playerHasbeenunko)

SetGlobalInt("knockouttime", 20)

function CalcView(ply, pos, ang, fov)

	local death_ragdoll = ply:GetRagdollEntity()
	local ko_ragdoll = ply:GetNWEntity("Ragdoll")
	
	if not ply:Alive() and ValidEntity(death_ragdoll) and GetGlobalInt("firstpersondeaths") == 1 then
	
		local eyes = death_ragdoll:GetAttachment(death_ragdoll:LookupAttachment("eyes"))
		return self.BaseClass:CalcView(ply, eyes.Pos, eyes.Ang, fov)
		
	elseif ply:GetNWBool("knockedout") and ValidEntity(ko_ragdoll) then
	
		local eyes = ko_ragdoll:GetAttachment(ko_ragdoll:LookupAttachment("eyes"))
		return self.BaseClass:CalcView(ply, eyes.Pos, eyes.Ang, fov)
		
	else
		return self.BaseClass:CalcView(ply, pos, ang, fov)
	end
	
end
hook.Add("CalcView", "veiw", calcview)

function CanPlayerSuicide(ply)
	if ply:GetNWBool("knockedout") then
		Notify(ply, 4, 4, "Your currently knocked out.!")
		return false
	end
	return true
end
hook.Add("CanPlayerSuicide", "omgidied", playerHasDied)


hook.Add(“HookType (see link below)”, “a random name”, theFunctionToCallFromThisHook)
UNKnockoutplayer and Knockoutplayer arent hooks

Also everything is case sensitive. You add the hook here:
hook.Add(“CalcView”, “veiw”, calcview)
But the function is CalcView, not calcview.

i dont no what hooks to use!?!