Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////
- // Counter_System.nut
- //
- // Version:
- // 1.0
- //
- // Modified:
- // August 30, 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
- // Left 4 Dead 2, and Aliens Swarm: Infestation
- ///////////////////////////////////////////////////////////////////////////
- // Initialize the Counter Sytem
- function InitCounterSystem()
- {
- functions.toConsole("Initializing Counter System...");
- // Initialize Globals
- ::operation <- 0; // Operation to perform(0 - Add | 1 - Subtract | 2 - Multiply | 3 - Divide)
- ::value <- 0; // Value to perform operation on
- ::item <- 0; // Item ID#
- ::playersInGame <- 0; // Players in the game
- // Initialize Classes
- ::functions <- Functions(); // Functions handler
- ::display <- Display(); // Display handler
- ::shop <- Shop(); // Shop handler
- // Initialize Arrays
- ::counter <- []; // Create the counter object array
- counter.append(0); // and an empty key
- ::players <- []; // Create the players array
- ::characters<- [ // Create the characters array
- "sarge",
- "wildcat",
- "faith",
- "crash",
- "jaeger",
- "wolfe",
- "bastille",
- "vegas"
- ];
- // User Defined Variables ////////////////
- ::developer <- 1; // (0 - Disable | 1 - Enable) debugging
- ::digitPrefix <- "digit"; // Prefix of display digits
- ::counterPrefix <- "team"; // Prefix of counter index
- ::spawnPrefix <- "dispenser_spawn"; // Prefix of env_entitiy_maker
- ::soundPrefix <- "dispenser_deny"; // Prefix of ambient_generic
- ::templatePrefix<- "template_item"; // Prefix of point_template
- //////////////////////////////////////////
- functions.toConsole("User Variables Initialized!");
- functions.toConsole("Initializing Counter Objects...");
- // Initialize counter objects
- // ADD COUNTERS HERE
- counter.append(Counter(1, 0, 0, 999, 1)); // Creates counter[1], id = 1, default = 0, minimum = 0, maximum = 999, multiplier = 1
- counter.append(Counter(2, 0, 0, 999, 1)); // Create counter[2], id = 1, default = 0, minimum = 0, maximum = 999, multiplier = 1
- functions.toConsole("Counter Objects Initialized!");
- functions.toConsole("Counter System Initialized!");
- }
- /////////////////
- // CLASS: Counter
- class Counter
- {
- counterId = 0;
- defaultValue = 0;
- minimumValue = 0;
- maximumValue = 0;
- currentValue = 0;
- multiplierValue = 1;
- digits = 0;
- constructor(counter_id, counter_def, counter_min, counter_max, counter_multi)
- {
- functions.toConsole("Creating Counter Object...");
- //
- counterId = counter_id;
- defaultValue = counter_def;
- minimumValue = counter_min;
- maximumValue = counter_max;
- currentValue = defaultValue;
- multiplierValue = counter_multi;
- digits = maximumValue.tostring().len();
- // Output counter to console
- functions.toConsole("counterId = " + counterId);
- functions.toConsole("Counter[" + counterId + "] defaultValue = " + defaultValue);
- functions.toConsole("Counter[" + counterId + "] minimumValue = " + minimumValue);
- functions.toConsole("Counter[" + counterId + "] maximumValue = " + maximumValue);
- functions.toConsole("Counter[" + counterId + "] currentValue = " + currentValue);
- functions.toConsole("Counter[" + counterId + "] multiplierValue = " + multiplierValue);
- functions.toConsole("Counter[" + counterId + "] digits = " + digits);
- //
- functions.toConsole("Counter Object Created!");
- }
- // Perform operation on counter
- function DoOperation()
- {
- local v = currentValue;
- // Determine operation to perform
- switch(operation)
- {
- case 0: // Add
- currentValue = Clamp(v + (value * multiplierValue));
- functions.toConsole("Counter[" + counterId + "] " + v + "(+" + value + ") = " + currentValue);
- break;
- case 1: // Subtract
- currentValue = Clamp(currentValue - (value * multiplierValue));
- functions.toConsole("Counter[" + counterId + "] " + v + "(-" + value + ") = " + currentValue);
- break;
- case 2: // Multiply
- currentValue = Clamp(currentValue * (value * multiplierValue));
- functions.toConsole("Counter[" + counterId + "] " + v + "(*" + value + ") = " + currentValue);
- break;
- case 3: // Divide
- currentValue = Clamp(currentValue / (value * multiplierValue));
- functions.toConsole("Counter[" + counterId + "] " + v + "(/" + value + ") = " + currentValue);
- break;
- }
- // Update display
- display.SetDisplay(counterId);
- }
- // Sets the counter to v
- function SetCounter(v)
- {
- currentValue = v;
- functions.toConsole("Counter[" + counterId + "] Value: " + v);
- // Update display
- display.SetDisplay(counterId);
- }
- // Reset the counter to the default value
- function Reset()
- {
- currentValue = defaultValue;
- functions.toConsole("Counter[" + counterId + "] Value: " + defaultValue);
- // Update display
- display.SetDisplay(counterId);
- }
- // Sets the counter's multiplier value
- function SetMultiplier(v)
- {
- multiplierValue = v;
- functions.toConsole("Counter[" + counterId + "] Multiplier: " + v);
- }
- // Constrain counter on operation
- function Clamp (v)
- {
- if(v < minimumValue)
- {
- functions.toConsole("Counter[" + counterId + "] Value below legal limit, set to minimum value: " + minimumValue);
- return minimumValue;
- }
- else if(v > maximumValue)
- {
- functions.toConsole("Counter[" + counterId + "] Value above legal limit, set to maximum value: " + maximumValue);
- return maximumValue;
- }
- else
- {
- functions.toConsole("Counter[" + counterId + "] No clamping has been performed on value: " + v);
- return v;
- }
- }
- }
- /////////////////
- // CLASS: Display
- class Display
- {
- constructor()
- {
- // Initialize Display class
- }
- // Set the LCD display for counter id
- function SetDisplay(id)
- {
- local placeValue = 0;
- local v = counter[id].currentValue;
- // For each digit
- for (local place = 1; place <= counter[id].digits; p++)
- {
- // Determine placeValue of digit place
- placeValue = v % 10;
- v = (v - placeValue) / 10;
- functions.toConsole("Place: " + place + " :: Value: " + placeValue);
- // Enable/Disable brushes to display placeValue on digit place
- switch (placeValue)
- {
- case 0:
- SetBrushState(id, place, [1, 2, 3, 4, 5, 6]);
- break;
- case 1:
- SetBrushState(id, place, [2, 3]);
- break;
- case 2:
- SetBrushState(id, place, [1, 2, 4, 5, 7]);
- break;
- case 3:
- SetBrushState(id, place, [1, 2, 3, 4, 7]);
- break;;
- case 4:
- SetBrushState(id, place, [2, 3, 6, 7]);
- break;
- case 5:
- SetBrushState(id, place, [1, 3, 4, 6, 7]);
- break;
- case 6:
- SetBrushState(id, place, [1, 3, 4, 5, 6, 7]);
- break;
- case 7:
- SetBrushState(id, place, [1, 2, 3]);
- break;
- case 8:
- SetBrushState(id, place, [1, 2, 3, 4, 5, 6, 7]);
- break;
- case 9:
- SetBrushState(id, place, [1, 2, 3, 4, 6, 7]);
- break;
- }
- }
- }
- // Enables or disables the brushes to display digit place
- function SetBrushState(id, place, brushes)
- {
- for (local b = 1; b <= 7; b++)
- {
- local enable = 0;
- local brush = digitPrefix + "_" + place + "_" + b + "_" + counterPrefix + id;
- // Is b in the array?
- foreach (key, val in brushes)
- {
- if (b == val)
- enable = 1;
- }
- if (enable)
- EntFire(brush, "Enable"); // Yes, enable brush b
- else
- EntFire(brush, "Disable");// No, disable brush b
- }
- }
- }
- //////////////
- // CLASS: Shop
- class Shop
- {
- // Compares counter[id]'s value to the price of the item
- function CheckFunds(id)
- {
- if (counter[id].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(id)
- {
- if (CheckFunds(id))
- { // Deduct funds & Spawn item
- counter[id].DoOperation();
- EntFire(spawnPrefix + id, "AddOutput", "EntityTemplate " + templatePrefix + item);
- EntFire(spawnPrefix + id, "ForceSpawn", 0);
- functions.toConsole("Item: " + templatePrefix + item + ":: Spawn Location: " + spawnPrefix + id);
- }
- else
- { // Denied Sound
- EntFire(soundPrefix + id, "PlaySound", 0);
- functions.toConsole("Insufficient funds for Item: " + templatePrefix + 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;
- toConsole("Operation: " + o);
- }
- // Sets the value to used against the counter
- function SetValue(v)
- {
- value = v;
- toConsole("Value: " + v);
- }
- // Gets players currently ingame
- function GetPlayers()
- {
- local character;
- foreach(i, n in characters)
- {
- character = Entities.FindByName(null, "#asw_name_" + n)
- if (character)
- {
- toConsole("player" + i + " = " + character);
- players.append(n = character);
- }
- }
- playersInGame = players.len();
- }
- // Display's player count in a hint
- function PlayerCount()
- {
- EntFire("hint_players", "AddOutput", "hint_caption " + playersInGame + " player(s) are currently in the game.");
- EntFire("hint_players", "ShowHint", 0);
- }
- }
- // End of Counter System
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement