Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////
- // Counter_System.nut
- //
- // Version:
- // 1.0
- //
- // Modified:
- // August 29, 2010
- //
- // Authors:
- // Seung Hahm aka Juicebox360 <logarithmmm@gmail.com>
- // Cris Crawford aka 8e8 <chris.j.crawford@hotmail.com>
- // Jason Spafford aka NullSoldier <nullprogrammer@gmail.com>
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // PURPOSE: This system serves as scoring/monetary handler for any HL2 game
- ///////////////////////////////////////////////////////////////////////////
- // Initialize the Counter Sytem
- function InitCounterSystem()
- {
- // Initialize Classes
- ::functions <- Functions();
- ::display <- Display();
- ::shop <- Shop();
- functions.toConsole("Initializing Counter System...");
- functions.toConsole("Initializing User Variables...");
- // User Defined Variables
- //////////////////////////////////////////////////
- ::value <- 0; // Value to add
- ::operation <- 0; // Operation to perform(0 - Add, 1 - Subtract, 2 - Multiply, 3 - Divide)
- // Display related //
- ::digitName <- "digit"; // Prefix of display digits
- ::counterName <- "team"; // Prefix of counter index
- // Spawn related //
- ::spawnName <- "dispenser_spawn"; // Prefix of env_entitiy_maker
- ::soundName <- "dispenser_deny"; // Prefix of ambient_generic
- ::templateName <- "template_item"; // Prefix of point_template
- // Shop related //
- ::item <- 0; // Item ID#
- // Misc //
- ::developer <- 1; // Enable debugging
- //////////////////////////////////////////////////
- functions.toConsole("User Variables Initialized!");
- functions.toConsole("Initializing Counter Objects...");
- // Initialize counter objects
- // ADD COUNTERS HERE
- ::counter <- [];
- counter.append(0);
- counter.append(Counter(0, 0, 999)); // Create counter[1] with default value of 0, minimum value of 0, and a maximum value of 999
- functions.toConsole("Counter Objects Initialized!");
- functions.toConsole("Counter System Initialized!");
- }
- /////////////////
- // CLASS: Counter
- class Counter
- {
- constructor(counter_def, counter_min, counter_max)
- { // Initialize counter
- functions.toConsole("Creating Counter Object...");
- local defaultValue = counter_def;
- functions.toConsole("defaultValue = " + defaultValue);
- local minimumValue = counter_min;
- functions.toConsole("minimumValue = " + minimumValue);
- local maximumValue = counter_max;
- functions.toConsole("maximumValue = " + maximumValue);
- local currentValue = defaultValue;
- functions.toConsole("currentValue = " + currentValue);
- // Set maximum digits for counter display
- local digits = maximumValue.tostring().len();
- functions.toConsole("digits = " + digits);
- functions.toConsole("Counter Object Created!");
- }
- // Perform operation on counter
- function DoOperation ()
- {
- // Determine operation to perform
- switch(operation)
- {
- case 0: // Add
- currentValue = Clamp(currentValue + value, minimumValue, maximumValue);
- break;
- case 1: // Subtract
- currentValue = Clamp(currentValue - value, minimumValue, maximumValue);
- break;
- case 2: // Multiply
- currentValue = Clamp(currentValue * value, minimumValue, maximumValue);
- break;
- case 3: // Divide
- currentValue = Clamp(currentValue / value, minimumValue, maximumValue);
- break;
- }
- // Update display
- display.SetDisplay(v)
- }
- // Reset the counter to the default value
- function Reset()
- {
- currentValue = defaultValue;
- toConsole("Value: " + defaultValue);
- }
- // Constrain counter on operation
- function Clamp (v)
- {
- if(v < minimumValue)
- {
- toConsole("Value below legal limit, set to minimum value: " + minimumValue);
- return minimumValue;
- }
- else if(v > maximumValue)
- {
- toConsole("Value above legal limit, set to maximum value: " + maximumValue);
- return maximumValue;
- }
- else
- return v;
- }
- }
- /////////////////
- // CLASS: Display
- class Display
- {
- constructor()
- {
- // Initialize Display class
- }
- // Set the LCD display for counter v
- function SetDisplay(v)
- {
- placeValue <- 0;
- localValue <- counter[v].currentValue;
- for (p <- 1; p <= counter[v].digits; p++)
- {
- placeValue = localValue % 10;
- localValue = (localValue - placeValue) / 10;
- toConsole("Place: " + p + " :: Value: " + placeValue);
- switch (placeValue)
- {
- case 0:
- SetBrushState(v, p, [1, 2, 3, 4, 5, 6]);
- break;
- case 1:
- SetBrushState(v, p, [2, 3]);
- break;
- case 2:
- SetBrushState(v, p, [1, 2, 4, 5, 7]);
- break;
- case 3:
- SetBrushState(v, p, [1, 2, 3, 4, 7]);
- break;;
- case 4:
- SetBrushState(v, p, [2, 3, 6, 7]);
- break;
- case 5:
- SetBrushState(v, p, [1, 3, 4, 6, 7]);
- break;
- case 6:
- SetBrushState(v, p, [1, 3, 4, 5, 6, 7]);
- break;
- case 7:
- SetBrushState(v, p, [1, 2, 3]);
- break;
- case 8:
- SetBrushState(v, p, [1, 2, 3, 4, 5, 6, 7]);
- break;
- case 9:
- SetBrushState(v, p, [1, 2, 3, 4, 6, 7]);
- break;
- }
- }
- }
- // Enables or disables the brushes to display digit v
- function SetBrushState(v, place, brushes)
- {
- for (b <- 1; b <= 7; b++)
- {
- enable <- 0;
- brush <- digitName + "_" + place + "_" + b + "_" + counterName + v;
- foreach (key, id in brushes)
- {
- if (b == id)
- enable <- 1;
- }
- if (enable)
- EntFire(brush, "Enable");
- else
- EntFire(brush, "Disable");
- }
- }
- }
- //////////////
- // CLASS: Shop
- class Shop
- {
- // Compares counter[v]'s value to the price of the item
- function CheckFunds(v)
- {
- if (counter[v].currentValue >= value)
- return true; // Sufficient funds
- else
- return false; // Insufficient funds
- }
- // Set's the current shop item's ID and price
- function SetItem(id, price)
- {
- item <- id;
- functions.SetValue(price);
- functions.toConsole("Item: " + id + " :: Price: " + price);
- }
- // Buy's current item
- function Buy(v)
- {
- if (CheckFunds(v))
- { // Deduct funds & Spawn item
- counter[v].doOperation();
- EntFire(spawnName + v, "AddOutput", "EntityTemplate " + templateName + item);
- EntFire(spawnName + v, "ForceSpawn", 0);
- functions.toConsole("Item: " + templateName + item + ":: Spawn Location: " + spawnName + v);
- }
- else
- { // Denied Sound
- EntFire(sound + i, "PlaySound", 0);
- functions.toConsole("Insufficient funds for Item: " + templateName + item);
- }
- }
- }
- ///////////////////
- // CLASS: Functions
- class Functions
- {
- constructor()
- {
- // Initialize Functions class
- }
- // Sends debugging output to console
- function toConsole(output)
- {
- if (developer)
- printl(output);
- }
- // Sets the operation to perform on the counter
- function SetOperation(o)
- {
- operation = o;
- functions.toConsole("Operation: " + o);
- }
- // Sets the value to used against the counter
- function SetValue(v)
- {
- value = v;
- functions.toConsole("Value: " + v);
- }
- }
- // End of Counter System
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement