Okay, so. I have this script installed on my server: lua/autorun/physgun_ply_freeze.lua
It allows anyone who has "ulx physgunplayer" enabled on their ULX Group to Freeze & Unfreeze players like as if they were a prop.
Here's the code:
[code]
local CATEGORY_NAME = "Livaco"
function FGod( ply, dmginfo )
if(ply:GetNWInt("FGod") == 1) then
dmginfo:ScaleDamage( 0 )
end
end
hook.Add("EntityTakeDamage", "FGod", FGod)
hook.Add("PhysgunDrop", "ply_physgunfreeze", function(pl, ent)
hook.Remove( "PhysgunDrop", "ulxPlayerDrop" )
ent._physgunned = false
if( ent:IsPlayer() ) then
ent:SetMoveType(pl:KeyDown(IN_ATTACK2) and MOVETYPE_NOCLIP or MOVETYPE_WALK)
if(pl:KeyDown(IN_ATTACK2)) then
ent:Freeze(true)
ent:SetNWInt("FGod", 1)
ent:DisallowSpawning( not should_unfreeze )
ulx.setNoDie( ent, not should_unfreeze )
table.insert( affected_plys, ent )
else
ent:Freeze(false)
ent:SetNWInt("FGod", 0)
ent:DisallowSpawning( false )
ulx.setNoDie( ent, should_unfreeze )
table.insert( affected_plys, ent )
end
if SERVER then
if !ent:Alive() then
ent:Spawn()
self:PlayerSpawn(ent)
ent:SetPos(pl:GetEyeTrace().HitPos)
end
end
return --self.BaseClass:PhysgunDrop( pl , ent )
end
end)
hook.Add( "PhysgunPickup", "ply_physgunned", function(pl, ent)
ent._physgunned = true
end)
function playerDies( pl, weapon, killer )
if(pl._physgunned) then
return false
else
return true
end
end
hook.Add( "CanPlayerSuicide", "playerNoDeath", playerDies )
[/code]
It works but I'm getting this error:
[code]
Error in hook PhysgunDrop: lua/autorun/physgun_ply_freeze.lua:26: attempt to call method 'DisallowSpawning' (a nil value)
stack traceback:
lua/autorun/physgun_ply_freeze.lua:26: in function 'fn'
addons/ulib/lua/ulib/shared/hook.lua:109: in function <addons/ulib/lua/ulib/shared/hook.lua:92>
[C]: in function '•‎​‬‪•'
[ERROR]
1. unknown - [C]:-1
[/code]
Anyone know why this is happening? Any help is greatly appreciated!
Are you sure DisallowSpawning is a shared function?
[editline]23rd April 2017[/editline]
[img]http://i.imgur.com/zomnFeP.png[/img]
[QUOTE=zoox;52140770]Are you sure DisallowSpawning is a shared function?
[editline]23rd April 2017[/editline]
[img]http://i.imgur.com/zomnFeP.png[/img][/QUOTE]
What do you mean, should I put this script server side?
Yes
[QUOTE=zoox;52140904]Yes[/QUOTE]
Okay thanks man, it's working
What is the updated code for this? sorry im a noob at lua
[QUOTE=emckinnoniv;52159548]What is the updated code for this? sorry im a noob at lua[/QUOTE]
make a file called something like: ulx_physply_freeze.lua and place it in: lua/autorun/server/
then paste the following code into the file we made.
[code]
local CATEGORY_NAME = "Livaco"
function FGod( ply, dmginfo )
if(ply:GetNWInt("FGod") == 1) then
dmginfo:ScaleDamage( 0 )
end
end
hook.Add("EntityTakeDamage", "FGod", FGod)
hook.Add("PhysgunDrop", "ply_physgunfreeze", function(pl, ent)
hook.Remove( "PhysgunDrop", "ulxPlayerDrop" )
ent._physgunned = false
if( ent:IsPlayer() ) then
ent:SetMoveType(pl:KeyDown(IN_ATTACK2) and MOVETYPE_NOCLIP or MOVETYPE_WALK)
if(pl:KeyDown(IN_ATTACK2)) then
ent:Freeze(true)
ent:SetNWInt("FGod", 1)
ent:DisallowSpawning( not should_unfreeze )
ulx.setNoDie( ent, not should_unfreeze )
table.insert( affected_plys, ent )
else
ent:Freeze(false)
ent:SetNWInt("FGod", 0)
ent:DisallowSpawning( false )
ulx.setNoDie( ent, should_unfreeze )
table.insert( affected_plys, ent )
end
if SERVER then
if !ent:Alive() then
ent:Spawn()
self:PlayerSpawn(ent)
ent:SetPos(pl:GetEyeTrace().HitPos)
end
end
return --self.BaseClass:PhysgunDrop( pl , ent )
end
end)
hook.Add( "PhysgunPickup", "ply_physgunned", function(pl, ent)
ent._physgunned = true
end)
function playerDies( pl, weapon, killer )
if(pl._physgunned) then
return false
else
return true
end
end
hook.Add( "CanPlayerSuicide", "playerNoDeath", playerDies )
[/code]
im getting this error in console on my server:
[ERROR] lua/autorun/server/ulx_physply_freeze.lua:22: bad argument #1 to 'insert' (table expected, got nil)
1. insert - [C]:-1
2. fn - lua/autorun/server/ulx_physply_freeze.lua:22
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:109
[QUOTE=emckinnoniv;52161835]im getting this error in console on my server:
[ERROR] lua/autorun/server/ulx_physply_freeze.lua:22: bad argument #1 to 'insert' (table expected, got nil)
1. insert - [C]:-1
2. fn - lua/autorun/server/ulx_physply_freeze.lua:22
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:109[/QUOTE]
Probably because in the script there's no table defined as 'affected_plys', maybe it was left out.
EDIT: Just checking, do you have ulx and ulib? If not that might be it.
[QUOTE=dgrawns;52163683]Probably because in the script there's no table defined as 'affected_plys', maybe it was left out.
EDIT: Just checking, do you have ulx and ulib? If not that might be it.[/QUOTE]
I don't think he does, or atleast doesn't have an updated version of it.
[QUOTE=dgrawns;52163683]Probably because in the script there's no table defined as 'affected_plys', maybe it was left out.
EDIT: Just checking, do you have ulx and ulib? If not that might be it.[/QUOTE]
I do have ulx
Sorry, you need to Log In to post a reply to this thread.