• Print

Author Topic: ULX Physgun  (Read 27125 times)

0 Members and 1 Guest are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
ULX Physgun
« on: April 05, 2013, 02:08:35 pm »
I feel that the physgun has become quite outdated so I am aiming to change it, as you can see currently this is very simple and lets admins freeze players like they would props.

Code: [Select]
-- Last Updated On JUN 21ST, 2015 --
-- I need to recode allot of my old stuff, maybe I'll release a pack someday (#valvetime). --

if CLIENT then return end; if not SERVER then return end

hook.Remove( "PhysgunDrop", "ulxPlayerDrop") -- We don't need this hook since we have a better hook here.
local function isPlayer(ent) return (IsValid(ent) && ent.GetClass && ent:GetClass() == "player") end

local function playerPickup( ply, ent )
local access, tag = ULib.ucl.query( ply, "ulx physgunplayer" )
if isPlayer(ent) and access then
local restrictions = {}
ULib.cmds.PlayerArg.processRestrictions( restrictions, ply, {}, tag and ULib.splitArgs( tag )[ 1 ] )
if restrictions.restrictedTargets == false or (restrictions.restrictedTargets and not table.HasValue( restrictions.restrictedTargets, ent )) then
return false
end
return true
end
end

timer.Simple(0.01, function()
hook.Add("PhysgunPickup", "_ply_physgungrab", function(ply, targ)
if IsValid(ply) and isPlayer(targ) then
if ply:query("ulx physgunplayer") and playerPickup( ply, targ ) then
local allowed = ULib.getUser( "@", true, ply )
if isPlayer(allowed) then
if allowed.frozen && ply:query( "ulx unfreeze" ) then
allowed.phrozen = true;
allowed.frozen = false;
end

allowed._ulx_physgun = {p=targ:GetPos(), b=true, a=ply}
end
end
end
end, tonumber(HOOK_HIGH)-2); MsgAll('LOADED! 1')
end)

hook.Add("PlayerSpawn", "_ply_physgungrab", function(ply)
timer.Simple(0.001, function()
if IsValid(ply) and ply._ulx_physgun then
local admin = ply._ulx_physgun.a
if ply._ulx_physgun.b and ply._ulx_physgun.p and IsValid(admin) then
ply:SetPos(ply._ulx_physgun.p);
ply:SetMoveType(MOVETYPE_NONE);
timer.Simple(0.001, function()
if not (IsValid(admin) and admin:KeyDown(IN_ATTACK)) then
ply:SetMoveType( MOVETYPE_WALK )
ply._ulx_physgun = nil
ply:Spawn()
end
end)
end
end
end)
end)

local function physgun_freeze( calling_ply, target_ply, should_unfreeze )
local v = target_ply
if v:InVehicle() then
v:ExitVehicle()
end

if not should_unfreeze then
v:Lock()
v.frozen = true
v.phrozen = true
ulx.setExclusive( v, "frozen" )
else
v:UnLock()
v.frozen = nil
v.phrozen = nil
ulx.clearExclusive( v )
end

v:DisallowSpawning( not should_unfreeze )
ulx.setNoDie( v, not should_unfreeze )

if v.whipped then
v.whipcount = v.whipamt -- Will make it remove
end
end

timer.Simple(0.01, function()
hook.Add("OnPhysgunFreeze", "_ulx_physgunfreeze", function(pl, ent)
if isPlayer(ent) then
ent:SetMoveType( MOVETYPE_WALK )
ent._ulx_physgun = nil
end
end)
hook.Add("PhysgunDrop", "_ulx_physgunfreeze", function(pl, ent)
if isPlayer(ent) then
ent:SetMoveType( MOVETYPE_WALK )
ent._ulx_physgun = nil
end

if IsValid(pl) and isPlayer(ent) then
if pl:query("ulx freeze") then
local isFrozen = ( ent:IsFrozen() or ent.frozen or ent.phrozen );
ent:SetMoveType(pl:KeyDown(IN_ATTACK2) and MOVETYPE_NONE or MOVETYPE_WALK);
timer.Simple(0.001, function()
if pl:KeyDown(IN_ATTACK2) and not isFrozen then
if pl:query( "ulx freeze" ) then
ent:SetVelocity(ent:GetVelocity()*-1);
ulx.freeze( pl, {ent}, false );
if ent.frozen then ent.phrozen = true end;
end
elseif pl:query( "ulx unfreeze" ) and isFrozen then
if pl:KeyDown(IN_ATTACK2) and pl:query( "ulx freeze" ) then
physgun_freeze(pl, ent, true)
timer.Simple(0.001, function() physgun_freeze(pl, ent, false) end);
else
ulx.freeze( pl, {ent}, true );
if not ent.frozen then ent.phrozen = nil end;
end
end
end);
else
ent:SetMoveType( MOVETYPE_WALK )
end
end
end); MsgAll('LOADED! 2')
end)

How to install: Put it in "lua/autorun/" make sure that its a ".lua" file.

Current Error: Players can still kill them selves while being held.

