iMagicBae

PortalGun Script (No comments) - iMagic

Apr 26th, 2020
453
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";
  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}};
  9.     switch (temp.modeID) {
  10.       case "PortalGun_modeBlue":
  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.       for (temp.npc: this.level.npcs) {
  14.         if (temp.npc.isinclass("personal_graal2007722_portal1")) {
  15.           if (!(temp.npc.x == temp.bulletx && temp.npc.y == temp.bullety)) {
  16.             temp.npc.destroy();
  17.           }
  18.         }
  19.       }
  20.       break;
  21.  
  22.       case "PortalGun_modeOrange":
  23.       temp.obj = putnpc2(temp.bulletx + this.portaloffset[temp.dir][0], temp.bullety + this.portaloffset[temp.dir][1], "join(\"personal_graal2007722_portal2\");");
  24.       temp.obj.owner = temp.pl;
  25.       for (temp.npc: this.level.npcs) {
  26.         if (temp.npc.isinclass("personal_graal2007722_portal2")) {
  27.           if (!(temp.npc.x == temp.bulletx && temp.npc.y == temp.bullety)) {
  28.             temp.npc.destroy();
  29.           }
  30.         }
  31.       }
  32.       break;
  33.     }
  34.     break;
  35.  
  36.     case "destroy":
  37.     for (temp.npc: this.level.npcs) {
  38.       if (temp.npc.isinclass("personal_graal2007722_portal1") || temp.npc.isinclass("personal_graal2007722_portal2")) {
  39.         temp.npc.destroy();
  40.       }
  41.     }
  42.     break;
  43.   }
  44. }
  45.  
  46. //#CLIENTSIDE
  47.   this.image = "tb_imagic-portalgun-icon.png";
  48.  
  49. function onCreated() {
  50.     // GANIS
  51.   this.gun_blueidle = "tb_imagic-portalgun-blueidle";
  52.   this.gun_bluewalk = "tb_imagic-portalgun-bluewalk";
  53.   this.gun_bluefire = "tb_imagic-portalgun-bluefire";
  54.   this.gun_orangeidle = "tb_imagic-portalgun-orangeidle";
  55.   this.gun_orangewalk = "tb_imagic-portalgun-orangewalk";
  56.   this.gun_orangefire = "tb_imagic-portalgun-orangefire";
  57.   this.gun_transition1 = "tb_imagic-portalgun-transition1";
  58.   this.gun_transition2 = "tb_imagic-portalgun-transition2";
  59.  
  60.     // STATS
  61.   this.gun_firerate = 0.8;
  62.   this.gun_freeze = 0.2;
  63.   this.gun_bulletpos = {{-0.35,-2}, {-1.5,1}, {1.2,2.5}, {2,0.8}};
  64. }
  65.  
  66. function onKeyPressed(code, key) {
  67.   if (player.weapon == this.name) {
  68.     if (key == "2") {
  69.       if (!this.isGunEquipped) {
  70.         this.isGunEquipped = true;
  71.         this.is_blue = true;
  72.         player.chat = "*Portal Gun Equipped*";
  73.         player.ani = "tb_imagic-portalgun-blueidle";
  74.         replaceani("idle", this.gun_blueidle);
  75.         replaceani("walk", this.gun_bluewalk);
  76.         freezeplayer(0.2);
  77.         setTimer(0.5);
  78.       } else {
  79.         this.isGunEquipped = false;
  80.         this.is_blue = NULL;
  81.         player.ani = "idle";
  82.         player.chat = "Unequipped";
  83.         replaceani("walk", "walk");
  84.         replaceani("idle", "idle");
  85.         freezeplayer(0.2);
  86.       }
  87.     }
  88.     if (this.isGunEquipped) {
  89.       if (key == "x") {
  90.         player.chat = "All portals have been destroyed";
  91.         triggerserver("gui", this.name, "destroy");
  92.       }
  93.       if (key == "d") {
  94.         if (!this.shooting) {
  95.           if (this.is_blue) {
  96.             this.shooting = true;
  97.             player.ani = this.gun_bluefire;
  98.             temp.angle = getangle(vecx(player.dir), vecy(player.dir));
  99.             modeID = "PortalGun_modeBlue";
  100.             setshootparams(modeID, player.account, player.dir);
  101.             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", "");
  102.             freezeplayer(this.gun_freeze);
  103.             blue_port_exists = true;
  104.             scheduleEvent(0.25, "onCheckMode", "");
  105.             setTimer(this.gun_firerate);
  106.           } else {
  107.             this.shooting = true;
  108.             player.ani = this.gun_orangefire;
  109.             temp.angle = getangle(vecx(player.dir), vecy(player.dir));
  110.             modeID = "PortalGun_modeOrange";
  111.             setshootparams(modeID, player.account, player.dir);
  112.             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", "");
  113.             this.join("personal_graal2007722_projectiles");
  114.             freezeplayer(this.gun_freeze);
  115.             orange_port_exists = true;
  116.             scheduleEvent(0.25, "onCheckMode", "");
  117.             setTimer(this.gun_firerate);
  118.           }
  119.         }
  120.       }
  121.       if (key == "f") {
  122.         onCheckMode();
  123.       }
  124.     }
  125.   }
  126. }
  127.  
  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. function onCheckMode() {
  140.   if (this.is_blue) {
  141.     player.ani = this.gun_transition1;
  142.     replaceani("idle", this.gun_orangeidle);
  143.     replaceani("walk", this.gun_orangewalk);
  144.     this.is_blue = false;
  145.   } else {
  146.     player.ani = this.gun_transition2;
  147.     replaceani("idle", this.gun_blueidle);
  148.     replaceani("walk", this.gun_bluewalk);
  149.     this.is_blue = true;
  150.   }
  151. }
  152.  
  153. function onTimeOut() {
  154.   this.shooting = false;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment