Guest User

28401880d

a guest
Feb 27th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.35 KB | None | 0 0
  1. /*----------------------------------------------------------------------------------------------------------------------------------------------------
  2. -- Addon: APAnti
  3. -- Author: LuaTenshi
  4. -- Contact: [email protected]
  5. ----------------------------------------------------------------------------------------------------------------------------------------------------*/
  6.  
  7. APA = APA or {} -- Do not remove.
  8. APA.Ghost = APA.Ghost or {} -- Do not remove.
  9. APA.Settings = APA.Settings or {} -- Do not remove.
  10. APA.Settings.FPP = APA.Settings.FPP or {} -- Do not remove.
  11.  
  12. /*----------------------------------------------------------------------------------------------------------------------------------------------------
  13. -- WARNING: Do not edit any thing above this line unless you know what you are doing!
  14. -- Below you will find the server settings!
  15. ----------------------------------------------------------------------------------------------------------------------------------------------------*/
  16.  
  17. -- Setting this to 1 will enable Anti Prop Kill, setting it to 0 will disable it!
  18. APA.Settings.AntiPK = 1
  19. -- Setting this to 1 will enable returning damage setting it to 0 will disable it!
  20. APA.Settings.DamageReturn = 1
  21. -- Setting this to 1 will stop vehicles from doing damage.
  22. APA.Settings.VehiclesDontHurt = 1
  23. -- Setting this to 1 will block explosions, setting it to 0 will disable it!
  24. APA.Settings.BlockExplosions = 1
  25. -- Setting this to 1 will make vehicles not collide with players.
  26. APA.Settings.NoCollideVehicles = 1
  27. -- Setting this to 1 will enable Anti Prop Push, setting it to 2 will make this also check constrains, while setting it to 0 will disable it!
  28. APA.Settings.AntiPush = 1
  29. -- Setting this to 1 will make props phase through players only, setting it to 0 will make props phase through every thing! (Requires: APA.Settings.AntiPush to be enabled!)
  30. APA.Settings.APCollision = 1 --(Requires: APA.Settings.AntiPush to be enabled!)
  31. -- Setting this to 1 will make it so that props are ghosted when they spawn, while setting it to 0 will disable it!
  32. APA.Settings.GhostOnSpawn = 1
  33. -- Setting this to 1 will make it impossible to fling props, while setting it to 0 will allow you to fling props normally.
  34. APA.Settings.Nerf = 1 -- Note: Setting physgun_maxSpeed to 400 (Default: 5000), will make this work better, and limmit how fast people can move props with their physgun.
  35. -- Setting this to 1 will attempt to automatically block huge props, setting this to 0 will disable it!
  36. APA.Settings.FPP.AutoBlock = 1 -- (Requires: Falco's Prop Protection!)
  37. APA.Settings.FPP.ABSize = 5.85 --How big a prop should be before it is blocked. (Requires: RemoveBig to be set to 1!)
  38. APA.Settings.FPP.Sounds = 0 --Setting this to 1 will make an error sound, when a prop is autoblocked. (Requires: RemoveBig to be set to 1!)
  39. -- Set to 1 to enable the Blacklist, and to 0 to disable it!
  40. APA.Settings.Blacklist = 1
  41. -- Set to 1 to enable the Whitelist, and to 0 to disable it!
  42. APA.Settings.Whitelist = 0
  43. -- Set to 1 to make weapons not collide with any thing except the world, and set to 0 to make weapons collide like normal.
  44. APA.Settings.NoCollideWeapons = 1
  45. -- Set to 1 to automatically freeze props over time, and set to 0 to disable. (Requires: Map restart.)
  46. APA.Settings.AutoFreeze = 0
  47. -- How long to wait before freezing all props. (Default: 300) (Requires: apa_autofreeze to be set to 1!)
  48. APA.Settings.AutoFreezeTime = 300
  49.  
  50. /*----------------------------------------------------------------------------------------------------------------------------------------------------
  51. -- This Blacklist will allow the Anti Prop Kill to detect things that it would not normally detect.
  52. -- Add things using their partial or full class names.
  53. -- Make sure to never change this text " local ClassBlacklist = { ", and use the preset below as an example.
  54. ----------------------------------------------------------------------------------------------------------------------------------------------------*/
  55.  
  56. local ClassBlacklist = {
  57.     "prop_physics",
  58.     "money",
  59.     "cheque",
  60.     "light",
  61.     "playx",
  62.     "lawboard",
  63.     "fadmin_motd",
  64.     "fadmin_jail",
  65.     "prop",
  66.     "wire"
  67. }
  68.  
  69. /*----------------------------------------------------------------------------------------------------------------------------------------------------
  70. -- This Whitelist will allow the Anti Prop Kill to ignore things that it would normally detect.
  71. -- Add things using their partial or full class names.
  72. -- Make sure to never change this text " local ClassWhitelist = { ", and use the preset below as an example.
  73. ----------------------------------------------------------------------------------------------------------------------------------------------------*/
  74.  
  75. local ClassWhitelist = {
  76.     "",
  77.     "",
  78.     ""
  79. }
  80.  
  81. /*----------------------------------------------------------------------------------------------------------------------------------------------------
  82. -- Congradulations, you are now ready to start using this script on your server! If you get any errors please report them to me!
  83. -- WARNING: Do not edit any thing below this line unless you know what you are doing!
  84. ----------------------------------------------------------------------------------------------------------------------------------------------------*/
  85.  
  86. --- Loading Console Vars ---
  87.  
  88. CreateConVar("apa_antipk", APA.Settings.AntiPK, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will enable Anti Prop Kill, setting it to 0 will disable it!")
  89. CreateConVar("apa_antipk_punish", APA.Settings.DamageReturn, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will hurt the person who through the prop!")
  90. CreateConVar("apa_vehiclesdonthurt", APA.Settings.VehiclesDontHurt, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will stop vehicles from doing damage.")
  91. CreateConVar("apa_blockexplosions", APA.Settings.BlockExplosions, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will block explosions, setting it to 0 will disable it!")
  92. CreateConVar("apa_nocollidevehicles", APA.Settings.NoCollideVehicles, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will make vehicles not collide with players.")
  93. CreateConVar("apa_antipush", APA.Settings.AntiPush, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will enable Anti Prop Push, setting it to 2 will make this also check constrains, while setting it to 0 will disable it!")
  94. CreateConVar("apa_apcollision", APA.Settings.APCollision, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will make props phase through players only, setting it to 0 will make props phase through every thing! (Requires: apa_antipush to be set to 1!)")
  95. CreateConVar("apa_ghostonspawn", APA.Settings.GhostOnSpawn, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will make it so that props are ghosted when they spawn, while setting it to 0 will disable it!")
  96. CreateConVar("apa_nerf", APA.Settings.Nerf, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will make it impossible to fling props, while setting it to 0 will allow you to fling props normally. Note: Setting physgun_maxSpeed to 400 (Default: 5000), will make this work better, and limmit how fast people can move props with their physgun.")
  97. CreateConVar("apa_fpp_autoblock", APA.Settings.FPP.AutoBlock, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to true will attempt to automatically block huge props, setting this to false will disable it! (Requires: Falco's Prop Protection!)")
  98. CreateConVar("apa_fpp_absize", APA.Settings.FPP.ABSize, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "How big a prop should be before it is blocked. (Requires: apa_fpp_autoblock to be set to 1!)")
  99. CreateConVar("apa_fpp_sounds", APA.Settings.FPP.Sounds, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Setting this to 1 will make an error sound, when a prop is autoblocked.")
  100. CreateConVar("apa_blacklist", APA.Settings.Blacklist, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Set to 1 to enable the Blacklist, and to 0 to disable it!")
  101. CreateConVar("apa_whitelist", APA.Settings.Whitelist, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Set to 1 to enable the Whitelist, and to 0 to disable it!")
  102. CreateConVar("apa_nocollideweapons", APA.Settings.NoCollideWeapons, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Set to 1 to make weapons not collide with any thing except the world, and set to 0 to make weapons collide like normal.")
  103. CreateConVar("apa_autofreeze", APA.Settings.AutoFreeze, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "Set to 1 to automatically freeze props over time, and set to 0 to disable. (Requires: Map restart.)")
  104. CreateConVar("apa_autofreeze_time", APA.Settings.AutoFreezeTime, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE, FCVAR_NOTIFY}, "How long to wait before freezing all props. (Default: 300) (Requires: apa_autofreeze to be set to 1!)")
  105.  
  106. --- DONE ---
  107.  
  108. local function APAReloadVars( firstLoad )
  109.     --- LOAD THE ALL IMPORTANT VARIABLES ----------------------------------------------
  110.     APA.Settings.AntiPK = GetConVar("apa_antipk"):GetInt()
  111.     APA.Settings.DamageReturn = GetConVar("apa_antipk_punish"):GetInt()
  112.     APA.Settings.VehiclesDontHurt = GetConVar("apa_vehiclesdonthurt"):GetInt()
  113.     APA.Settings.BlockExplosions = GetConVar("apa_blockexplosions"):GetInt()
  114.     APA.Settings.NoCollideVehicles = GetConVar("apa_nocollidevehicles"):GetInt()
  115.     APA.Settings.AntiPush = GetConVar("apa_antipush"):GetInt()
  116.     APA.Settings.APCollision = GetConVar("apa_apcollision"):GetInt()
  117.     APA.Settings.GhostOnSpawn = GetConVar("apa_ghostonspawn"):GetInt()
  118.     APA.Settings.Nerf = GetConVar("apa_nerf"):GetInt()
  119.     APA.Settings.FPP.AutoBlock = GetConVar("apa_fpp_autoblock"):GetInt()
  120.     APA.Settings.FPP.ABSize = GetConVar("apa_fpp_absize"):GetInt()
  121.     APA.Settings.FPP.Sounds = GetConVar("apa_fpp_sounds"):GetInt()
  122.     APA.Settings.Blacklist = GetConVar("apa_blacklist"):GetInt()
  123.     APA.Settings.Whitelist = GetConVar("apa_whitelist"):GetInt()
  124.     APA.Settings.NoCollideWeapons = GetConVar("apa_nocollideweapons"):GetInt()
  125.     APA.Settings.AutoFreeze = GetConVar("apa_autofreeze"):GetInt()
  126.     APA.Settings.AutoFreezeTime = GetConVar("apa_autofreeze_time"):GetInt()
  127.     --- DONE -------------------------------------------------------------------------
  128.  
  129.     if not firstLoad then
  130.         MsgAll("\n<|||APAnti Has Been Reloaded!|||>\n")
  131.         for _,v in pairs(player.GetAll()) do v:ChatPrint("\n<|||APAnti Has Been Reloaded!|||>\n") end
  132.     end
  133. end
  134.  
  135. hook.Add("Initialize", "_APALoadVariables", function() APAReloadVars( true ) end)
  136.  
  137. local function APAntiLoad()
  138.  
  139.     APAReloadVars( true )
  140.  
  141.     if not (CPPI and CPPI.GetVersion()) then MsgC( Color( 255, 0, 0 ), "ERROR: CPPI not found, Prop protection not installed?") return end
  142.     -- This only works if we have CPPI, sorry.
  143.  
  144.     function APA.FindOwner( ent )
  145.         local owner = owner or nil
  146.         if (ent:CPPIGetOwner()) then local cppi,_ = ent:CPPIGetOwner() end
  147.         owner = cppi or ent.FPPOwner or ent.Owner
  148.         return owner
  149.     end
  150.  
  151.     function APA.FindKiller( atker, inflictor )
  152.         if( atker and !atker:IsPlayer() ) then --I dont know...
  153.             atker = atker.Owner
  154.         end
  155.         ---I completly derped on the line above feel free to check if it acctually does any thing.---
  156.         if( atker and !atker:IsPlayer() ) then --If its not the attacker then its the inflictor right?
  157.             atker = inflictor
  158.         end
  159.         ---The Above Should Not Cause Any Problems---
  160.         if( atker and !atker:IsPlayer() and IsValid(inflictor) ) then --This is what we need...
  161.             atker = APA.FindOwner( inflictor )
  162.         end
  163.         ---The Above Is The Real Function That We Need---                                                                               --Yes I know, I'm paranoid.
  164.         return atker
  165.     end
  166.  
  167.     function APA.EntityCheck( entClass )
  168.         local badEntity, goodEntity = false, false
  169.  
  170.         if( APA.Settings.Blacklist >= 1 ) then
  171.             for _,v in pairs(ClassBlacklist) do
  172.                 if( string.find( string.lower(entClass), string.lower(v) ) ) then
  173.                     badEntity = true
  174.                 end
  175.             end
  176.         end
  177.  
  178.         if( APA.Settings.Whitelist >= 1 ) then
  179.             for _,v in pairs(ClassWhitelist) do
  180.                 if( string.find( string.lower(entClass), string.lower(v) ) ) then
  181.                     goodEntity = true
  182.                 end
  183.             end
  184.         end
  185.  
  186.         return badEntity, goodEntity
  187.     end
  188.  
  189.     function APA.antiPk( target, dmginfo )
  190.         if( APA.Settings.AntiPK >= 1 ) then
  191.             local entClass = dmginfo:GetInflictor():GetClass()
  192.             local badEntity, goodEntity = APA.EntityCheck( entClass )
  193.  
  194.             print(" | Bad, Good: " .. tostring(badEntity) .. ", " .. tostring(goodEntity) .. " | ") -- Debugging
  195.  
  196.             local atker, inflictor, dmg, odmg = dmginfo:GetAttacker(), dmginfo:GetInflictor(), dmginfo:GetDamage()
  197.             print(" 1. | Damage: " .. tostring(dmg) .. " Attacker: " .. tostring(atker) .. " | ") -- Debugging.
  198.  
  199.             if APA.Settings.VehiclesDontHurt >= 1 and not badEntity then
  200.                 if atker:IsVehicle() or inflictor:IsVehicle() then -- Is a vehicle doing this?
  201.                     dmginfo:SetDamage(0)    dmginfo:ScaleDamage( 0 )
  202.                     dmg = 0 -- Set the damage variable to 0 just incase.
  203.                 end
  204.             end
  205.             print(" 2. | Damage: " .. tostring(dmg) .. " Attacker: " .. tostring(atker) .. " | ") -- Debugging.
  206.  
  207.             if APA.Settings.BlockExplosions == 2 and not badEntity then -- Stop damage from explosives.
  208.                 if dmginfo:IsExplosionDamage() then -- Is this explosion damage?
  209.                     dmginfo:SetDamage(0)    dmginfo:ScaleDamage( 0 )
  210.                 end
  211.             end
  212.             print(" 3. | Damage: " .. tostring(dmg) .. " Attacker: " .. tostring(atker) .. " | ") -- Debugging.
  213.  
  214.             if ( dmginfo:GetDamageType() == DMG_CRUSH or badEntity ) and !goodEntity then
  215.  
  216.                 atker, inflictor, dmg = dmginfo:GetAttacker(), dmginfo:GetInflictor(), dmginfo:GetDamage()
  217.                 -- Reconfirm...
  218.  
  219.                 print("DEBUG: A: ",atker," I: ",inflictor," D: ",dmg) -- Debugging.
  220.                 dmginfo:SetDamage(0)    dmginfo:ScaleDamage( 0 )
  221.  
  222.                 print(" 4. | Damage: " .. tostring(dmg) .. " Attacker: " .. tostring(atker) .. " | ") -- Debugging.
  223.  
  224.                 atker = APA.FindKiller( atker, inflictor )
  225.                 if( atker and IsValid(atker) and atker:IsPlayer() and target and IsValid(target) and target:IsPlayer() ) then
  226.                     if(atker != target) then
  227.                         if( !atker.APAWarned ) then
  228.                             MsgAll( atker:GetName() .. "[" .. atker:SteamID() .. "]" .. " hit " .. target:GetName() .. "[" .. target:SteamID() .. "]" .. " with a prop!\n" )
  229.                             atker.APAWarned = true
  230.                             timer.Simple(0.25, function() atker.APAWarned = false end) --Removing console spam.
  231.                         end
  232.                         if APA.Settings.DamageReturn >= 1 then
  233.                             print(" 5. | Damage: " .. tostring(dmg) .. " Attacker: " .. tostring(atker) .. " | ") -- Debugging.
  234.                             print("MUCH WOW: " .. tostring(atker) .. " | Hurting with " .. tostring(odmg) .. " damage.") -- Debugging
  235.                             atker:TakeDamage( odmg, atker, atker ) --I hope the return to sender works now.
  236.                         end
  237.                     end
  238.                 end
  239.             end
  240.         end
  241.     end
  242.     hook.Add( "EntityTakeDamage", "APAntiPk", APA.antiPk )
  243.  
  244.     ---Block-Explosions---
  245.  
  246.     hook.Add( "PlayerSpawnedProp", "APAntiExplode", function( _, _, prop )
  247.         if( prop and IsValid(prop) and APA.Settings.BlockExplosions >= 1 ) then
  248.             prop:SetKeyValue("ExplodeDamage", "0")
  249.             prop:SetKeyValue("ExplodeRadius", "0")
  250.         end
  251.     end)
  252.  
  253.     ---Ghosting-Stuff---
  254.  
  255.     function APA.Ghost.Force( ent )
  256.     -- Used for ghosting a prop when it spawns in theory we could have FPPs anti-spam take care of this but this lets people build without their console getting spammed with "your prop has been ghosted".
  257.         if( ent:IsValid() and !ent:IsPlayer() and !ent:IsWorld() ) then
  258.             ent.APGhost = true
  259.             ent.OldCollisionGroup = ent:GetCollisionGroup()
  260.             ent:SetRenderMode(RENDERMODE_TRANSALPHA)
  261.             ent:DrawShadow(false)
  262.             ent.OldColor = ent.OldColor or ent:GetColor()
  263.             ent:SetColor(Color(255, 255, 255, ent.OldColor.a - 70))
  264.  
  265.  
  266.             if( APA.Settings.APCollision >= 1 ) then
  267.                 ent:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  268.                 ent.CollisionGroup = COLLISION_GROUP_WEAPON
  269.             else
  270.                 ent:SetCollisionGroup(COLLISION_GROUP_WORLD)
  271.                 ent.CollisionGroup = COLLISION_GROUP_WORLD
  272.             end
  273.  
  274.             ent.APNoColided = true
  275.  
  276.             local PhysObj = ent:GetPhysicsObject()
  277.             if( PhysObj ) then PhysObj:EnableMotion(false) end
  278.         end
  279.     end
  280.  
  281.     function APA.Ghost.On( picker, ent, spoof )
  282.         if( ent:IsValid() and !ent:IsPlayer() and !ent:IsWorld() ) then
  283.             if( spoof or (picker and picker:IsValid() and picker:IsPlayer()) ) then
  284.                 if( spoof or ( ent:CPPICanPhysgun( picker ) and not ent:IsPlayer() ) ) then
  285. --                  |_ Used for the anti-trap makes it so the prop is ghosted. |_ Admins and SuperAdmins can pick up other peoples props so...
  286.                     ent.APGhost = true
  287.                     ent.OldCollisionGroup = ent:GetCollisionGroup()
  288.                     ent:SetRenderMode(RENDERMODE_TRANSALPHA)
  289.                     ent:DrawShadow(false)
  290.                     ent.OldColor = ent.OldColor or ent:GetColor()
  291.                     ent:SetColor(Color(255, 255, 255, ent.OldColor.a - 70)) -- Make the prop slightly faded to show that its ghosted.
  292.  
  293.                     if( APA.Settings.APCollision >= 1 ) then
  294.                         ent:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  295.                         ent.CollisionGroup = COLLISION_GROUP_WEAPON
  296.                     else
  297.                         ent:SetCollisionGroup(COLLISION_GROUP_WORLD)
  298.                         ent.CollisionGroup = COLLISION_GROUP_WORLD
  299.                     end
  300.  
  301.                     ent.APNoColided = true
  302.                 end
  303.             end
  304.         end
  305.     end
  306.  
  307.     function APA.Ghost.CanOff( ent )
  308.         local mins, maxs = ent:LocalToWorld(ent:OBBMins( )), ent:LocalToWorld(ent:OBBMaxs( ))
  309.         local cube = ents.FindInBox( mins, maxs )
  310.         local owner = APA.FindOwner( ent )
  311.         for _,v in pairs(cube) do
  312.             local PhysObj = v:GetPhysicsObject()
  313.             if( ( IsValid(v) and v:GetModel() and v != ent ) and ( PhysObj and PhysObj:IsValid() and PhysObj:IsMotionEnabled() ) and ( IsValid(APA.FindOwner( v )) ) or v:IsPlayer() or v:IsNPC() ) then
  314.                 if not ent.APAIsObscured then
  315.                     owner:SendLua([[notification.AddLegacy( "Prop Obscured!", NOTIFY_ERROR, 2 )]])
  316.                     ent.APAIsObscured = true
  317.                 end
  318.                 return false
  319.             end
  320.         end
  321.         ent.APAIsObscured = nil
  322.         return true
  323.     end
  324.  
  325.     function APA.Ghost.Off( picker, ent, spoof )
  326.         if( APA.Ghost.CanOff( ent ) ) then
  327.             if( ent.APGhost and (ent:IsValid() and !ent:IsPlayer() and !ent:IsWorld()) ) then
  328.                 if( spoof or (picker and picker:IsValid() and picker:IsPlayer()) ) then
  329.                     if( spoof or ( ent:CPPICanPhysgun( picker ) and not ent:IsPlayer() ) ) then
  330.                         ent.APGhost = nil
  331.                         ent:DrawShadow(true)
  332.  
  333.                         if ent.OldColor then ent:SetColor(Color(ent.OldColor.r, ent.OldColor.g, ent.OldColor.b, ent.OldColor.a)) end
  334.                         ent.OldColor = nil
  335.  
  336.                         ent:SetCollisionGroup(COLLISION_GROUP_NONE)
  337.                         ent.CollisionGroup = COLLISION_GROUP_NONE
  338.                         ent.APNoColided = false
  339.                     end
  340.                 end
  341.             end
  342.         end
  343.     end
  344.  
  345.     --ANTI-TRAP--
  346.     hook.Remove("think", "APAntiPropPush-EntityScanner")
  347.     timer.Create( "APAntiPropPush-EntityScanner", 1.3, 0, function()
  348.         for _,ent in pairs(ents.GetAll()) do
  349.             if (ent:IsWeapon() or ent:GetClass() == "spawned_weapon") and APA.Settings.NoCollideWeapons >= 1 then
  350.                 ent:SetCollisionGroup(COLLISION_GROUP_WORLD)
  351.                 ent.CollisionGroup = COLLISION_GROUP_WORLD
  352.             end
  353.             --------------
  354.             if ent:IsVehicle() then
  355.                 if APA.Settings.NoCollideVehicles >= 1 and not ent.APNoColided then
  356.                     ent:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  357.                     ent.CollisionGroup = COLLISION_GROUP_WEAPON
  358.                     ent:SetCustomCollisionCheck( true )
  359.                     ent.APNoColided = true
  360.                 end
  361.             else    --------------------
  362.                 if ent.APGhostOff or APA.Settings.AntiPush >= 1 then
  363.                     if ent.APGhostOff then
  364.                         local MotionEnabled, PhysObj = false, ent:GetPhysicsObject(); if( IsValid(PhysObj) ) then MotionEnabled = PhysObj:IsMotionEnabled() end
  365.                         if APA.Settings.AntiPush >= 1 then
  366.                             if (ent:GetVelocity():Distance( Vector( 0.1, 0.1, 0.1 ) ) > 0.2 and MotionEnabled) then
  367.                                 APA.Ghost.On( nil, ent, true )
  368.                             end
  369.                         end
  370.                         if ( ( ent:GetVelocity():Distance( Vector( 0.1, 0.1, 0.1 ) ) <= 0.2 or !MotionEnabled ) and ent.APGhost ~= nil ) then
  371.                             if APA.Ghost.CanOff( ent ) then
  372.                                 APA.Ghost.Off( nil, ent, true )
  373.                             end
  374.                         end
  375.                     end
  376.                 end
  377.             end
  378.         end
  379.     end)
  380.    
  381.     if APA.Settings.AutoFreeze >= 1 then -- The only command that needs map restart.
  382.         if APA.Settings.AutoFreezeTime < 60 then APA.Settings.AutoFreezeTime = 300 end
  383.         timer.Create( "APAntiAutoFreezeTimer", APA.Settings.AutoFreezeTime, 0, function()
  384.             if PA.Settings.AutoFreeze >= 1 then
  385.                 for _,ent in pairs(ents.FindByClass("prop_physics")) do
  386.                     if ent and IsValid(ent) then
  387.                         local phys = ent:GetPhysicsObject()
  388.                         if phys:IsValid() then
  389.                             phys:EnableMotion(false)
  390.                         end
  391.                     end
  392.                 end
  393.             end
  394.         end)
  395.     end
  396.  
  397.     --Check Vehicle Spawn--
  398.     hook.Add("PlayerSpawnedVehicle", "APA.VehicleSpawnCheck", function(ent)
  399.         if APA.Settings.NoCollideVehicles >= 1 then
  400.             ent:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  401.             ent.CollisionGroup = COLLISION_GROUP_WEAPON
  402.             ent.APNoColided = true
  403.         end
  404.     end)
  405.  
  406.     --Property-Setting-Fix--
  407.     hook.Add("CanProperty", "APA.CanPropertyFix", function( _, property, ent )
  408.         if( tostring(property) == "collision" and ent.APNoColided ) then return false end
  409.     end)
  410.  
  411.     ---Physgun-Stuff---
  412.  
  413.     --PHYSGUN-DROP--
  414.  
  415.     hook.Add( "PhysgunDrop", "APAntiPropPush-Drop", function( picker, ent ) -- We always want to unghost props if they are ghosted.
  416.         if( ( !ent:IsPlayer() and !ent:IsNPC() and !ent:IsVehicle() ) and picker != ent ) then
  417.             if APA.Ghost.CanOff( ent ) and not ( APA.Settings.AntiPush >= 1 ) then APA.Ghost.Off( picker, ent, true ) end -- Unghost props a little faster.
  418.             ent.APGhostOff = true
  419.         end
  420.     end)
  421.  
  422.     --PHYSGUN-PICKUP--
  423.     hook.Add( "PhysgunPickup", "APAntiPropPush-Pickup", function( picker, ent )
  424.         if( APA.Settings.AntiPush >= 1 ) then
  425.             if( ( !ent:IsPlayer() and !ent:IsNPC() and !ent:IsVehicle() ) and picker != ent ) then
  426.                 APA.Ghost.On( picker, ent, true )
  427.                 ent.APGhostOff = false
  428.             end
  429.         end
  430.     end)
  431.  
  432.     --PHYSGUN-THROW-NERF--
  433.     hook.Add( "PhysgunDrop", "APAntiPropPush-Nerf", function( _, ent )
  434.         if APA.Settings.Nerf >= 1 then
  435.             if( ent and (ent:IsValid() and !ent:IsPlayer() and !ent:IsWorld()) and ent:GetPhysicsObject() ) then
  436.                 ent:SetVelocity(Vector(0,0,0))
  437.                 ent:SetAbsVelocity(Vector(0,0,0))
  438.                 ---------
  439.                 local phys = ent:GetPhysicsObject()
  440.                 if( phys and IsValid(phys) ) then
  441.                     phys:AddAngleVelocity( phys:GetAngleVelocity() * -1 )
  442.                     phys:SetVelocityInstantaneous( Vector(0,0,0) )
  443.                 end
  444.             end
  445.         end
  446.     end)
  447.  
  448.  
  449.     --Ghost Props On Spawn:
  450.     hook.Add("PlayerSpawnedProp", "_APA.AntiSpam.PropSafeSpawn", function(_, _, ent)
  451.         if IsValid(ent) and APA.Settings.GhostOnSpawn >= 1 then
  452.             local phys = ent:GetPhysicsObject()
  453.             if phys:IsValid() then
  454.                 APA.Ghost.Force( ent )
  455.                 ent.APGhostOff = false
  456.             end
  457.         end
  458.     end)
  459.  
  460.     ---I dont like huge props | Default big props math.pow(10, 5.85) or 707945.784384 & math.pow(3.23, 5.85) or 952.433704327---
  461.     hook.Add("PlayerSpawnedProp", "APA.Settings.FPP.AutoBlock", function(ply,mdl,ent)
  462.         if APA.Settings.FPP.AutoBlock then
  463.             if ( ent:GetPhysicsObject() and ent:GetPhysicsObject():GetVolume() ) then
  464.                 local mins, maxs = ent:LocalToWorld(ent:OBBMins( )), ent:LocalToWorld(ent:OBBMaxs( ))
  465.                 if ( ent:GetPhysicsObject():GetVolume() > math.pow(10,APA.Settings.FPP.ABSize) ) or ( mins:Distance(maxs) > math.pow(3.23,APA.Settings.FPP.ABSize) ) then
  466.                     if( mdl and ( type(FPP) == "table" ) ) then --This will only work if you have Falco's Prop Protection!
  467.                         mdl = string.Replace(string.Replace(string.Replace( mdl, "\\", "/" ), "\"", ""), ";", "") --Just in case.
  468.                         RunConsoleCommand( "FPP_AddBlockedModel", mdl )
  469.                     end
  470.                     if( ply:IsValid() ) then
  471.                         ply:ChatPrint("That prop is now blocked, thanks!")
  472.                         ply:SendLua([[notification.AddLegacy( "That prop is now blocked, thanks!", NOTIFY_ERROR, 10 )]])
  473.                         if APA.Settings.FPP.Sounds >= 1 then ply:SendLua([[surface.PlaySound("ambient/alarms/klaxon1.wav")]]) end
  474.                     end
  475.                     if( ent:IsValid() ) then ent:Remove() end
  476.                 end
  477.             end
  478.         end
  479.     end)
  480.  
  481.     ---Now lets fix a long forgotten exploit...
  482.     function APA.ModelBypassFix( ply, model )
  483.         model = string.lower(model or "")
  484.         model = string.Replace(model, "\\", "/")
  485.         model = string.gsub(model, "[\\/]+", "/")
  486.        
  487.         if string.find(model, "../", 1, true) then
  488.             ply:SendLua([[notification.AddLegacy( "The model path goes up in the folder tree.", NOTIFY_ERROR, 10 )]])
  489.             ply:SendLua([[surface.PlaySound("ambient/alarms/klaxon1.wav")]])
  490.             return true
  491.         end
  492.  
  493.         return false
  494.     end
  495.  
  496.     hook.Add("PlayerSpawnObject", "APAModelBypassFix", function(ply, model)
  497.         if APA.ModelBypassFix( ply, model ) then
  498.             return false
  499.         end
  500.     end)
  501.     ---------------
  502.     hook.Add("PlayerSpawnProp", "APAModelBypassFix_", function(ply, model)
  503.         if APA.ModelBypassFix( ply, model ) then
  504.             return false
  505.         end
  506.     end)
  507.  
  508.     hook.Add("PlayerInitialSpawn", function( ply ) timer.Simple(3.5, function() ply:ChatPrint("This server is running APAnti by LuaTenshi.") end) end)
  509.     -- Is it bad if I want to let people know that the server is running my addon?
  510.  
  511.     MsgAll("\n<|||APAnti Is Now Running!|||>\n")
  512.     hook.Remove("PlayerConnect", "APAnti-Execution-Hook")
  513. end
  514.  
  515. hook.Add("PlayerConnect", "APAnti-Execution-Hook", function() MsgAll("\n<|||APAnti Is Loading...|||>\n") timer.Simple( 0.5, function() APAntiLoad() end ) end)
  516. concommand.Add("apa_reload", function() APAReloadVars( false ) end, nil, nil, {FCVAR_DEMO, FCVAR_GAMEDLL, FCVAR_SERVER_CAN_EXECUTE})
Advertisement
Add Comment
Please, Sign In to add comment