I plan this to be expanded with new and innovative ideas, if you have an idea but don't know how to code feel free to post any way because I am sure that some one who does know how to code may pick it up.

(This is not a release because it is not done yet. I will make a release post when its done or close to being done.)
(This does work tho.)

---------------------------------------------------------------
P.S: A big thanks to CapsAdmin and Python1320. (You see I got the idea from QBox.)
« Last Edit: June 10, 2017, 08:43:27 pm by LuaTenshi »
I cry every time I see that I am not a respected member of this community.

Offline Joram

  • Newbie
  • *
  • Posts: 4
  • Karma: -1
Re: ULX Physgun
« Reply #1 on: August 14, 2014, 10:46:24 am »
Excuse me if I am grave digging here but is there a way to add a usergroup and command to it?

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: ULX Physgun
« Reply #2 on: August 21, 2014, 05:32:13 pm »
if your just wanting to allow a group only to use the weapon you want to add.

Code: Lua
  1. ITEM.AllowedUserGroups = { "superadmin", "admin", "donator", "etc" }

easy enough, just put it below the rest of your ITEM codes and your good to go, takes affect the next map change


"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Joram

  • Newbie
  • *
  • Posts: 4
  • Karma: -1
Re: ULX Physgun
« Reply #3 on: August 29, 2014, 04:10:43 am »
No I ment a rank to freeze a player, Like moderators can pickup but not freeze

Offline ChaosWolf

  • Jr. Member
  • **
  • Posts: 94
  • Karma: 2
  • "The Exiled One's" Server Owner
Re: ULX Physgun
« Reply #4 on: August 29, 2014, 10:26:28 am »
I don't see why you couldn't use the freeze command then pick them up. As for freezing in mid air like a prop. I don't know.
"Someone once told me, scripting lua is like trying to build a rocket ship, once your finished with it and think your done, you start it up only to realize you had just built it upside down." ~Programmer

Offline Joram

  • Newbie
  • *
  • Posts: 4
  • Karma: -1
Re: ULX Physgun
« Reply #5 on: August 31, 2014, 12:18:32 pm »
Because we are using it now it's really usefull for grabbing a minge quickly and freeze them, But I would like to restrict ranks to it

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: ULX Physgun
« Reply #6 on: August 31, 2014, 02:23:16 pm »
bind b "ulx freeze @"

That'll freeze whoever you're looking at.
Out of the Garry's Mod business.

Offline Joram

  • Newbie
  • *
  • Posts: 4
  • Karma: -1
Re: ULX Physgun
« Reply #7 on: September 09, 2014, 06:59:15 am »
Waw didn't know about that one!

But I modified it (It's alot for me)
it's probally shitty but people may be worse then me so:

Code: [Select]
function FGod( ply, dmginfo )
if(ply:GetNetworkedVar("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" ) --This hook from ULX seems to break this script that's why we are removing it here.

ent._physgunned = false

if( ent:IsPlayer() && ( pl:IsUserGroup( "YourAdminGroupHere" ) or pl:IsUserGroup( "YourSecondAdminGroupHere" )) ) then     --If you want to insert another one insert "or pl:IsUserGroup( "YetAnotherGroup" )"       
-- predicted?

if(pl:KeyDown(IN_ATTACK2)) then
ent:Freeze(true)
ent:SetNetworkedVar("FGod", 1)
ent:SetMoveType(MOVETYPE_NOCLIP)
else
ent:Freeze(false)
ent:SetNetworkedVar("FGod", 0)
ent:SetMoveType(MOVETYPE_WALK)
end



if SERVER then
-- NO UUUU FKR
if !ent:Alive() then
ent:Spawn()
self:PlayerSpawn(ent)
ent:SetPos(pl:GetEyeTrace().HitPos)
end
end

else -- If it wasn't an admin in your defined groups then don't do anything
ent:Freeze(false)
ent:SetNetworkedVar("FGod", 0)
ent:SetMoveType(MOVETYPE_WALK)

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 )

Offline 007section1

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: ULX Physgun
« Reply #8 on: November 08, 2014, 08:24:11 am »
which lua file folder should i do it in ive tried the gmod lua then the gmod ulib how do i do it im really stuck

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: ULX Physgun
« Reply #9 on: March 29, 2015, 09:08:25 pm »
I have updated the code above, it should now work for everyone. Without even having to remove the hooks from ULX!
I cry every time I see that I am not a respected member of this community.

Offline Livaco

  • Full Member
  • ***
  • Posts: 133
  • Karma: -37
    • Livaco
Re: ULX Physgun
« Reply #10 on: April 02, 2015, 12:47:05 am »
Good Idea Because People Woint Jump Down From Admin Sits And If Theirs None There Just Freeze Them Up Into The Air!
Here To Help And Be Happy And Help :)

My Website
My Addons
PermaBanV1.0

Quote from:  Livaco on April 12 at 9:10:20 PM
I May Be Dum But Am Still Better Then The Rest

Livaco Products©

  • Print