ULX

Author Topic: ULX Physgun freeze - FIXED - UPDATED  (Read 25605 times)

0 Members and 1 Guest are viewing this topic.

Offline Son_Of_Flynn

  • Newbie
  • *
  • Posts: 5
  • Karma: 2
ULX Physgun freeze - FIXED - UPDATED
« on: March 12, 2015, 07:47:11 PM »
I used to have an add on for my server named ULX Physgun, it was made about 2 years ago and I can't even remember who coded it or where it was uploaded originally so sorry to whoever was the original coder, however the recent garry's mod updates as you all know messed with a few things so here is a fix .

Here is a list of the things I changed:

- SetNetworkedVar has been replaces with SetNWInt as it was removed in the latest gmod update.
- Players can longer suicide when physgun frozen.
- I'm not the original author, I'm reloading a fixed and improved version.

To install simply create a new .lua file in garrysmod/lua/autorun and call it something like: ULXPhysgun.lua and just simply paste the code in and restart your server.

It will work for any ULX group that can physgun players.

Code: [Select]
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 )
« Last Edit: March 17, 2015, 07:41:42 PM by Son_Of_Flynn »

Offline eagle9er9er

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #1 on: March 12, 2015, 08:59:51 PM »
I hope you don't hate me for asking a noob question, it's been awhile.

Where do I put this? I've been looking for a script like this forever, thank you.

Offline Stranger Danger

  • Newbie
  • *
  • Posts: 24
  • Karma: 2
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #2 on: March 13, 2015, 12:18:21 AM »
You add it to Root/lua/autorun/server. I have a question, I wanted to modify it to where only admins can freeze and unfreeze targets, I tried adding ent:isAdmin() but ran into the problem that the target was getting stuck frozen and I couldn't unfreeze them. Is there any possible way you can modify it to where it only works with Admins? Much appreciated and very cool idea.

Offline lynx

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 15
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #3 on: March 13, 2015, 02:20:35 AM »
That'd be more a question for the Developer Chat forum, but heres your answer:

Where you have
Code: [Select]
if( ent:IsPlayer() ) then 
If you add
Code: [Select]
and pl:IsAdmin()
To make it
Code: [Select]
if( ent:IsPlayer() and pl:IsAdmin() ) then 
Then it would only run the freeze code if the player holding the other player is an admin. With ent:IsAdmin() it checks if the player being physgunned is an admin so it would return false all the time (unless they are an admin) causing it to not work.


To the OP, I do suggest creating it into an addon format rather than posting code and telling people to put it in autorun. The best way to do it (in my opinion) would be this:
Create a folder in addons called phys_freeze.
In phys_freeze make the following folder structure: /lua/ulx/modules/server/
Save the code into a file called phys_freeze.lua into the server folder.
Create a zip of the phys_freeze folder and upload it as an attachment to your original post.
« Last Edit: March 13, 2015, 02:24:11 AM by lynx »

Offline Son_Of_Flynn

  • Newbie
  • *
  • Posts: 5
  • Karma: 2
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #4 on: March 13, 2015, 06:48:27 AM »
I hope you don't hate me for asking a noob question, it's been awhile.

Where do I put this? I've been looking for a script like this forever, thank you.

I updated the main post with installation instructions.

Offline Son_Of_Flynn

  • Newbie
  • *
  • Posts: 5
  • Karma: 2
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #5 on: March 13, 2015, 07:04:29 AM »
That'd be more a question for the Developer Chat forum, but heres your answer:

Where you have
Code: [Select]
if( ent:IsPlayer() ) then 
If you add
Code: [Select]
and pl:IsAdmin()
To make it
Code: [Select]
if( ent:IsPlayer() and pl:IsAdmin() ) then 
Then it would only run the freeze code if the player holding the other player is an admin. With ent:IsAdmin() it checks if the player being physgunned is an admin so it would return false all the time (unless they are an admin) causing it to not work.


To the OP, I do suggest creating it into an addon format rather than posting code and telling people to put it in autorun. The best way to do it (in my opinion) would be this:
Create a folder in addons called phys_freeze.
In phys_freeze make the following folder structure: /lua/ulx/modules/server/
Save the code into a file called phys_freeze.lua into the server folder.
Create a zip of the phys_freeze folder and upload it as an attachment to your original post.

You could also do:

Code: [Select]
pl:IsUserGroup("YOURUSERGROUP")
To only enable it for certain usergroups, however the group must be able to physgun players.

So in the end it will look like this:

Code: [Select]
if( ent:IsPlayer() and pl:IsUserGroup("example") ) then

Offline Stranger Danger

  • Newbie
  • *
  • Posts: 24
  • Karma: 2
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #6 on: March 13, 2015, 10:52:22 AM »
You could also do:

Code: [Select]
pl:IsUserGroup("YOURUSERGROUP")
To only enable it for certain usergroups, however the group must be able to physgun players.

So in the end it will look like this:

Code: [Select]
if( ent:IsPlayer() and pl:IsUserGroup("example") ) then

Perfect thanks, I didn't realize ent was the object being phys gunned. Thanks for the help and update.
« Last Edit: March 13, 2015, 11:02:48 AM by Stranger Danger »

Offline silentkiller101

  • Newbie
  • *
  • Posts: 14
  • Karma: -1
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #7 on: March 15, 2015, 07:06:53 PM »
So this makes it so you can freeze players with the Physgun?

Offline aidanjohns921

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #8 on: March 16, 2015, 02:09:40 PM »
Very nice script however my console likes to pop out this message whenever I physgun a player regardless of freezing or not (because of letting go is under the same function for unfreezing)

Code: [Select]
[ERROR] lua/autorun/ulxphysgun.lua:25: attempt to call method 'DisallowSpawning' (a nil value)
  1. fn - lua/autorun/ulxphysgun.lua:25
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179

Offline Son_Of_Flynn

  • Newbie
  • *
  • Posts: 5
  • Karma: 2
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #9 on: March 17, 2015, 07:42:49 PM »
Very nice script however my console likes to pop out this message whenever I physgun a player regardless of freezing or not (because of letting go is under the same function for unfreezing)

Code: [Select]
[ERROR] lua/autorun/ulxphysgun.lua:25: attempt to call method 'DisallowSpawning' (a nil value)
  1. fn - lua/autorun/ulxphysgun.lua:25
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179

Thanks for this, it should be fixed now.

Offline pyro199931

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: ULX Physgun freeze - FIXED - UPDATED
« Reply #10 on: March 18, 2015, 09:00:25 PM »
Error in hook PhysgunDrop: lua/autorun/ulxphysgun.lua:25: attempt to call method 'DisallowSpawning' (a nil value)
stack traceback:
   lua/autorun/ulxphysgun.lua:25: in function 'fn'
   addons/ulib/lua/ulib/shared/hook.lua:179: in function <addons/ulib/lua/ulib/shared/hook.lua:162>
   [C]: in function '????????'

[ERROR]
  1. unknown - [C]:-1


lua error :|

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given