Advertisement
FocusedWolf

SentryLimit - With giant comments

Sep 1st, 2011
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. Script.Load("../ns2/lua/NS2Utility.lua") //1. Allow me to show you how not to copy a bazillion lines of irrelevant NS2Utility.lua code that will likely change with every version.
  2.  
  3. //2. SourceGear DiffMerge is a wonderful program. Saw you had some modded strings in GetCrosshairText and GetSelectionText. Thought you should know if it was unintentional. I tossed em from this file to keep it simple.
  4.  
  5. //3. These could be local.
  6. local kSentryBuildRadius = 21 //WARNING: don't set to large because it will limit sentry building on the other sides of walls.
  7. local kMaxSentryInArea = 4
  8.  
  9. //4. Part of a neat trick for overloading CheckBuildEntityRequirements
  10. local base_CheckBuildEntityRequirements
  11. if not base_CheckBuildEntityRequirements then
  12.     base_CheckBuildEntityRequirements = CheckBuildEntityRequirements //if statement is necessary so when someone saves/hotloads changes to this file that base_CheckBuildEntityRequirements doesn't grow.
  13. end
  14.  
  15. //5. No need to recreate these strings every time that CheckBuildEntityRequirements is called
  16. local sentryClassName = "Sentry"
  17. local sentryErrorMessage = "Warning: Too many Sentries!"
  18.  
  19. //6. Added some "ugly" (not IMO) local variables optimizations for table.count and GetEntitiesWithinRange
  20. local _GetEntitiesWithinRange = GetEntitiesWithinRange
  21. local _Count = table.count
  22.  
  23. function CheckBuildEntityRequirements(techId, position, player, ignoreEntity)
  24.  
  25.     //7. Merged nested if statements. Don't worry the code won't run unless kTechId.Sentry == techId
  26.    
  27.     //8. Unnecessary/Unoptimal to use GetEntitiesForTeamWithinRange instead of GetEntitiesWithinRange.
  28.     //   Check in decoda the implementation of GetEntitiesWithinRange and GetEntitiesForTeamWithinRange to see what i mean.
  29.     //   Besides, aliens can't drop sentries, and if they could, i'd think you'd want this restriction to still apply.
  30.    
  31.     // Check if the entity is a Sentry
  32.     if kTechId.Sentry == techId and _Count(_GetEntitiesWithinRange(sentryClassName, position, kSentryBuildRadius)) >= kMaxSentryInArea then
  33.         //legalBuild, errorString
  34.         return false, sentryErrorMessage
  35.     end
  36.    
  37.     //call the dev's base code that was in CheckBuildEntityRequirements
  38.     return base_CheckBuildEntityRequirements(techId, position, player, ignoreEntity)
  39.  
  40. end
  41.  
  42. //Comment regarding #7
  43. // if you don't believe me then try this code at: http://www.lua.org/cgi-bin/demo
  44. /*
  45. testValue = false --try = true after you see the result with false
  46.  
  47. i = 1
  48. function Test()
  49.     i = i + 1
  50.     return true
  51. end
  52.  
  53. if testValue and Test() then
  54. end
  55.  
  56. print(i)
  57. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement