Advertisement
no1star

Untitled

Aug 15th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1.  
  2. SWEP.PrintName = "Repair Tool"
  3. SWEP.Author = "Liam0102"
  4. SWEP.Purpose = "Repair Star Wars Vehicles"
  5. SWEP.Instructions = "Left Click to Repair"
  6. SWEP.Category = "Star Wars"
  7. SWEP.Base = "weapon_base"
  8. SWEP.Slot = 3
  9. SWEP.SlotPos = 5
  10. SWEP.DrawAmmo = false
  11. SWEP.DrawCrosshair = true
  12. SWEP.ViewModel = "models/weapons/c_toolgun.mdl"
  13. SWEP.WorldModel = "models/weapons/w_toolgun.mdl"
  14. SWEP.AnimPrefix = "python"
  15. SWEP.HoldType = "pistol"
  16. SWEP.Spawnable = false
  17. SWEP.AdminSpawnable = false
  18. list.Set("SWVehicles.Weapons", SWEP.PrintName, SWEP);
  19.  
  20. SWEP.Primary.ClipSize = -1
  21. SWEP.Primary.DefaultClip = -1
  22. SWEP.Primary.Automatic = true;
  23. SWEP.Primary.Ammo = "none"
  24.  
  25. SWEP.Secondary.ClipSize = -1
  26. SWEP.Secondary.DefaultClip = -1
  27. SWEP.Secondary.Automatic = false
  28. SWEP.Secondary.Ammo = "none"
  29.  
  30. function SWEP:Deploy()
  31. self.Weapon:SendWeaponAnim(ACT_VM_DRAW); -- Animation
  32.  
  33. return true
  34. end
  35.  
  36. function SWEP:Initialize()
  37. self.Weapon:SetWeaponHoldType(self.HoldType)
  38. end
  39.  
  40. if CLIENT then
  41.  
  42. function SWEP:Initialize()
  43. surface.CreateFont( "REPAIR_Health", {
  44. font = "Arial",
  45. size = 32,
  46. weight = 1000,
  47. blursize = 0,
  48. scanlines = 0,
  49. antialias = true,
  50. underline = false,
  51. italic = false,
  52. strikeout = false,
  53. symbol = false,
  54. rotary = false,
  55. shadow = false,
  56. additive = false,
  57. outline = true,
  58. } )
  59. self.Weapon:SetWeaponHoldType(self.HoldType)
  60. end
  61.  
  62. local veh_Health = 0;
  63. local veh_StartHealth = 0;
  64. local shouldDraw = false;
  65. local Weapon;
  66. function SWEP:Think()
  67. local p = LocalPlayer();
  68. Weapon = self;
  69. veh_Health, veh_StartHealth = self:GetVehicleHealth();
  70.  
  71. end
  72.  
  73. local function RepairToolHUD()
  74. local p = LocalPlayer()
  75. if(veh_Health == nil or veh_StartHealth == nil) then return end;
  76. if(veh_Health > 0 and (p:GetActiveWeapon() == Weapon) and veh_StartHealth > 0) then
  77. surface.SetTextColor(255,255,255,255);
  78. surface.SetFont( "REPAIR_Health" )
  79. surface.SetTextPos(ScrW()/10*9,ScrH()/10*9);
  80. surface.DrawText("Hull: " .. (math.Round(veh_Health / veh_StartHealth * 100)) .. "%")
  81. end
  82. end
  83.  
  84. hook.Add("HUDPaint", "RepairToolHUD", RepairToolHUD)
  85.  
  86.  
  87. function SWEP:GetVehicleHealth()
  88. local p = LocalPlayer();
  89. local EyeTrace = p:GetEyeTrace();
  90. if(EyeTrace.Hit) then
  91. if(IsValid(EyeTrace.Entity)) then
  92. local e = EyeTrace.Entity;
  93. local class = e:GetClass();
  94. if(GetStarWarsVehicle(class) or e.IsSWVehicle) then
  95. return e:GetNWInt("Health"), e.StartHealth;
  96. end
  97. end
  98. end
  99. return 0,0;
  100. end
  101.  
  102. end
  103.  
  104. function GetStarWarsVehicle(veh)
  105.  
  106. local Vehicles = list.Get("SWVehicles");
  107. for k,v in pairs(Vehicles) do
  108. if(v.ClassName == veh) then
  109. return true;
  110. end
  111. end
  112. return false;
  113.  
  114. end
  115.  
  116. if SERVER then
  117.  
  118. AddCSLuaFile()
  119.  
  120.  
  121. function SWEP:Initialize()
  122. self:SetWeaponHoldType(self.HoldType)
  123. end
  124.  
  125. function SWEP:PrimaryAttack()
  126. local EyeTrace = self.Owner:GetEyeTrace();
  127. if(EyeTrace.Hit) then
  128. if(IsValid(EyeTrace.Entity)) then
  129. local e = EyeTrace.Entity;
  130. local class = e:GetClass();
  131. if(GetStarWarsVehicle(class) or e.IsSWVehicle) then
  132. local distance = (e:GetPos() - self.Owner:GetPos()):Length();
  133. if(distance <= 300) then
  134. local Health = e:GetNWInt("Health");
  135.  
  136. if(Health < e.StartHealth) then
  137. self:RepairEffect(EyeTrace.HitPos);
  138. end
  139.  
  140. if(Health <= e.StartHealth - 10) then
  141. Health = Health + 10;
  142. self:RepairEffect(EyeTrace.HitPos);
  143. else
  144. Health = e.StartHealth;
  145. end
  146.  
  147. if(e.CriticalDamage) then
  148. if(Health >= Health / e.StartHealth * 10) then
  149. e.CriticalDamage = false;
  150. end
  151. end
  152. e:SetNWInt("Health",Health);
  153. e.VehicleHealth = Health;
  154. if(Health >= e.StartHealth*0.1) then
  155. e.CriticalDamage = false;
  156. end
  157.  
  158. if(Health >= e.StartHealth*0.2) then
  159. e.WeaponsDisabled = false;
  160. end
  161. end
  162. elseif class == "my_entity" then
  163. e:SetArmorProgress(e:GetArmorProgress() + 1)
  164. self:RepairEffect(EyeTrace.HitPos)
  165.  
  166. end
  167. end
  168. end
  169. return true
  170. end
  171.  
  172. function SWEP:RepairEffect(pos)
  173. local fx = EffectData()
  174. fx:SetOrigin( pos )
  175. util.Effect( "StunstickImpact", fx, true )
  176.  
  177. end
  178.  
  179.  
  180. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement