@Rayne_Mercury-legacy (Rayne Mercury) posted a new topic, subject "Limiting the Physgun, and more!". It read:

   In my gamemode, I want players to be able to use the Physgun, but severely limit the range as well as size of objects they're allowed to lift.
    
    Is there an easier way to get the Physgun's functionality (rotate, freeze) but with limited range and size? Maybe in a SWEP? I'm looking through Garrysmod.org as we speak, then I'll probably search these forums.
    
    I think I know how to handle the size issue, I'm using Itemforge, and I'll just disallow using the physgun on anything but Itemforge items, and limit the size using its system.
    
    Next question: Is it possible to remove a weld or nail in a way other than using the Undo key or menu? I just ninja'd myself with this question, never mind, heh.
    
    Sorry, I originally thought I'd have more questions at this point.
    
    Not-EDIT: I'm searching the forums as I post this for information on limiting the physgun. If you have a solution, please let me know.
    
    EDIT: Clarification, for range, I want it to not be able to pick things up if they're a certain distance away (basically arms' length or maybe a bit further, I can handle this part) and if you move it past that range, it drops (and unfreezes if frozen).

Then @Fantym420-legacy (Fantym420) said

    I think you want these two hooks:  
    **[Gamemode.PhysgunDrop
    
    http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PhysgunDrop)**  
    **[Gamemode.PhysgunPickup
    
    http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PhysgunPickup)**
    
    In the pickup hook check for distance and mass limits, set anything special like no collides, color, etc.  
    Then in the Drop hook put everything back to normal if you changed stuff.
    
    Not sure about checking the distance between the player and the entity they grabbed after the initial pickup, but you could probably do a think that checks players and what they are PhysGunning.

Then @Rayne_Mercury-legacy (Rayne Mercury) said

    Yeah, I think I found those before. The trouble comes with actually getting it all to work. I think I can manage the Physgun hooks, it's using the Think one that I have no idea where to begin.

To which @MDave-legacy (MDave) replied

    You should store the picked up entity, and then in a think hook constantly check the player, and the entity distance.
    
    [lua]  
    local max_distance = 100
    
    hook.Add( “PhysgunPickup” “ASD” , function( ply , ent )  
    ply._heldEnt = ent  
    end )  
    hook.Add( “Think” , “ASD2” , function()  
    for _ , ply in pairs( player.GetAll() ) do  
    if ( ply._heldEnt and ply._heldEnt:IsValid() ) then  
    if ( ( ply:GetPos() - ply._heldEnt:GetPos() ):Length() >= max_distance ) then  
    ply._heldEnt:ForcePlayerDrop()  
    ply._heldEnt = nil  
    end  
    end  
    end  
    end )
    
    [/lua]

@Rayne_Mercury-legacy (Rayne Mercury) replied

    Hey, thanks! I'll try this out when I get home today.

After which, @Donkie-legacy (Donkie) added

    Why does everyone do  
    _heldEnt and _heldEnt:IsValid()  
    when you can do  
    ValidEntity(_heldEnt)  
    ?

So @Freze-legacy (Freze) replied

    Looks prettier for some? Like some people has other preferences.  
    if not _heltEnt:IsValid() then return; end  
    ?

To which @Rayne_Mercury-legacy (Rayne Mercury) replied

    Oh, what about if the player freezes an object and then moves out of that range? I'd like for the object to unfreeze if that happens. Seems it's no longer held… Maybe I need something that looks for frozen objects, and makes sure a player is nearby to “hold” it? If there isn't, it unfreezes.


{'source': 'discourse', 'url': 'https://forum.facepunch.com/t/limiting-the-physgun-and-more/84684', 'title': 'Limiting the Physgun, and more!', 'views': 5032, 'has_accepted_answer': False, 'word_count': 540, 'like_count': 0, 'reply_count': 7, 'participant_count': 5, 'posts': 8, 'tags': '', 'author': '@Rayne_Mercury-legacy (Rayne Mercury)', 'participants': '@Rayne_Mercury-legacy (Rayne Mercury), @Fantym420-legacy (Fantym420), @MDave-legacy (MDave), @Donkie-legacy (Donkie), @Freze-legacy (Freze)', 'image_url': [None], 'created_at': '2011-04-28T23:25:24.000Z', 'last_posted_at': '2011-04-30T03:29:00.000Z'}