Advertisement
Guest User

Untitled

a guest
Jan 14th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //#CLIENTSIDE
  2. const resetTime = 2;
  3.  
  4. function onCreated() {
  5.   configKeyOrders();
  6.  
  7.   this.test = "";
  8. }
  9.  
  10. function onKeyPressed(keycode, key) {
  11.   this.test = (this.combosenabled?this.test:"") @ key;
  12.  
  13.   temp.check = ((this.testcheck!=false)
  14.     ? this.testcheck(this.test)
  15.     : this.check(this.test)
  16.   );
  17.  
  18.   if (temp.check.type() == 3) { // check if it's an array
  19.     keyCombo(this.test, temp.check[1], temp.check.subarray(2));
  20.   }
  21.   scheduleEvent(resetTime, "remove");
  22. }
  23.  
  24. function keyCombo(sequence, action, options) {
  25.   /* Go through each sequence to do sequence-based actions */
  26.   switch(sequence) {
  27.     case "dream":
  28.       if (player.level.name == "dungeon01-b2.nw") {
  29.         player.addAchievement("foundhiddendungeon1");
  30.       }
  31.   }
  32.   /* go through the action key words and execute them with options*/
  33.   switch(action) {
  34.     /* single key actions */
  35.     case "grab":
  36.       player.movement.grab();
  37.     break;
  38.     case "attack":
  39.       player.attack();
  40.     break;
  41.     case "useskill":
  42.       player.useSkill();
  43.     break;
  44.  
  45.     // add your own code to execute different actions
  46.     case "opendoor":
  47.       findlevel(options[0]).(@ options[1]).openDoor();
  48.     break:
  49.     case "addachievement":
  50.       player.addAchievement(options[0]);
  51.     break;
  52.   }
  53. }
  54.    
  55. function onRemove() {
  56.   this.text = this.text.substring(1);
  57. }
  58.  
  59. // Change the options for each key order here
  60. // this._<keyorder> =  {"action", "param0", "param1", ...};
  61.  
  62. function configKeyOrders() {
  63.   // single key non-combo actions
  64.   this._s = {"attack"};
  65.   this._d = {"useskill"};
  66.   this._a = {"grab"};
  67.  
  68.   // Answer the final riddle in the dungeon to gain access to the boss
  69.   this._catcher = {
  70.     "opendoor", "dungeon04-c3.nw", "doorboss"
  71.   };
  72.  
  73.   // Answer the riddle to enter the hidden dungeon
  74.   this._dream = {
  75.     "opendoor", "overworld01-b2.nw", "doorentrance"
  76.   };
  77.  
  78.  
  79.   /* This is a function used to check for a valid key done in sequence.
  80.       Return false if there's nothing valid,
  81.       return array if the variable is valid.
  82.  
  83.       Here you could actually expand the system a lot, and even take in keys for slashing, jumping,
  84.       use items etc, and only do combos under a certain event from another system for example.
  85.  
  86.       Then you could actually have all player key input done in one system, instead of having it
  87.       spread out in different scripts
  88.   */
  89.   this.check = function(value) {
  90.     // single keys are not a combo, so don't execute
  91.     if (this.combosenabled && value.length() = 1) return false;
  92.  
  93.     // check if the value exists, then give the data if valid
  94.     temp.array = makevar("this._" @ value);
  95.     return ((temp.array.type() == 3)?temp.array:false);
  96.   };
  97.  
  98.   this.testcheck = false;
  99.   this.combosenabled = false;
  100. }
  101.  
  102. // Allows you to change the check function temporary, includes a reset
  103. public function changeCheckFunction(func) this.testcheck = func;
  104. public function resetCheckFunction() this.testcheck = false;
  105.  
  106. // enable or disable combos
  107. public function enableCombos() this.combosenabled = true;
  108. public function disableCombos() this.combosenabled = false;
  109.  
  110. // allows you to re map keys
  111. public function changeKeys(oldkey, newkey) {
  112.   temp.oldkey_value = makevar("this._" @ oldkey);
  113.   if (temp.oldkey_value.type() == 3) {
  114.     makevar("this._" @ newkey) = temp.oldkey_value;
  115.     makevar("this._" @ oldkey) = NULL;
  116.   }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement