Advertisement
offyerrocker

tact_reload.lua

Aug 7th, 2017 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.76 KB | None | 0 0
  1. if RequiredScript == "lib/tweak_data/weapontweakdata" then
  2.  
  3.     Hooks:PostHook( WeaponTweakData, "init", "Tact_Reload", function(self) 
  4.         --tactical reloading shite
  5.         local tact_rel = {'deagle','colt_1911','usp','p226','g22c','glock_17','glock_18c','b92fs','ppk','mp9','new_mp5','mp7','p90','olympic','akmsu','akm','akm_gold','ak74','m16','amcar','new_m4','ak5','s552','g36','aug','saiga','new_m14','scar','fal','rpk','msr','r93','m95','famas','galil','g3','scorpion','benelli','serbu','r870','ksg','g26','spas12','l85a2','vhs','hs2000','tec9','sub2000','asval','wa2000','polymer','winchester1874','sparrow','model70','m37','china','sr2','pl14','tecci','hajk','boot'}
  6.        
  7.         if self.m40a5 then
  8.             table.insert( tact_rel, "m40a5" )
  9.         end
  10.         if self.ak12 then
  11.             table.insert( tact_rel, "ak12" )
  12.         end
  13.         if self.pp then
  14.             table.insert( tact_rel, "pp" )
  15.         end
  16.         if self.mpx then
  17.             table.insert( tact_rel, "mpx" )
  18.         end
  19.         if self.fd338 then
  20.             table.insert( tact_rel, "fd338" )
  21.         end
  22.         if self.sks then
  23.             table.insert( tact_rel, "sks" )
  24.         end
  25.         if self.grach then
  26.             table.insert( tact_rel, "grach" )
  27.         end
  28.         if self.qs then
  29.             table.insert( tact_rel, "qs" )
  30.         end
  31.         if self.novas then
  32.             table.insert( tact_rel, "novas" )
  33.         end
  34.         if self.acw then
  35.             table.insert( tact_rel, "acw" )
  36.         end
  37.         if self.sr3m then
  38.             table.insert( tact_rel, "sr3m" )
  39.         end
  40.         if self.l115 then
  41.             table.insert( tact_rel, "l115" )
  42.         end
  43.         if self.g36k then
  44.             table.insert( tact_rel, "g36k" )
  45.         end
  46.         if self.contraband then
  47.             table.insert( tact_rel, "contraband" )
  48.         end --say hello to my Little Friend 7.62 Assault Rifle
  49.        
  50.         for i, wep_id in ipairs(tact_rel) do
  51.             self[ wep_id ].tactical_reload = 1
  52.         end
  53.        
  54.         local tact_akimbo = {'x_deagle','x_1911','x_b92fs','jowi','x_usp','x_g17','x_g22c','x_sr2','x_mp5','x_akmsu'}
  55.         if self.x_mpx then
  56.             table.insert( tact_rel, "x_mpx" )
  57.         end
  58.         if self.x_fmg9 then
  59.             table.insert( tact_rel, "x_fmg9" )
  60.         end
  61.         for i, wep_id in ipairs(tact_akimbo) do
  62.             self[ wep_id ].tactical_reload = 2
  63.         end
  64.        
  65.     end)
  66.  
  67. elseif RequiredScript == "lib/units/weapons/newraycastweaponbase" then
  68.  
  69.     --These functions were made by Deadly Mutton Chops and B1313
  70.     --{
  71.     function NewRaycastWeaponBase:clip_full()
  72.         if  self:weapon_tweak_data().tactical_reload then
  73.             return self:get_ammo_remaining_in_clip() == self:get_ammo_max_per_clip() +  self:weapon_tweak_data().tactical_reload
  74.         else
  75.             return self:get_ammo_remaining_in_clip() == self:get_ammo_max_per_clip()
  76.         end
  77.     end
  78.            
  79.     function NewRaycastWeaponBase:on_reload()
  80.         if self:gadget_overrides_weapon_functions() then        --offyerrocker wuz hear lol
  81.             NewRaycastWeaponBase.super.on_reload(self)
  82.             --last two lines here are probably unnecessary
  83.             --Previous method only affected conventional guns. Reloading the contraband_m203 would reload the base gun instead with that method.
  84.             self:set_reload_objects_visible(false)
  85.             self._reload_objects = {}
  86.         elseif self:weapon_tweak_data().uses_clip == true then
  87.             if self:get_ammo_remaining_in_clip() <= self:get_ammo_max_per_clip()  then
  88.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_total(), self:get_ammo_max_per_clip(), self:get_ammo_remaining_in_clip() +  self:weapon_tweak_data().clip_capacity))
  89.             end
  90.         else
  91.             if self:get_ammo_remaining_in_clip() > 0 and  self:weapon_tweak_data().tactical_reload == 1 then
  92.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_total(), self:get_ammo_max_per_clip() + 1))
  93.             elseif self:get_ammo_remaining_in_clip() > 1 and  self:weapon_tweak_data().tactical_reload == 2 then
  94.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_total(), self:get_ammo_max_per_clip() + 2))
  95.             elseif self:get_ammo_remaining_in_clip() == 1 and  self:weapon_tweak_data().tactical_reload == 2 then
  96.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_total(), self:get_ammo_max_per_clip() + 1))
  97.             elseif self:get_ammo_remaining_in_clip() > 0 and not  self:weapon_tweak_data().tactical_reload then
  98.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_total(), self:get_ammo_max_per_clip()))
  99.             elseif self._setup.expend_ammo then
  100.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_total(), self:get_ammo_max_per_clip()))
  101.             else
  102.                 self:set_ammo_remaining_in_clip(self:get_ammo_max_per_clip())
  103.                 self:set_ammo_total(self:get_ammo_max_per_clip())
  104.             end
  105.         end
  106.         managers.job:set_memory("kill_count_no_reload_" .. tostring(self._name_id), nil, true)
  107.     end
  108.    
  109.     function NewRaycastWeaponBase:reload_expire_t()
  110.         if self._use_shotgun_reload then
  111.             local ammo_remaining_in_clip = self:get_ammo_remaining_in_clip()
  112.             if self:get_ammo_remaining_in_clip() > 0 and  self:weapon_tweak_data().tactical_reload == 1 then
  113.                 return math.min(self:get_ammo_total() - ammo_remaining_in_clip, self:get_ammo_max_per_clip() + 1 - ammo_remaining_in_clip) * self:reload_shell_expire_t()
  114.             else
  115.                 return math.min(self:get_ammo_total() - ammo_remaining_in_clip, self:get_ammo_max_per_clip() - ammo_remaining_in_clip) * self:reload_shell_expire_t()
  116.             end
  117.         end
  118.         return nil
  119.     end
  120.    
  121.     function NewRaycastWeaponBase:update_reloading(t, dt, time_left)
  122.         if self._use_shotgun_reload and t > self._next_shell_reloded_t then
  123.             local speed_multiplier = self:reload_speed_multiplier()
  124.             self._next_shell_reloded_t = self._next_shell_reloded_t + self:reload_shell_expire_t() / speed_multiplier
  125.             if self:get_ammo_remaining_in_clip() > 0 and  self:weapon_tweak_data().tactical_reload == 1 then
  126.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_max_per_clip() + 1, self:get_ammo_remaining_in_clip() + 1))
  127.                 return true
  128.             else
  129.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_max_per_clip(), self:get_ammo_remaining_in_clip() + 1))
  130.                 return true
  131.             end
  132.             managers.job:set_memory("kill_count_no_reload_" .. tostring(self._name_id), nil, true)
  133.             return true
  134.         end
  135.     end
  136.     --}
  137.  
  138. elseif RequiredScript == "lib/units/weapons/shotgun/newshotgunbase" then
  139.    
  140.     --These functions were made by Dumb Money Clocks and B1313
  141.     --{
  142.     function NewShotgunBase:reload_expire_t()
  143.         local ammo_remaining_in_clip = self:get_ammo_remaining_in_clip()
  144.         if self:get_ammo_remaining_in_clip() > 0 and  self:weapon_tweak_data().tactical_reload == 1 then
  145.             return math.min(self:get_ammo_total() - ammo_remaining_in_clip, self:get_ammo_max_per_clip() + 1 - ammo_remaining_in_clip) * self:reload_shell_expire_t()
  146.         else
  147.             return math.min(self:get_ammo_total() - ammo_remaining_in_clip, self:get_ammo_max_per_clip() - ammo_remaining_in_clip) * self:reload_shell_expire_t()
  148.         end
  149.     end
  150.    
  151.     function NewShotgunBase:reload_enter_expire_t()
  152.         return self:weapon_tweak_data().timers.shotgun_reload_enter or 0.3
  153.     end
  154.    
  155.     function NewShotgunBase:reload_exit_expire_t()
  156.         return self:weapon_tweak_data().timers.shotgun_reload_exit_empty or 0.7
  157.     end
  158.    
  159.     function NewShotgunBase:reload_not_empty_exit_expire_t()
  160.         return self:weapon_tweak_data().timers.shotgun_reload_exit_not_empty or 0.3
  161.     end
  162.    
  163.     function NewShotgunBase:reload_shell_expire_t()
  164.         return self:weapon_tweak_data().timers.shotgun_reload_shell or 0.56666666
  165.     end
  166.    
  167.     function NewShotgunBase:_first_shell_reload_expire_t()
  168.         return self:reload_shell_expire_t() - (self:weapon_tweak_data().timers.shotgun_reload_first_shell_offset or 0.33)
  169.     end
  170.    
  171.     function NewShotgunBase:start_reload(...)
  172.         NewShotgunBase.super.start_reload(self, ...)
  173.         self._started_reload_empty = self:clip_empty()
  174.         local speed_multiplier = self:reload_speed_multiplier()
  175.         self._next_shell_reloded_t = managers.player:player_timer():time() + self:_first_shell_reload_expire_t() / speed_multiplier
  176.     end
  177.    
  178.     function NewShotgunBase:started_reload_empty()
  179.         return self._started_reload_empty
  180.     end
  181.    
  182.     function NewShotgunBase:update_reloading(t, dt, time_left)
  183.         if t > self._next_shell_reloded_t then
  184.             local speed_multiplier = self:reload_speed_multiplier()
  185.             self._next_shell_reloded_t = self._next_shell_reloded_t + self:reload_shell_expire_t() / speed_multiplier
  186.             if self:get_ammo_remaining_in_clip() > 0 and  self:weapon_tweak_data().tactical_reload == 1 then
  187.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_max_per_clip() + 1, self:get_ammo_remaining_in_clip() + 1))
  188.                 return true
  189.             else
  190.                 self:set_ammo_remaining_in_clip(math.min(self:get_ammo_max_per_clip(), self:get_ammo_remaining_in_clip() + 1))
  191.                 return true
  192.             end
  193.         end
  194.     end
  195.    
  196.     function SaigaShotgun:reload_expire_t()
  197.         return nil
  198.     end
  199.    
  200.     function SaigaShotgun:reload_enter_expire_t()
  201.         return nil
  202.     end
  203.    
  204.     function SaigaShotgun:reload_exit_expire_t()
  205.         return self:weapon_tweak_data().timers.reload_exit_empty or nil
  206.     end
  207.    
  208.     function SaigaShotgun:reload_not_empty_exit_expire_t()
  209.         return self:weapon_tweak_data().timers.reload_exit_not_empty or nil
  210.     end
  211.    
  212.     function SaigaShotgun:update_reloading(t, dt, time_left)
  213.     end
  214. --}
  215.    
  216. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement