Advertisement
FocusedWolf

SentryLimit v2

Sep 1st, 2011
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. Script.Load("../ns2/lua/NS2Utility.lua")
  2.  
  3. local kSentryBuildRadius = 21 //WARNING: don't set to large because it will limit sentry building in adjacent rooms.
  4. local kMaxSentryInArea = 4
  5.  
  6. local _GetEntitiesWithClassname = Shared.GetEntitiesWithClassname
  7.  
  8. //Noticed their wasn't a GetEntitiesWithinXZRange so i made one by stripping the team check from GetEntitiesForTeamWithinXZRange
  9. local function GetEntitiesWithinXZRange(className, origin, range)
  10.  
  11.     local rangeSquared = range * range
  12.  
  13.     local function inRangeXZFilterFunction(entity)
  14.         local inRange = (entity:GetOrigin() - origin):GetLengthSquaredXZ() <= rangeSquared
  15.         return inRange
  16.     end
  17.     return GetEntitiesWithFilter(_GetEntitiesWithClassname(className), inRangeXZFilterFunction)
  18.  
  19. end
  20.  
  21. local base_CheckBuildEntityRequirements = CheckBuildEntityRequirements
  22.  
  23. local sentryClassName = "Sentry"
  24. local sentryErrorMessage = "Warning: Too many Sentries!"
  25. local _Count = table.count
  26. function CheckBuildEntityRequirements(techId, position, player, ignoreEntity)
  27.  
  28.     // Check if the entity is a Sentry
  29.     if kTechId.Sentry == techId and _Count(GetEntitiesWithinXZRange(sentryClassName, position, kSentryBuildRadius)) >= kMaxSentryInArea then
  30.         return false, sentryErrorMessage //legalBuild, errorString
  31.     end
  32.  
  33.     return base_CheckBuildEntityRequirements(techId, position, player, ignoreEntity)
  34.  
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement