SHARE
TWEET

Untitled

a guest Jul 17th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Create(self)
  2.  
  3. -- Initialize variables and timers
  4.  
  5. self.smgbodylist = {};
  6. self.smgbarrellist = {};
  7. self.smgmaglist = {};
  8. self.smgbulletlist = {};
  9. self.smgsoundlist = {};
  10. self.smgsoundlist["fire"] = {};
  11. self.smgsoundlist["reload"] = {};
  12. self.smgmuzzlelist = {};
  13.  
  14. self.projectileteam = -1;
  15. self.allmodulesfound = false;
  16. self.ammocounter = 0;
  17. self.reloading = false;
  18.  
  19. self.Body = {};
  20. self.Mag = {};
  21. self.Barrel = {};
  22. self.Bullet = {};
  23. self.FireSound = nil;
  24. self.ReloadSound = nil;
  25. self.MuzzleFlash = nil;
  26.  
  27. self.firingtimer = Timer();
  28.  
  29. -- Initial stats
  30. -- Basic stats
  31. self.rateoffire = 700;
  32. self.ammocapacity = 20;
  33. self.accuracy = 25;
  34.  
  35. -- Initial modifiers
  36. self.rofmod = 0.8 + math.random()*0.4;
  37. self.magmod = 0.8 + math.random()*0.4;
  38. self.accmod = 0.8 + math.random()*0.4;
  39. self.firevelmod = 0.8 + math.random()*0.4;
  40. self.massmod = 0.8 + math.random()*0.4;
  41. self.sharpnessmod = 0.8 + math.random()*0.4;
  42.  
  43. -- Load body modules
  44. dofile("Brolands.rte/smg/bodymodules.lua");
  45. BrolandsBodies(self);
  46.  
  47. -- Load barrel modules
  48. dofile("Brolands.rte/smg/barrelmodules.lua");
  49. BrolandsBarrels(self);
  50.  
  51. -- Load magazines modules
  52. dofile("Brolands.rte/smg/magazinemodules.lua");
  53. BrolandsMagazines(self);
  54.  
  55. -- Load bullets
  56. dofile("Brolands.rte/smg/bulletmodules.lua");
  57. BrolandsBullets(self);
  58.  
  59. -- Load muzzleflashes
  60. dofile("Brolands.rte/smg/muzzleflashmodules.lua");
  61. BrolandsMuzzleflashes(self);
  62.  
  63. -- Load sounds
  64. dofile("Brolands.rte/smg/soundmodules.lua");
  65. BrolandsSounds(self);
  66.  
  67. end
  68.  
  69. function Update(self)
  70.  
  71. -- Generate gun
  72.     if self.allmodulesfound ~= true then
  73.     -- Find the attachments
  74.         for i=1,MovableMan:GetMOIDCount()-1 do
  75.             local mo = MovableMan:GetMOFromID(i);
  76.             if mo.PresetName == "SmgBody" and mo.RootID == self.RootID then
  77.                 self.Body["pointer"] = ToAttachable(mo);
  78.                 self.Body["pointer"].GetsHitByMOs = false;
  79.             elseif mo.PresetName == "SmgMag" and mo.RootID == self.RootID then
  80.                 self.Mag["pointer"] = ToAttachable(mo);
  81.                 self.Mag["pointer"].GetsHitByMOs = false;
  82.             elseif mo.PresetName == "SmgBarrel" and mo.RootID == self.RootID then
  83.                 self.Barrel["pointer"] = ToAttachable(mo);
  84.                 self.Barrel["pointer"].GetsHitByMOs = false;
  85.             end
  86.             if self.Body["pointer"] and self.Mag["pointer"] and self.Barrel["pointer"] then
  87.             self.allmodulesfound = true;
  88.                 break;
  89.             end
  90.         end
  91.  
  92. -- Body
  93.     for k,v in pairs(self.smgbodylist[math.random(1,#self.smgbodylist)]) do self.Body[k] = v end
  94. --  for k,v in pairs(self.smgbodylist[15]) do self.Body[k] = v end
  95.     self.Body["pointer"].Frame = self.Body["sprite"];
  96.  
  97. -- Modify stat modifier with module modifier
  98.     self.rofmod = self.rofmod * self.Body["rofmod"];
  99.     self.magmod = self.magmod * self.Body["magmod"];
  100.     self.accmod = self.accmod * self.Body["accmod"];
  101.     self.firevelmod = self.firevelmod * self.Body["firevelmod"];
  102.     self.massmod = self.massmod * self.Body["massmod"];
  103.     self.sharpnessmod = self.sharpnessmod * self.Body["sharpnessmod"];
  104.  
  105. -- Mag
  106.     for k,v in pairs(self.smgmaglist[math.random(1,#self.smgmaglist)]) do self.Mag[k] = v end
  107. --  for k,v in pairs(self.smgmaglist[16]) do self.Mag[k] = v end
  108.     self.Mag["pointer"].Frame = self.Mag["sprite"];
  109.     self.Mag["offset"] = self.Body["magoffset"];
  110.  
  111. -- Modify stat modifier with module modifier
  112.     self.rofmod = self.rofmod * self.Mag["rofmod"];
  113.     self.magmod = self.magmod * self.Mag["magmod"];
  114.     self.accmod = self.accmod * self.Mag["accmod"];
  115.     self.firevelmod = self.firevelmod * self.Mag["firevelmod"];
  116.     self.massmod = self.massmod * self.Mag["massmod"];
  117.     self.sharpnessmod = self.sharpnessmod * self.Mag["sharpnessmod"];
  118.  
  119. -- Barrel
  120.     for k,v in pairs(self.smgbarrellist[math.random(1,#self.smgbarrellist)]) do self.Barrel[k] = v end
  121. --  for k,v in pairs(self.smgbarrellist[18]) do self.Barrel[k] = v end
  122.     self.Barrel["pointer"].Frame = self.Barrel["sprite"];
  123.     self.Barrel["offset"] = self.Body["barreloffset"];
  124.  
  125. -- Modify gun stat modifier with module modifier
  126.     self.rofmod = self.rofmod * self.Barrel["rofmod"];
  127.     self.magmod = self.magmod * self.Barrel["magmod"];
  128.     self.accmod = self.accmod * self.Barrel["accmod"];
  129.     self.firevelmod = self.firevelmod * self.Barrel["firevelmod"];
  130.     self.massmod = self.massmod * self.Barrel["massmod"];
  131.     self.sharpnessmod = self.sharpnessmod * self.Barrel["sharpnessmod"];
  132.  
  133. -- Bullet
  134.     for k,v in pairs(self.smgbulletlist[math.random(1,#self.smgbulletlist)]) do self.Bullet[k] = v end
  135. --  for k,v in pairs(self.smgbulletlist[3]) do self.Bullet[k] = v end
  136.  
  137. -- Modify gun stat modifier with module modifier
  138.     self.rofmod = self.rofmod * self.Bullet["rofmod"];
  139.     self.magmod = self.magmod * self.Bullet["magmod"];
  140.     self.accmod = self.accmod * self.Bullet["accmod"];
  141.     self.firevelmod = self.firevelmod * self.Bullet["firevelmod"];
  142.     self.massmod = self.massmod * self.Bullet["massmod"];
  143.     self.sharpnessmod = self.sharpnessmod * self.Bullet["sharpnessmod"];
  144.  
  145. -- Fire sound
  146.  
  147. self.FireSound = self.smgsoundlist["fire"][self.Bullet["firesounds"][math.random(1,#self.Bullet["firesounds"])]];
  148.  
  149. -- Reload sound
  150.  
  151. self.ReloadSound = self.smgsoundlist["reload"][self.Mag["reloadsounds"][math.random(1,#self.Mag["reloadsounds"])]];
  152.  
  153. -- Muzzle flash
  154.  
  155. self.MuzzleFlash = self.smgmuzzlelist[self.Bullet["muzzleflash"][math.random(1,#self.Bullet["muzzleflash"])]];
  156.  
  157. -- Done generating gun, apply gun stat modifiers
  158.     self.rateoffire = Round(self.rateoffire * self.rofmod);
  159.     self.ammocapacity = Round(self.ammocapacity * self.magmod);
  160.  
  161. -- You can't be more precise than 100%
  162. if self.accuracy > 100 then
  163.     self.accuracy = 100;
  164. else
  165.     self.accuracy = Round(self.accuracy * self.accmod);
  166. end
  167.    
  168.     self.Bullet["firevel"] = Round(self.Bullet["firevel"] * self.firevelmod);
  169.     self.Bullet["mass"] = self.Bullet["mass"] * self.massmod;
  170.     self.Bullet["sharpness"] = Round(self.Bullet["sharpness"] * self.sharpnessmod);
  171.    
  172.    
  173. -- Output gun stats to console
  174. --  print("\nRate of fire: "..self.rateoffire.." Rounds Per Minute\nMagazine capacity: "..self.ammocapacity.." Rounds\nAccuracy: "..self.accuracy.."%\nProjectile type: "..self.Bullet["particle"].."\nProjectile mass: "..self.Bullet["mass"].."\nProjectile speed: "..self.Bullet["firevel"].."\nProjectile sharpness: "..self.Bullet["sharpness"].."\n");
  175.  
  176.     self.ammocounter = self.ammocapacity;
  177.  
  178. -- Clear unneeded tables and variables
  179. self.smgbodylist = nil;
  180. self.smgbarrellist = nil;
  181. self.smgmaglist = nil;
  182. self.smgbulletlist = nil;
  183. self.smgsoundlist = nil;
  184. self.rofmod = nil;
  185. self.magmod = nil;
  186. self.accmod = nil;
  187. self.firevelmod = nil;
  188. self.massmod = nil;
  189. self.sharpnessmod = nil;
  190. end
  191.  
  192. -- Figure out what team is currently holding the gun
  193. self.projectileteam = MovableMan:GetMOFromID(self.RootID).Team;
  194.  
  195.  
  196. -- Move around attachables
  197.     if self.Body["pointer"].ToDelete ~= true and self.Body["pointer"].PresetName ~= "" then
  198.         if self.HFlipped then
  199.             self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X * -1,self.Body["offset"].Y):RadRotate(self.RotAngle);
  200.         else
  201.             self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X,self.Body["offset"].Y):RadRotate(self.RotAngle);
  202.         end
  203.         self.Body["pointer"].RotAngle = self.RotAngle;
  204.         self.Body["pointer"].HFlipped = self.HFlipped;
  205.     end
  206.  
  207.     if self.Mag["pointer"].ToDelete ~= true and self.Mag["pointer"].PresetName ~= "" then
  208.         if self.HFlipped then
  209.             self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X * -1,self.Mag["offset"].Y):RadRotate(self.RotAngle);
  210.         else
  211.             self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X,self.Mag["offset"].Y):RadRotate(self.RotAngle);
  212.         end
  213.         self.Mag["pointer"].RotAngle = self.RotAngle;
  214.         self.Mag["pointer"].HFlipped = self.HFlipped;
  215.     end
  216.  
  217.     if self.Barrel["pointer"].ToDelete ~= true and self.Barrel["pointer"].PresetName ~= "" then
  218.         if self.HFlipped then
  219.             self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X * -1,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
  220.         else
  221.             self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
  222.         end
  223.         self.Barrel["pointer"].RotAngle = self.RotAngle;
  224.         self.Barrel["pointer"].HFlipped = self.HFlipped;
  225.     end
  226.  
  227.    
  228.    
  229.    
  230.    
  231.    
  232.    
  233.     if self:IsActivated() and self.firingtimer:IsPastSimMS(60000 / self.rateoffire) and self.ammocounter > 0 and self.Magazine ~= nil then
  234.     self.ammocounter = self.ammocounter - 1;
  235.     self.firingtimer:Reset()
  236.  
  237. -- Decide which kind of particle to create depending on the bullets particle type
  238.         if self.Bullet["particletype"] == "MOPixel" then
  239.             self.particle = CreateMOPixel(self.Bullet["particle"],"Brolands.rte");
  240.         elseif self.Bullet["particletype"] == "MOSRotating" then
  241.             self.particle = CreateMOSRotating(self.Bullet["particle"],"Brolands.rte");
  242.         elseif self.Bullet["particletype"] == "MOSParticle" then
  243.             self.particle = CreateMOSParticle(self.Bullet["particle"],"Brolands.rte");
  244.         end
  245.  
  246. -- Decide which kind of particle to create depending on the muzzleflashs particle type
  247.         if self.MuzzleFlash["particletype"] == "MOPixel" then
  248.             self.particle2 = CreateMOPixel(self.MuzzleFlash["particle"],"Brolands.rte");
  249.         elseif self.MuzzleFlash["particletype"] == "MOSRotating" then
  250.             self.particle2 = CreateMOSRotating(self.MuzzleFlash["particle"],"Brolands.rte");
  251.         elseif self.MuzzleFlash["particletype"] == "MOSParticle" then
  252.             self.particle2 = CreateMOSParticle(self.MuzzleFlash["particle"],"Brolands.rte");
  253.         end
  254.  
  255. -- Figure out if the actor is sharpaiming or not.
  256.     local MO = MovableMan:GetMOFromID(self.RootID)
  257.     local Aiming = 1;
  258.     if MO then
  259.         local Actor = ToActor(MO)
  260.         if Actor:GetController():IsState(Controller.AIM_SHARP) then
  261.         Aiming = 0.5;
  262.         else
  263.         Aiming = 1;
  264.         end
  265.     end
  266.  
  267. -- Create a direction vector for the projectile depending on if the gun is HFlipped or not
  268.         if self.HFlipped == true then
  269.             self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
  270.             if math.random() > 0.5 then
  271.                 self.firingvector = Vector(-1,0):RadRotate(self.RotAngle + math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
  272.             else
  273.                 self.firingvector = Vector(-1,0):RadRotate(self.RotAngle - math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
  274.             end
  275.         else
  276.             self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
  277.             if math.random() > 0.5 then
  278.                 self.firingvector = Vector(1,0):RadRotate(self.RotAngle + math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
  279.             else
  280.                 self.firingvector = Vector(1,0):RadRotate(self.RotAngle - math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
  281.             end
  282.         end
  283.         self.particle.Mass = self.Bullet["mass"]
  284.         self.particle.Sharpness = self.Bullet["sharpness"];
  285.         self.particle.Vel = self.firingvector * self.Bullet["firevel"];
  286.         self.particle.LifeTime = 1500;
  287.         self.particle.Team = self.projectileteam;
  288.         self.particle.IgnoresTeamHits = true;
  289.         MovableMan:AddParticle(self.particle);
  290.  
  291. -- Create firing sound emitter.
  292.         self.particle = CreateAEmitter(self.FireSound,"Brolands.rte");
  293.         self.particle.Pos = self.Pos;
  294.         MovableMan:AddParticle(self.particle);
  295.  
  296. -- Create muzzleflash
  297.         self.particle2.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
  298.         self.particle2.Vel = self.Vel;
  299.         MovableMan:AddParticle(self.particle2);
  300.     end
  301.    
  302. -- Keeps track of the magazine
  303.     if self.Magazine == nil then
  304.         self.Mag["pointer"].Scale = 0;
  305.         self.ammocounter = self.ammocapacity;
  306.         self.reloading = true;
  307.     else
  308.         self.Mag["pointer"].Scale = 1;
  309.         self.Magazine.RoundCount = self.ammocounter;
  310.     end
  311.  
  312.     if self.reloading == true and self.Magazine ~= nil then
  313.     self.reloading = false;
  314.     -- When the gun is done reloading, play reload sound
  315.     self.particle = CreateAEmitter(self.ReloadSound,"Brolands.rte");
  316.     self.particle.Pos = self.Pos;
  317.     MovableMan:AddParticle(self.particle);
  318.     end
  319.  
  320. end
  321.  
  322. function Destroy(self)
  323. end
  324.  
  325. function Round(num, idp)
  326.     local mult = 10^(idp or 0)
  327.     return math.floor(num * mult + 0.5) / mult
  328. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top