iMagicBae

PortalGun Script (Commented) - iMagic

Apr 26th, 2020
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Scripted by iMagic*
  2. //findplayer("Graal2007722").addweapon(this.name);
  3. this.image = "tb_imagic-portalgun-icon.png"; //Icon File
  4.  
  5. function onActionServerSide(mode, bulletx, bullety, modeID, temp.pl, dir) {
  6.   switch (mode) {
  7.     case "SpawnPortal":
  8.     this.portaloffset = {{-2,-1.5},{-0.7,-3.5},{-2,-3.5},{-3,-3.5}};  // Spawn offset based on graal's perspective so that they dont spawn inside a wall.
  9.     switch (temp.modeID) {
  10.       case "PortalGun_modeBlue":  // Spawns the proper portal by mode ID.
  11.       temp.obj = putnpc2(temp.bulletx + this.portaloffset[temp.dir][0], temp.bullety + this.portaloffset[temp.dir][1], "join(\"personal_graal2007722_portal1\");");
  12.       temp.obj.owner = temp.pl;
  13.       // This next bit destroys any other portals of the same kind so that there may only be one portal of specific color.
  14.       for (temp.npc: this.level.npcs) {
  15.         if (temp.npc.isinclass("personal_graal2007722_portal1")) {
  16.           if (!(temp.npc.x == temp.bulletx && temp.npc.y == temp.bullety)) {
  17.             temp.npc.destroy();
  18.           }
  19.         }
  20.       }
  21.       break;
  22.  
  23.       case "PortalGun_modeOrange":
  24.       temp.obj = putnpc2(temp.bulletx + this.portaloffset[temp.dir][0], temp.bullety + this.portaloffset[temp.dir][1], "join(\"personal_graal2007722_portal2\");");
  25.       temp.obj.owner = temp.pl;
  26.       for (temp.npc: this.level.npcs) {
  27.         if (temp.npc.isinclass("personal_graal2007722_portal2")) {
  28.           if (!(temp.npc.x == temp.bulletx && temp.npc.y == temp.bullety)) {
  29.             temp.npc.destroy();
  30.           }
  31.         }
  32.       }
  33.       break;
  34.     }
  35.     break;
  36.  
  37.     case "destroy":
  38.     // This destroys any instance of either portal on the player's level
  39.     for (temp.npc: this.level.npcs) {
  40.       if (temp.npc.isinclass("personal_graal2007722_portal1") || temp.npc.isinclass("personal_graal2007722_portal2")) {
  41.         temp.npc.destroy();
  42.       }
  43.     }
  44.     break;
  45.   }
  46. }
  47.  
  48. //#CLIENTSIDE
  49.   this.image = "tb_imagic-portalgun-icon.png";
  50.  
  51. function onCreated() {
  52.     // GANIS
  53.   this.gun_blueidle = "tb_imagic-portalgun-blueidle";
  54.   this.gun_bluewalk = "tb_imagic-portalgun-bluewalk";
  55.   this.gun_bluefire = "tb_imagic-portalgun-bluefire";
  56.   this.gun_orangeidle = "tb_imagic-portalgun-orangeidle";
  57.   this.gun_orangewalk = "tb_imagic-portalgun-orangewalk";
  58.   this.gun_orangefire = "tb_imagic-portalgun-orangefire";
  59.   this.gun_transition1 = "tb_imagic-portalgun-transition1";
  60.   this.gun_transition2 = "tb_imagic-portalgun-transition2";
  61.  
  62.     // STATS
  63.   this.gun_firerate = 0.8;
  64.   this.gun_freeze = 0.2;
  65.   this.gun_bulletpos = {{-0.35,-2}, {-1.5,1}, {1.2,2.5}, {2,0.8}};
  66. }
  67.  
  68. function onKeyPressed(code, key) {
  69.   if (player.weapon == this.name) { //This bit, though redundant, avoids malfunction of other weapon scripts whilst this one isnt equipped.
  70.     if (key == "2") {
  71.       if (!this.isGunEquipped) {
  72.         this.isGunEquipped = true;
  73.         this.is_blue = true;
  74.         player.chat = "*Portal Gun Equipped*";
  75.         player.ani = "tb_imagic-portalgun-blueidle";
  76.         replaceani("idle", this.gun_blueidle);
  77.         replaceani("walk", this.gun_bluewalk);
  78.         freezeplayer(0.2);
  79.         setTimer(0.5);  //Sets this.isShooting to false on onTimeout();
  80.       } else {
  81.         this.isGunEquipped = false;
  82.         this.is_blue = NULL;
  83.         player.ani = "idle";
  84.         player.chat = "Unequipped";
  85.         replaceani("walk", "walk");
  86.         replaceani("idle", "idle");
  87.         freezeplayer(0.2);
  88.       }
  89.     }
  90.     if (this.isGunEquipped) {
  91.       if (key == "x") {
  92.         player.chat = "All portals have been destroyed";
  93.         triggerserver("gui", this.name, "destroy");  // Requests to destroy all of the instances of either portal on the level.
  94.       }
  95.       if (key == "d") {
  96.         if (!this.shooting) {
  97.           if (this.is_blue) {
  98.             this.shooting = true;
  99.             player.ani = this.gun_bluefire;
  100.             temp.angle = getangle(vecx(player.dir), vecy(player.dir));
  101.             modeID = "PortalGun_modeBlue";  // Sets a modeID for the blue mode.
  102.             setshootparams(modeID, player.account, player.dir);
  103.             shoot(player.x + this.gun_bulletpos[player.dir][0], player.y + this.gun_bulletpos[player.dir][1], player.z, temp.angle, 0, 0, "tb_imagic-portalgun-bulletblue", "");
  104.             freezeplayer(this.gun_freeze);
  105.             scheduleEvent(0.25, "onCheckMode", "");  // Automatically toggles between either the blue or orange mode when the player shoots.
  106.             setTimer(this.gun_firerate);
  107.           } else {
  108.             this.shooting = true;
  109.             player.ani = this.gun_orangefire;
  110.             temp.angle = getangle(vecx(player.dir), vecy(player.dir));
  111.             modeID = "PortalGun_modeOrange";
  112.             setshootparams(modeID, player.account, player.dir);
  113.             shoot(player.x + this.gun_bulletpos[player.dir][0], player.y + this.gun_bulletpos[player.dir][1], player.z, temp.angle, 0, 0, "tb_imagic-portalgun-bulletorange", "");
  114.             freezeplayer(this.gun_freeze);
  115.             scheduleEvent(0.25, "onCheckMode", "");
  116.             setTimer(this.gun_firerate);
  117.           }
  118.         }
  119.       }
  120.       if (key == "f") {
  121.         onCheckMode();  // Allows the player to toggle between modes at will.
  122.       }
  123.     }
  124.   }
  125. }
  126.  
  127. // This next bit catches the portal's modeID, the portal's x and y and the player's direction and sends that information serverside to create the portal.
  128. function onActionProjectile2(temp.x, temp.y, modeID, temp.pl, player.dir) {
  129.   if (player.weapon == this.name) {
  130.     temp.bulletx = params[0];
  131.     temp.bullety = params[1];
  132.     temp.modeID = params[2];
  133.     temp.pl = params[3];
  134.     pl.dir = params[4];
  135.     triggerserver("gui", this.name, "SpawnPortal", bulletx, bullety, modeID, temp.pl, pl.dir);
  136.   }
  137. }
  138.  
  139. // This next bit handles switching the ganis for toggling modes.
  140. function onCheckMode() {
  141.   if (this.is_blue) {
  142.     player.ani = this.gun_transition1;
  143.     replaceani("idle", this.gun_orangeidle);
  144.     replaceani("walk", this.gun_orangewalk);
  145.     this.is_blue = false;
  146.   } else {
  147.     player.ani = this.gun_transition2;
  148.     replaceani("idle", this.gun_blueidle);
  149.     replaceani("walk", this.gun_bluewalk);
  150.     this.is_blue = true;
  151.   }
  152. }
  153.  
  154. function onTimeOut() {
  155.   this.shooting = false;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment