• Print

Author Topic: Physgun/Toolgun out = godmode  (Read 4489 times)

0 Members and 1 Guest are viewing this topic.

Offline richlen99

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
  • Server Developer/Maintainer
    • GOOGLE
Physgun/Toolgun out = godmode
« on: July 17, 2015, 06:50:17 pm »
Hello all,

I'm trying to create a quick little script for my server, so people (whom are lazy might I add) won't have to type !(un)god when they have a physgun/toolgun out, to aid in building.


Here's what I've got so far, and I don't know where to go from here.

Code: Lua
  1. hook.Add( "PlayerTick", "BuildMode", function(ply)
  2.     if ply:GetActiveWeapon() == ( "gmod_tool" ) then
  3.         timer.Create( "TOOLGUN", 1, 1, function()
  4.             ply:ConCommand( "ulx god" )
  5.             print("toolgun")
  6.         end )
  7.     elseif ply:GetActiveWeapon() == ( "weapon_physgun" ) then
  8.         timer.Create( "PHYSGUN", 1, 1, function()
  9.             ply:ConCommand( "ulx god" )
  10.             print("physgun")
  11.         end )
  12.     elseif ply:GetActiveWeapon() ~= ( "gmod_tool" ) or ply:GetActiveWeapon() ~= ( "weapon_physgun" ) then
  13.         timer.Create( "INVALIDWEP", 1, 1, function()
  14.             ply:ConCommand( "ulx ungod" )
  15.             print("otherwep")
  16.         end )
  17. end )
« Last Edit: July 17, 2015, 07:38:52 pm by richlen99 »



Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Physgun/Toolgun out = godmode
« Reply #1 on: July 18, 2015, 01:25:18 am »
Think/Tick are expensive time constraints in Gmod for any code.
I'd look more into possible equip/select/deploy hooks before using a think every tick/frame.
It's been years since I tinkered, but poking into the wiki, tool:deploy might be a better hook.
http://wiki.garrysmod.com/page/TOOL/Deploy

Be warned though - even if you develop working code, exploits/cheaters will abuse this.
Imagine how easy it will be to switch from a weapon/pvp to a tool/god just to avoid being killed.
« Last Edit: July 18, 2015, 01:28:12 am by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Physgun/Toolgun out = godmode
« Reply #2 on: July 18, 2015, 09:56:30 pm »
I believe this would work even better.  http://wiki.garrysmod.com/page/GM/PlayerSwitchWeapon

What exactly were you asking for help with?

  • Print