nap14hockey

Ulx Physics Gun Freeze

Nov 24th, 2017 (edited)
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. --DarkRP Script to freeze players with physicsgun
  2.  
  3. if CLIENT then return end; if not SERVER then return end
  4.  
  5. hook.Remove( "PhysgunDrop", "ulxPlayerDrop") -- We don't need this hook since we have a better hook here.
  6. local function isPlayer(ent) return (IsValid(ent) && ent.GetClass && ent:GetClass() == "player") end
  7.  
  8. local function playerPickup( ply, ent )
  9.     local access, tag = ULib.ucl.query( ply, "ulx physgunplayer" )
  10.     if isPlayer(ent) and access then
  11.         local restrictions = {}
  12.         ULib.cmds.PlayerArg.processRestrictions( restrictions, ply, {}, tag and ULib.splitArgs( tag )[ 1 ] )
  13.         if restrictions.restrictedTargets == false or (restrictions.restrictedTargets and not table.HasValue( restrictions.restrictedTargets, ent )) then
  14.             return false
  15.         end
  16.         return true
  17.     end
  18. end
  19.  
  20. timer.Simple(0.01, function()
  21.     hook.Add("PhysgunPickup", "_ply_physgungrab", function(ply, targ)
  22.         if IsValid(ply) and isPlayer(targ) then
  23.             if ply:query("ulx physgunplayer") and playerPickup( ply, targ ) then
  24.                 local allowed = ULib.getUser( "@", true, ply )
  25.                 if isPlayer(allowed) then
  26.                     if allowed.frozen && ply:query( "ulx unfreeze" ) then
  27.                         allowed.phrozen = true;
  28.                         allowed.frozen = false;
  29.                     end
  30.                      
  31.                     allowed._ulx_physgun = {p=targ:GetPos(), b=true, a=ply}
  32.                 end
  33.             end
  34.         end
  35.     end, tonumber(HOOK_HIGH)-2); MsgAll('LOADED! 1')
  36. end)
  37.  
  38. hook.Add("PlayerSpawn", "_ply_physgungrab", function(ply)
  39.     timer.Simple(0.001, function()
  40.         if IsValid(ply) and ply._ulx_physgun then
  41.             local admin = ply._ulx_physgun.a
  42.             if ply._ulx_physgun.b and ply._ulx_physgun.p and IsValid(admin) then
  43.                 ply:SetPos(ply._ulx_physgun.p);
  44.                 ply:SetMoveType(MOVETYPE_NONE);
  45.                 timer.Simple(0.001, function()
  46.                     if not (IsValid(admin) and admin:KeyDown(IN_ATTACK)) then
  47.                         ply:SetMoveType( MOVETYPE_WALK )
  48.                         ply._ulx_physgun = nil
  49.                         ply:Spawn()
  50.                     end
  51.                 end)
  52.             end
  53.         end
  54.     end)
  55. end)
  56.  
  57. local function physgun_freeze( calling_ply, target_ply, should_unfreeze )
  58.     local v = target_ply
  59.     if v:InVehicle() then
  60.         v:ExitVehicle()
  61.     end
  62.  
  63.     if not should_unfreeze then
  64.         v:Lock()
  65.         v.frozen = true
  66.         v.phrozen = true
  67.         ulx.setExclusive( v, "frozen" )
  68.     else
  69.         v:UnLock()
  70.         v.frozen = nil
  71.         v.phrozen = nil
  72.         ulx.clearExclusive( v )
  73.     end
  74.  
  75.     v:DisallowSpawning( not should_unfreeze )
  76.     ulx.setNoDie( v, not should_unfreeze )
  77.  
  78.     if v.whipped then
  79.         v.whipcount = v.whipamt -- Will make it remove
  80.     end
  81. end
  82.  
  83. timer.Simple(0.01, function()
  84.     hook.Add("OnPhysgunFreeze", "_ulx_physgunfreeze", function(pl, ent)
  85.         if isPlayer(ent) then
  86.             ent:SetMoveType( MOVETYPE_WALK )
  87.             ent._ulx_physgun = nil
  88.         end
  89.     end)
  90.     hook.Add("PhysgunDrop", "_ulx_physgunfreeze", function(pl, ent)
  91.         if isPlayer(ent) then
  92.             ent:SetMoveType( MOVETYPE_WALK )
  93.             ent._ulx_physgun = nil
  94.         end
  95.  
  96.         if IsValid(pl) and isPlayer(ent) then
  97.             if pl:query("ulx freeze") then
  98.                 local isFrozen = ( ent:IsFrozen() or ent.frozen or ent.phrozen );
  99.                 ent:SetMoveType(pl:KeyDown(IN_ATTACK2) and MOVETYPE_NONE or MOVETYPE_WALK);
  100.                 timer.Simple(0.001, function()
  101.                     if pl:KeyDown(IN_ATTACK2) and not isFrozen then
  102.                         if pl:query( "ulx freeze" ) then
  103.                             ent:SetVelocity(ent:GetVelocity()*-1);
  104.                             ulx.freeze( pl, {ent}, false );
  105.                             if ent.frozen then ent.phrozen = true end;
  106.                         end
  107.                     elseif pl:query( "ulx unfreeze" ) and isFrozen then
  108.                         if pl:KeyDown(IN_ATTACK2) and pl:query( "ulx freeze" ) then
  109.                             physgun_freeze(pl, ent, true)
  110.                             timer.Simple(0.001, function() physgun_freeze(pl, ent, false) end);
  111.                         else
  112.                             ulx.freeze( pl, {ent}, true );
  113.                             if not ent.frozen then ent.phrozen = nil end;
  114.                         end
  115.                     end
  116.                 end);
  117.             else
  118.                 ent:SetMoveType( MOVETYPE_WALK )
  119.             end
  120.         end
  121.     end); MsgAll('LOADED! 2')
  122. end)
Advertisement
Add Comment
Please, Sign In to add comment