Advertisement
wifiboost

Teemo gun

Mar 11th, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.57 KB | None | 0 0
  1. if SERVER then
  2. AddCSLuaFile()
  3. SWEP.Weight = 5
  4. SWEP.AutoSwitchTo = true
  5. SWEP.AutoSwitchFrom = true
  6. end
  7.  
  8. if CLIENT then
  9. SWEP.PrintName = "Teemo's Poison Dart"
  10. SWEP.Slot = 1
  11. SWEP.SlotPos = 1
  12. SWEP.DrawAmmo = true
  13. SWEP.DrawCrosshair = false
  14. end
  15.  
  16. SWEP.Author = "Your Name"
  17. SWEP.Contact = "Your Email"
  18. SWEP.Purpose = "A deadly poison dart weapon"
  19. SWEP.Instructions = "Left click to fire a poison dart"
  20.  
  21. SWEP.Category = "Your Category"
  22.  
  23. SWEP.Spawnable = true
  24. SWEP.AdminOnly = false
  25.  
  26. SWEP.ViewModelFOV = 70
  27. SWEP.ViewModelFlip = false
  28. SWEP.UseHands = true
  29. SWEP.ViewModel = "models/weapons/cstrike/c_pist_usp.mdl"
  30. SWEP.WorldModel = "models/weapons/w_pist_usp.mdl"
  31.  
  32. SWEP.Primary.Sound = Sound("Weapon_USP.Single")
  33. SWEP.Primary.Damage = 10
  34. SWEP.Primary.NumShots = 1
  35. SWEP.Primary.Recoil = 0.5
  36. SWEP.Primary.Cone = 0.02
  37. SWEP.Primary.Delay = 0.15
  38. SWEP.Primary.ClipSize = 20
  39. SWEP.Primary.DefaultClip = 60
  40. SWEP.Primary.Automatic = true
  41. SWEP.Primary.Ammo = "Pistol"
  42. SWEP.Primary.Tracer = 1
  43. SWEP.Primary.TracerName = "Tracer"
  44. SWEP.Primary.Force = 10
  45.  
  46. SWEP.Secondary.ClipSize = -1
  47. SWEP.Secondary.DefaultClip = -1
  48. SWEP.Secondary.Automatic = false
  49. SWEP.Secondary.Ammo = "none"
  50.  
  51. function SWEP:Initialize()
  52. self:SetHoldType("pistol")
  53. end
  54.  
  55. if SERVER then
  56.  
  57. SWEP.PoisonDamage = 5 -- Damage per tick of poison
  58. SWEP.PoisonInterval = 1 -- Time between poison ticks in seconds
  59. SWEP.PoisonDuration = 10 -- Duration of the poison debuff in seconds
  60. end
  61. function SWEP:PoisonTarget(target)
  62. if target:IsPlayer() or target:IsNPC() then
  63. target:SetNWBool("TeemoPoisoned", true)
  64. target:SetNWFloat("TeemoPoisonEndTime", CurTime() + self.PoisonDuration)
  65. target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
  66. end
  67. end
  68.  
  69.  
  70. function SWEP:Think()
  71. local owner = self:GetOwner()
  72. if not IsValid(owner) then return end
  73. local trace = owner:GetEyeTrace()
  74. local target = trace.Entity
  75. if IsValid(target) and not target:IsWorld() and not owner:IsSameTeam(target) then
  76. self:PoisonTarget(target)
  77. end
  78. if target:GetNWBool("TeemoPoisoned", false) and target:GetNWFloat("TeemoPoisonEndTime", 0) > CurTime() then
  79. if target:GetNWFloat("TeemoPoisonNextTick", 0) <= CurTime() then
  80. target:TakeDamage(self.PoisonDamage, owner, self)
  81. target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
  82. end
  83. else
  84. target:SetNWBool("TeemoPoisoned", false)
  85. target:SetNWFloat("TeemoPoisonEndTime", 0)
  86. target:SetNWFloat("TeemoPoisonNextTick", 0)
  87. end
  88. end
  89. function SWEP:Holster()
  90. self:EndPoison()
  91. return true
  92. end
  93. function SWEP:OnRemove()
  94. self:EndPoison()
  95. end
  96. function SWEP:EndPoison()
  97. for _, target in pairs(player.GetAll()) do
  98. target:SetNWBool("TeemoPoisoned", false)
  99. target:SetNWFloat("TeemoPoisonEndTime", 0)
  100. target:SetNWFloat("TeemoPoisonNextTick", 0)
  101. end
  102. end
  103. function Player:GetNWBool(name, default)
  104. return self:GetNWVarProxy(name, default)
  105. end
  106.  
  107. function SWEP:DrawHUD()
  108. local target = self:GetOwner():GetEyeTrace().Entity
  109. if IsValid(target) and not target:IsWorld() and not self:GetOwner():IsSameTeam(target) then
  110. draw.SimpleText("Poison Target: " .. target:GetName(), "DermaDefault", ScrW() / 2, ScrH() / 2 - 50, Color(255, 0, 0), TEXT_ALIGN_CENTER)
  111. end
  112.  
  113. if self:GetOwner():GetNWBool("TeemoPoisoned", false) then
  114. draw.SimpleText("Poisoned!", "DermaDefault", ScrW() / 2, ScrH() / 2 + 50, Color(0, 255, 0), TEXT_ALIGN_CENTER)
  115. end
  116. end
  117.  
  118. function SWEP:Initialize()
  119. self:SetHoldType("pistol")
  120. end
  121.  
  122. function SWEP:PrimaryAttack()
  123. if not self:CanPrimaryAttack() then return end
  124. local bullet = {}
  125. bullet.Num = self.Primary.NumShots
  126. bullet.Src = self.Owner:GetShootPos()
  127. bullet.Dir = self.Owner:GetAimVector()
  128. bullet.Spread = Vector(self.Primary.Cone, self.Primary.Cone, 0)
  129. bullet.Tracer = self.Primary.Tracer
  130. bullet.TracerName = self.Primary.TracerName
  131. bullet.Force = self.Primary.Force
  132. bullet.Damage = self.Primary.Damage
  133. bullet.AmmoType = self.Primary.Ammo
  134.  
  135. self:FireBullets(bullet)
  136.  
  137. self:EmitSound(self.Primary.Sound)
  138. self:TakePrimaryAmmo(1)
  139. self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
  140. end
  141.  
  142. function SWEP:SecondaryAttack()
  143. -- Secondary fire mode code here
  144. end
  145.  
  146. function SWEP:Reload()
  147. -- Reload code here
  148. end
  149.  
  150. if SERVER then
  151. SWEP.PoisonDamage = 5 -- Damage per tick of poison
  152. SWEP.PoisonInterval = 1 -- Time between poison ticks in seconds
  153. SWEP.PoisonDuration = 10 -- Duration of the poison debuff in seconds
  154. end
  155. function SWEP:PoisonTarget(target)
  156. if target:IsPlayer() or target:IsNPC() then
  157. target:SetNWBool("TeemoPoisoned", true)
  158. target:SetNWFloat("TeemoPoisonEndTime", CurTime() + self.PoisonDuration)
  159. target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
  160. end
  161. end
  162.  
  163. function SWEP:Think()
  164. local owner = self:GetOwner()
  165. if not IsValid(owner) then return end
  166. local trace = owner:GetEyeTrace()
  167. local target = trace.Entity
  168.  
  169. if IsValid(target) and not target:IsWorld() and not owner:IsSameTeam(target) then
  170. self:PoisonTarget(target)
  171. end
  172.  
  173. if target:GetNWBool("TeemoPoisoned", false) and target:GetNWFloat("TeemoPoisonEndTime", 0) > CurTime() then
  174. if target:GetNWFloat("TeemoPoisonNextTick", 0) <= CurTime() then
  175. target:TakeDamage(self.PoisonDamage, owner, self)
  176. target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
  177. end
  178. else
  179. target:SetNWBool("TeemoPoisoned", false)
  180. target:SetNWFloat("TeemoPoisonEndTime", 0)
  181. target:SetNWFloat("TeemoPoisonNextTick", 0)
  182. end
  183. end
  184.  
  185. function SWEP:DrawHUD()
  186. local target = self:GetOwner():GetEyeTrace().Entity
  187. if IsValid(target) and not target:IsWorld() and not self:GetOwner():IsSameTeam(target) then
  188. local w = ScrW()
  189. local h = ScrH()
  190. local x, y = w/2, h/2
  191. surface.SetDrawColor(255, 255, 255, 255)
  192. surface.DrawLine(x-20, y, x-10, y)
  193. surface.DrawLine(x+10, y, x+20, y)
  194. surface.DrawLine(x, y-20, x, y-10)
  195. surface.DrawLine(x, y+10, x, y+20)
  196. end
  197. end
  198.  
  199. function SWEP:Initialize()
  200. self:SetHoldType("pistol")
  201. end
  202.  
  203. function SWEP:PrimaryAttack()
  204. if not self:CanPrimaryAttack() then return end
  205. local bullet = {}
  206. bullet.Num = self.Primary.NumShots
  207. bullet.Src = self.Owner:GetShootPos()
  208. bullet.Dir = self.Owner:GetAimVector()
  209. bullet.Spread = Vector(self.Primary.Cone, self.Primary.Cone, 0)
  210. bullet.Tracer = self.Primary.Tracer
  211. bullet.TracerName = self.Primary.TracerName
  212. bullet.Force = self.Primary.Force
  213. bullet.Damage = self.Primary.Damage
  214. bullet.AmmoType = self.Primary.Ammo
  215.  
  216. self:FireBullets(bullet)
  217.  
  218. self:EmitSound(self.Primary.Sound)
  219. self:TakePrimaryAmmo(1)
  220. self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
  221. end
  222.  
  223. function SWEP:SecondaryAttack()
  224. -- Secondary fire mode code here
  225. end
  226.  
  227. function SWEP:Reload()
  228. -- Reload code here
  229. end
  230. if CLIENT then
  231. local TeemoIcon = Material("vgui/hud/teemo_icon")
  232. function SWEP:DrawHUD()
  233. surface.SetDrawColor(255, 255, 255, 255)
  234. surface.SetMaterial(TeemoIcon)
  235. surface.DrawTexturedRect(20, ScrH() - 120, 100, 100)
  236. local owner = self:GetOwner()
  237. if not IsValid(owner) then return end
  238.  
  239. local target = owner:GetEyeTrace().Entity
  240. if not IsValid(target) or target:IsWorld() or owner:IsSameTeam(target) then return end
  241.  
  242. local x, y = ScrW() / 2, ScrH() / 2
  243. local w, h = 200, 40
  244.  
  245. draw.RoundedBox(8, x - w / 2, y - h / 2, w, h, Color(0, 0, 0, 200))
  246.  
  247. local poisonEndTime = target:GetNWFloat("TeemoPoisonEndTime", 0)
  248. local timeLeft = math.max(0, poisonEndTime - CurTime())
  249. local numTicks = math.ceil(timeLeft / self.PoisonInterval)
  250. local totalDamage = self.PoisonDamage * numTicks
  251.  
  252. local text = string.format("Poisoned: %d damage over %d seconds", totalDamage, math.ceil(timeLeft))
  253. draw.SimpleText(text, "DermaDefault", x, y, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  254. end
  255. end
  256. function SWEP:PrimaryAttack()
  257. self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
  258. if SERVER then
  259. local bullet = {}
  260. bullet.Num = 1
  261. bullet.Src = self.Owner:GetShootPos()
  262. bullet.Dir = self.Owner:GetAimVector()
  263. bullet.Spread = Vector(0, 0, 0)
  264. bullet.Tracer = 1
  265. bullet.TracerName = "Tracer"
  266. bullet.Force = 10
  267. bullet.Damage = self.Primary.Damage
  268. self.Owner:FireBullets(bullet)
  269. end
  270.  
  271. self:EmitSound("Weapon_AR2.Single")
  272. self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
  273.  
  274. local animTime = self.Owner:GetViewModel():SequenceDuration()
  275. timer.Simple(animTime, function()
  276. if IsValid(self) then
  277. self:SendWeaponAnim(ACT_VM_IDLE)
  278. end
  279. end)
  280. end
  281.  
  282. if CLIENT then
  283. local TeemoIcon = Material("vgui/hud/teemo_icon")
  284. function SWEP:DrawHUD()
  285. surface.SetDrawColor(255, 255, 255, 255)
  286. surface.SetMaterial(TeemoIcon)
  287. surface.DrawTexturedRect(20, ScrH() - 120, 100, 100)
  288.  
  289. if self:IsPoisoned() then
  290. local totalDamage = self.PoisonDamage * self.PoisonDuration / self.PoisonInterval
  291. local timeLeft = self.PoisonEndTime - CurTime()
  292. local text = string.format("Poisoned: %d damage over %d seconds", totalDamage, math.ceil(timeLeft))
  293. draw.DrawText(text, "Trebuchet24", 130, ScrH() - 70, Color(255, 255, 255), TEXT_ALIGN_LEFT)
  294. end
  295. end
  296.  
  297. function SWEP:ViewModelDrawn()
  298. local vm = self.Owner:GetViewModel()
  299. local attachment = vm:GetAttachment(1)
  300.  
  301. if not attachment then return end
  302.  
  303. local pos = attachment.Pos
  304. local ang = attachment.Ang
  305.  
  306. pos = pos + ang:Forward() * 2 + ang:Right() * -3 + ang:Up() * -3
  307.  
  308. cam.Start3D2D(pos, ang, 0.02)
  309. surface.SetDrawColor(255, 255, 255, 255)
  310. surface.SetMaterial(TeemoIcon)
  311. surface.DrawTexturedRect(0, 0, 150, 150)
  312. cam.End3D2D()
  313. end
  314.  
  315. end
  316. function SWEP:GetPoisoned()
  317. return self:GetNWBool("IsPoisoned", false)
  318. end
  319. function SWEP:SecondaryAttack()
  320. -- Check if the poison is already active
  321. if self:GetPoisoned() then return end
  322. -- Set the poison duration and activate the poison
  323. self.PoisonDuration = 5
  324. self:SetPoisoned(true)
  325.  
  326. -- Play the poison sound
  327. self:EmitSound("teemo/poison.wav")
  328.  
  329. -- Create the poison effect
  330. local effectData = EffectData()
  331. effectData:SetOrigin(self.Owner:GetShootPos())
  332. util.Effect("TeemoPoison", effectData)
  333.  
  334. -- Set the next time the poison will tick
  335. self.NextPoisonTick = CurTime() + self.PoisonInterval
  336. end
  337. function SWEP:Think()
  338. -- Check if the poison is active
  339. if self:GetPoisoned() then
  340. -- Check if it's time for the poison to tick
  341. if CurTime() >= self.NextPoisonTick then
  342. -- Deal damage to the target
  343. local target = self.Owner:GetEyeTrace().Entity
  344. if IsValid(target) and target:IsPlayer() or target:IsNPC() then
  345. local damageInfo = DamageInfo()
  346. damageInfo:SetAttacker(self.Owner)
  347. damageInfo:SetInflictor(self)
  348. damageInfo:SetDamage(self.PoisonDamage)
  349. target:TakeDamageInfo(damageInfo)
  350. end
  351. -- Reduce the poison duration and set the next poison tick time
  352. self.PoisonDuration = self.PoisonDuration - self.PoisonInterval
  353. self.NextPoisonTick = CurTime() + self.PoisonInterval
  354. end
  355.  
  356. -- Check if the poison has run its course
  357. if self.PoisonDuration <= 0 then
  358. self:SetPoisoned(false)
  359. end
  360. end
  361. end
  362. function SWEP:Think()
  363. local owner = self:GetOwner()
  364. if self:IsPoisoned(owner) then
  365. -- Apply poison damage here
  366. end
  367. end
  368. -- Register the SWEP with Garry's Mod
  369. weapons.Register(SWEP, "weapon_teemo_poison_shooter", true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement