• Limiting the Physgun, and more!
    7 replies, posted
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).
I think you want these two hooks: [b][url=wiki.garrysmod.com/?title=Gamemode.PhysgunDrop]Gamemode.PhysgunDrop [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [b][url=wiki.garrysmod.com/?title=Gamemode.PhysgunPickup]Gamemode.PhysgunPickup [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] 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.
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.
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]
Hey, thanks! I'll try this out when I get home today.
Why does everyone do _heldEnt and _heldEnt:IsValid() when you can do ValidEntity(_heldEnt) ?
Looks prettier for some? Like some people has other preferences. if not _heltEnt:IsValid() then return; end ?
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.
Sorry, you need to Log In to post a reply to this thread.