SHARE
TWEET

Untitled

a guest Jan 20th, 2016 69 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. -- Move around attachables
  196.     if self.Body["pointer"].ToDelete ~= true and self.Body["pointer"].PresetName ~= "" then
  197.         if self.HFlipped then
  198.             self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X * -1,self.Body["offset"].Y):RadRotate(self.RotAngle);
  199.         else
  200.             self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X,self.Body["offset"].Y):RadRotate(self.RotAngle);
  201.         end
  202.         self.Body["pointer"].RotAngle = self.RotAngle;
  203.         self.Body["pointer"].HFlipped = self.HFlipped;
  204.     end
  205.  
  206.     if self.Mag["pointer"].ToDelete ~= true and self.Mag["pointer"].PresetName ~= "" then
  207.         if self.HFlipped then
  208.             self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X * -1,self.Mag["offset"].Y):RadRotate(self.RotAngle);
  209.         else
  210.             self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X,self.Mag["offset"].Y):RadRotate(self.RotAngle);
  211.         end
  212.         self.Mag["pointer"].RotAngle = self.RotAngle;
  213.         self.Mag["pointer"].HFlipped = self.HFlipped;
  214.     end
  215.  
  216.     if self.Barrel["pointer"].ToDelete ~= true and self.Barrel["pointer"].PresetName ~= "" then
  217.         if self.HFlipped then
  218.             self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X * -1,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
  219.         else
  220.             self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
  221.         end
  222.         self.Barrel["pointer"].RotAngle = self.RotAngle;
  223.         self.Barrel["pointer"].HFlipped = self.HFlipped;
  224.     end
  225.  
  226.     if self:IsActivated() and self.firingtimer:IsPastSimMS(60000 / self.rateoffire) and self.ammocounter > 0 and self.Magazine ~= nil then
  227.     self.ammocounter = self.ammocounter - 1;
  228.     self.firingtimer:Reset()
  229.  
  230. -- Decide which kind of particle to create depending on the bullets particle type
  231.         if self.Bullet["particletype"] == "MOPixel" then
  232.             self.particle = CreateMOPixel(self.Bullet["particle"],"Brolands.rte");
  233.         elseif self.Bullet["particletype"] == "MOSRotating" then
  234.             self.particle = CreateMOSRotating(self.Bullet["particle"],"Brolands.rte");
  235.         elseif self.Bullet["particletype"] == "MOSParticle" then
  236.             self.particle = CreateMOSParticle(self.Bullet["particle"],"Brolands.rte");
  237.         end
  238.  
  239. -- Decide which kind of particle to create depending on the muzzleflashs particle type
  240.         if self.MuzzleFlash["particletype"] == "MOPixel" then
  241.             self.particle2 = CreateMOPixel(self.MuzzleFlash["particle"],"Brolands.rte");
  242.         elseif self.MuzzleFlash["particletype"] == "MOSRotating" then
  243.             self.particle2 = CreateMOSRotating(self.MuzzleFlash["particle"],"Brolands.rte");
  244.         elseif self.MuzzleFlash["particletype"] == "MOSParticle" then
  245.             self.particle2 = CreateMOSParticle(self.MuzzleFlash["particle"],"Brolands.rte");
  246.         end
  247.  
  248. -- Figure out if the actor is sharpaiming or not.
  249.     local MO = MovableMan:GetMOFromID(self.RootID)
  250.     local Aiming = 1;
  251.     if MO then
  252.         local Actor = ToActor(MO)
  253.         if Actor:GetController():IsState(Controller.AIM_SHARP) then
  254.         Aiming = 0.5;
  255.         else
  256.         Aiming = 1;
  257.         end
  258.     end
  259.  
  260. -- Create a direction vector for the projectile depending on if the gun is HFlipped or not
  261.         if self.HFlipped == true then
  262.             self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
  263.             if math.random() > 0.5 then
  264.                 self.firingvector = Vector(-1,0):RadRotate(self.RotAngle + math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
  265.             else
  266.                 self.firingvector = Vector(-1,0):RadRotate(self.RotAngle - math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
  267.             end
  268.         else
  269.             self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X,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.         end
  276.         self.particle.Mass = self.Bullet["mass"]
  277.         self.particle.Sharpness = self.Bullet["sharpness"];
  278.         self.particle.Vel = self.firingvector * self.Bullet["firevel"];
  279.         self.particle.LifeTime = 1500;
  280.         self.particle.Team = self.projectileteam;
  281.         self.particle.IgnoresTeamHits = true;
  282.         MovableMan:AddParticle(self.particle);
  283.  
  284. -- Create firing sound emitter.
  285.         self.particle = CreateAEmitter(self.FireSound,"Brolands.rte");
  286.         self.particle.Pos = self.Pos;
  287.         MovableMan:AddParticle(self.particle);
  288.  
  289. -- Create muzzleflash
  290.         self.particle2.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
  291.         self.particle2.Vel = self.Vel;
  292.         MovableMan:AddParticle(self.particle2);
  293.     end
  294.    
  295. -- Keeps track of the magazine
  296.     if self.Magazine == nil then
  297.         self.Mag["pointer"].Scale = 0;
  298.         self.ammocounter = self.ammocapacity;
  299.         self.reloading = true;
  300.     else
  301.         self.Mag["pointer"].Scale = 1;
  302.         self.Magazine.RoundCount = self.ammocounter;
  303.     end
  304.  
  305.     if self.reloading == true and self.Magazine ~= nil then
  306.     self.reloading = false;
  307.     -- When the gun is done reloading, play reload sound
  308.     self.particle = CreateAEmitter(self.ReloadSound,"Brolands.rte");
  309.     self.particle.Pos = self.Pos;
  310.     MovableMan:AddParticle(self.particle);
  311.     end
  312.  
  313. end
  314.  
  315. function Destroy(self)
  316. end
  317.  
  318. function Round(num, idp)
  319.     local mult = 10^(idp or 0)
  320.     return math.floor(num * mult + 0.5) / mult
  321. 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