Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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. 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.
- //3. These could be local.
- local kSentryBuildRadius = 21 //WARNING: don't set to large because it will limit sentry building on the other sides of walls.
- local kMaxSentryInArea = 4
- //4. Part of a neat trick for overloading CheckBuildEntityRequirements
- local base_CheckBuildEntityRequirements
- if not base_CheckBuildEntityRequirements then
- base_CheckBuildEntityRequirements = CheckBuildEntityRequirements //if statement is necessary so when someone saves/hotloads changes to this file that base_CheckBuildEntityRequirements doesn't grow.
- end
- //5. No need to recreate these strings every time that CheckBuildEntityRequirements is called
- local sentryClassName = "Sentry"
- local sentryErrorMessage = "Warning: Too many Sentries!"
- //6. Added some "ugly" (not IMO) local variables optimizations for table.count and GetEntitiesWithinRange
- local _GetEntitiesWithinRange = GetEntitiesWithinRange
- local _Count = table.count
- function CheckBuildEntityRequirements(techId, position, player, ignoreEntity)
- //7. Merged nested if statements. Don't worry the code won't run unless kTechId.Sentry == techId
- //8. Unnecessary/Unoptimal to use GetEntitiesForTeamWithinRange instead of GetEntitiesWithinRange.
- // Check in decoda the implementation of GetEntitiesWithinRange and GetEntitiesForTeamWithinRange to see what i mean.
- // Besides, aliens can't drop sentries, and if they could, i'd think you'd want this restriction to still apply.
- // Check if the entity is a Sentry
- if kTechId.Sentry == techId and _Count(_GetEntitiesWithinRange(sentryClassName, position, kSentryBuildRadius)) >= kMaxSentryInArea then
- //legalBuild, errorString
- return false, sentryErrorMessage
- end
- //call the dev's base code that was in CheckBuildEntityRequirements
- return base_CheckBuildEntityRequirements(techId, position, player, ignoreEntity)
- end
- //Comment regarding #7
- // if you don't believe me then try this code at: http://www.lua.org/cgi-bin/demo
- /*
- testValue = false --try = true after you see the result with false
- i = 1
- function Test()
- i = i + 1
- return true
- end
- if testValue and Test() then
- end
- print(i)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement