Advertisement
Guest User

[LUA] Predator Missile

a guest
Oct 3rd, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.86 KB | None | 0 0
  1. if CLIENT then
  2. SWEP.PrintName = "Predator Missile"
  3. SWEP.LimitedStock = true
  4. SWEP.Author = "Otger"
  5. --SWEP.Contact = "n/a"
  6. SWEP.Purpose = "Air-to-surface controllable missile."
  7. SWEP.Instructions = "Left click to launch an air-to-surface missile from the sky above the aimed position.\nWhen launched, use the mouse or the movement keys to direct it, left click to boost it, and right click to quit controlling it.\nReload to open the menu."
  8. SWEP.Slot = 6
  9. SWEP.SlotPos = 6
  10. SWEP.Kind = WEAPON_EQUIP1
  11. SWEP.CanBuy = { ROLE_TRAITOR }
  12. SWEP.WepSelectIcon = surface.GetTextureID("VGUI/swep_asm")
  13. SWEP.BounceWeaponIcon = true
  14. SWEP.ViewModel = "models/weapons/v_c4.mdl"
  15. SWEP.WorldModel = "models/weapons/w_c4.mdl"
  16. SWEP.DrawAmmo = false
  17. SWEP.DrawCrosshair = true
  18. --SWEP.Category = "Other"
  19. end
  20. SWEP.Weight = 5
  21. SWEP.AutoSwitchTo = false
  22. SWEP.AutoSwitchFrom = false
  23. SWEP.Spawnable = true
  24. SWEP.AdminSpawnable = true
  25.  
  26. if SERVER then
  27. AddCSLuaFile("swep_asm.lua")
  28. resource.AddFile("materials/VGUI/swep_asm.vmt")
  29. resource.AddFile("materials/VGUI/swep_asm.vtf")
  30. resource.AddFile("materials/VGUI/entities/swep_asm.vmt")
  31. resource.AddFile("materials/VGUI/entities/swep_asm.vtf")
  32. --resource.AddFile("materials/HUD/asm_available.vmt")
  33. --resource.AddFile("materials/HUD/asm_available.vtf")
  34. resource.AddFile("materials/HUD/killicons/asm_missile.vmt")
  35. resource.AddFile("materials/HUD/killicons/asm_missile.vtf")
  36. if util.IsValidModel("models/weapons/v_c4.mdl") then
  37. SWEP.ModelC4 = true
  38. SWEP.ViewModel = "models/weapons/v_c4.mdl"
  39. SWEP.WorldModel = "models/weapons/w_c4.mdl"
  40. else
  41. SWEP.ModelC4 = false
  42. SWEP.ViewModel = "models/weapons/v_toolgun.mdl"
  43. SWEP.WorldModel = "models/weapons/w_toolgun.mdl"
  44. end
  45. end
  46. SWEP.Primary.ClipSize = -1
  47. SWEP.Primary.DefaultClip = -1
  48. SWEP.Primary.Automatic = false
  49. SWEP.Primary.Ammo = "none"
  50. SWEP.Secondary.ClipSize = -1
  51. SWEP.Secondary.DefaultClip = -1
  52. SWEP.Secondary.Automatic = false
  53. SWEP.Secondary.Ammo = "none"
  54.  
  55. local SndReady = Sound("npc/metropolice/vo/isreadytogo.wav")
  56. local SndReadyB = Sound("buttons/blip2.wav")
  57. local SndRequested = Sound("buttons/button24.wav")
  58. local SndInbound = Sound("npc/combine_soldier/vo/inbound.wav")
  59.  
  60. util.PrecacheModel("models/props_junk/PopCan01a.mdl")
  61. util.PrecacheModel("models/props_c17/canister01a.mdl")
  62.  
  63. function SWEP:Initialize()
  64. self.Delay = 0
  65. self.Status = 0
  66. self.ThirdPerson = false
  67.  
  68. if self.ModelC4 then self:SetWeaponHoldType("slam")
  69. else self:SetWeaponHoldType("pistol") end
  70.  
  71. if CLIENT then
  72. self.FadeCount = 0
  73. self.Load = 0
  74. killicon.Add("sent_asm","HUD/killicons/asm_missile",Color(255,0,0,255))
  75. language.Add("sent_asm","Air-to-surface Missile")
  76. --hook.Add("HUDPaint","ASMSwepDrawHUD", function() self:DrawInactiveHUD() end)
  77. end
  78. end
  79.  
  80. function SWEP:OnRemove()
  81. if SERVER then
  82. self:UnlockPlayer()
  83. if IsValid(self.Camera) then
  84. if IsValid(self.Owner) && (self.Owner:GetViewEntity() == self.Camera) then
  85. self.Owner:SetViewEntity(self.Owner)
  86. end
  87. self.Camera:Remove()
  88. end
  89. end
  90. if CLIENT then
  91. if self.HtmlIcon && self.HtmlIcon:IsValid() then self.HtmlIcon:Remove() end
  92. self.HtmlIcon = nil
  93. if(self.Menu && self.Menu:IsValid()) then
  94. self.Menu:SetVisible(false)
  95. self.Menu:Remove()
  96. end
  97. hook.Remove("HUDPaint","AsmSwepDrawHUD")
  98. end
  99. end
  100.  
  101. function SWEP:Deploy()
  102. if SERVER then
  103. self:SendWeaponAnim(ACT_VM_DRAW)
  104. end
  105. return true
  106. end
  107.  
  108. function SWEP:Holster()
  109. if(self.Status>0) then return false end
  110. return true
  111. end
  112.  
  113. function SWEP:ShouldDropOnDie() return false end
  114.  
  115. -- SERVER --
  116.  
  117. if SERVER then
  118. if !ASMSettings then
  119. ASMSettings = {}
  120. ASMSettings.DmgSelf = true
  121. ASMSettings.DmgFriend = true
  122. end
  123.  
  124. function SWEP:PrimaryAttack()
  125. if(self.Status == 0) then
  126. if self.Delay > CurTime() then return end
  127.  
  128. local tr = self.Owner:GetEyeTrace()
  129. local vPos = self:FindInitialPos(tr.HitPos)
  130.  
  131. if vPos then
  132. if self:SpawnMissile(vPos) then
  133. self.Owner:ConCommand("firstperson")
  134. self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
  135. self.Owner:SetAnimation(PLAYER_ATTACK1)
  136. self:EmitSound(SndRequested)
  137.  
  138. self:LockPlayer()
  139. self:SetStatus(1,1.75)
  140. end
  141. else
  142. self:SendMessage(1)
  143. end
  144. elseif(self.Status == -1) then
  145. self:SendMessage(2)
  146. end
  147. self:SetNextPrimaryFire(CurTime()+999999999999999999)
  148. end
  149.  
  150. function SWEP:SecondaryAttack() end
  151.  
  152. function SWEP:Reload()
  153. if self.Owner:IsAdmin() && (self.Status < 1) then
  154. umsg.Start("ASM-Menu",self.Owner)
  155. umsg.String(tostring(ASMSettings.DmgSelf)..","..tostring(ASMSettings.DmgFriend))
  156. umsg.End()
  157. end
  158. end
  159.  
  160. function SWEP:Equip()
  161. --if !self.ModelC4 then self:SendMessage(0) end
  162. end
  163.  
  164. function SWEP:Think()
  165. if CurTime() < self.Delay then return end
  166.  
  167. if self.Status == 1 then
  168. self:SetStatus(2,0.5)
  169. elseif self.Status == 2 then
  170. if IsValid(self.Missile) then
  171. self.Missile:Launch()
  172. self.Owner:SetViewEntity(self.Camera)
  173. self:SendWeaponAnim(ACT_VM_IDLE)
  174. self:SetStatus(3,0)
  175. else
  176. self:SetStatus(0,0)
  177. end
  178. elseif (self.Status>2) &&(self.Status<6) then
  179. if IsValid(self.Missile) then
  180. if (self.Status==3) then
  181. if self.Owner:KeyDown(IN_ATTACK) or self.Owner:KeyDown(IN_USE) then
  182. self:SetStatus(4,0)
  183. self.Missile:Boost()
  184. end
  185. end
  186. if self.Status < 5 then
  187. local vVel = Vector(0,0,0)
  188.  
  189. if self.Owner:KeyDown(IN_FORWARD) then vVel=vVel+Vector(16,0,0) end
  190. if self.Owner:KeyDown(IN_BACK) then vVel=vVel+Vector(-16,0,0) end
  191. if self.Owner:KeyDown(IN_MOVELEFT) then vVel=vVel+Vector(0,16,0) end
  192. if self.Owner:KeyDown(IN_MOVERIGHT) then vVel=vVel+Vector(0,-16,0) end
  193.  
  194. local cmd = self.Owner:GetCurrentCommand()
  195. vVel=vVel+Vector(0,-cmd:GetMouseX()/10,0)
  196. vVel=vVel+Vector(-cmd:GetMouseY()/10,0,0)
  197.  
  198. self.Missile:GetPhysicsObject():AddVelocity(vVel)
  199.  
  200. if self.Owner:KeyDown(IN_ATTACK2) then
  201. self.Owner:SetViewEntity(self.Owner)
  202. self:UnlockPlayer()
  203. self:SetStatus(5,0)
  204. end
  205. end
  206. else
  207. self:MissileDestroyed()
  208. self:SendMessage(3)
  209. end
  210. elseif self.Status == 6 then
  211. self:UnlockPlayer()
  212. self:SetStatus(-1,0)
  213.  
  214. timer.Simple(3, function()
  215. if IsValid(self) then
  216. if self.Status == -1 then self:SetStatus(0,0) end
  217. end
  218. end)
  219. end
  220. end
  221.  
  222. function SWEP:SetStatus(status,delay)
  223. self.Status = (status or 0)
  224. if delay > 0 then self.Delay = CurTime() + delay end
  225. if IsValid(self.Owner) then
  226. umsg.Start("ASM-Update", self.Owner)
  227. umsg.Entity(self.Weapon)
  228. umsg.Short(status or 0)
  229. umsg.End()
  230. end
  231. end
  232.  
  233. function SWEP:SendMessage(id)
  234. umsg.Start("ASM-Msg",self.Owner)
  235. umsg.Short(id)
  236. umsg.End()
  237. end
  238.  
  239. function SWEP:CreateCamera()
  240. local ent = ents.Create("prop_physics")
  241. ent:SetModel("models/props_junk/PopCan01a.mdl")
  242. ent:SetPos(self.Owner:GetPos())
  243. ent:SetAngles(Angle(90,0,0))
  244. ent:Spawn()
  245. ent:Activate()
  246. ent:SetMoveType(MOVETYPE_NOCLIP)
  247. ent:SetSolid(SOLID_NONE)
  248. ent:SetRenderMode(RENDERMODE_NONE)
  249. ent:DrawShadow(false)
  250. return ent
  251. end
  252.  
  253. function SWEP:SpawnMissile(vPos)
  254. local mis = ents.Create("sent_asm")
  255. mis:SetPos(vPos+Vector(0,0,mis:OBBMins().z-48))
  256. mis:SetAngles(Angle(90,0,0))
  257. mis:Spawn()
  258. mis:Activate()
  259.  
  260. if IsValid(mis) then
  261. if !IsValid(self.Camera) then self.Camera = self:CreateCamera() end
  262.  
  263. self.Camera:SetPos(mis:GetPos()+Vector(0,0,-56))
  264. self.Camera:SetAngles(Angle(90,0,0))
  265. self.Camera:SetParent(mis)
  266.  
  267. mis.Owner = self.Owner
  268. mis.SWEP = self
  269.  
  270. self.Missile = mis
  271. self:SetNWEntity("Missile",mis)
  272. return true
  273. end
  274. return false
  275. end
  276.  
  277. local function ASMSetVis(ply)
  278. local wep = ply:GetActiveWeapon()
  279. if IsValid(wep) && wep:GetClass() == "swep_asm" then
  280. if (wep.Status==2) or (wep.Status==3) then
  281. if IsValid(wep.Camera) then AddOriginToPVS(wep.Camera:GetPos()) end
  282. end
  283. end
  284. end
  285. hook.Add("SetupPlayerVisibility", "ASMSetupVis", ASMSetVis)
  286.  
  287. local function ASMGetDmg(ent,inflictor,attacker,amount,dmginfo)
  288. if IsValid(inflictor) && (inflictor:GetClass()=="sent_asm") && IsValid(inflictor.SWEP) then
  289. if ent:IsPlayer() then
  290. if (inflictor.Owner == ent) && !ASMSettings.DmgSelf then
  291. dmginfo:SetDamage(0)
  292. end
  293. elseif ent:IsNPC() then
  294. if !ASMSettings.DmgFriend && inflictor.SWEP:CheckFriendly(ent) then
  295. dmginfo:SetDamage(0)
  296. end
  297. end
  298. end
  299. end
  300. hook.Add("EntityTakeDamage", "ASMSetupDamage", ASMGetDmg)
  301.  
  302. function SWEP:LockPlayer()
  303. self.LastMoveType = self.Owner:GetMoveType()
  304. self.Owner:SetMoveType(MOVETYPE_NONE)
  305. end
  306.  
  307. function SWEP:UnlockPlayer()
  308. if IsValid(self.Owner) && (self.Owner:GetMoveType()==MOVETYPE_NONE) then
  309. self.Owner:SetMoveType(self.LastMoveType or MOVETYPE_WALK)
  310. end
  311. end
  312.  
  313. function SWEP:MissileDestroyed()
  314. if IsValid(self.Owner) then
  315. self.Owner:SetViewEntity(self.Owner)
  316. end
  317. if IsValid(self.Camera) then
  318. self.Camera:SetParent(nil)
  319. end
  320. if(self.Status>1) then
  321. self:SetStatus(6,0.5)
  322. end
  323. end
  324.  
  325. function SWEP:FindInitialPos(vStart)
  326. local td = {}
  327. td.start = vStart+Vector(0,0,-32)
  328. td.endpos = vStart
  329. td.endpos.z = 16384
  330. td.mask = MASK_NPCWORLDSTATIC
  331. td.filter = {}
  332. local bContinue = true
  333. local nCount=0
  334. local tr = {}
  335. local vPos = nil
  336.  
  337. while bContinue && td.start.z <= td.endpos.z do
  338. nCount = nCount + 1
  339. tr = util.TraceLine(td)
  340. if tr.HitSky then
  341. vPos = tr.HitPos
  342. bContinue = false
  343. elseif !tr.Hit then
  344. td.start = tr.HitPos - Vector(0,0,64)
  345. elseif tr.HitWorld then
  346. td.start = tr.HitPos + Vector(0,0,64)
  347. elseif(IsValid(tr.Entity)) then
  348. table.insert(td.filter, tr.Entity)
  349. end
  350. if nCount>128 then break end
  351. end
  352. return vPos
  353. end
  354.  
  355. function SWEP:CheckFriendly(ent)
  356. if ent:Disposition(self.Owner) == 1 then return false end
  357. return true
  358. end
  359.  
  360. concommand.Add("ASM-Config", function(ply,cmd,args)
  361. local wep = Entity(tonumber(args[1]))
  362. if IsValid(wep) && wep:GetClass() == "swep_asm" then
  363. if ply == wep.Owner && ply:IsAdmin() then
  364. ASMSettings.DmgSelf = tobool(args[2])
  365. ASMSettings.DmgFriend = tobool(args[3])
  366. end
  367. end
  368. end)
  369. end
  370.  
  371. -- CLIENT --
  372.  
  373. if CLIENT then
  374.  
  375. surface.CreateFont("AsmScreenFont", {
  376. size = 18,
  377. weight = 400,
  378. antialias = false,
  379. shadow = false,
  380. font = "Trebuchet MS"})
  381.  
  382. surface.CreateFont("AsmCamFont", {
  383. size = 22,
  384. weight = 700,
  385. antialias = false,
  386. shadow = false,
  387. font = "Courier New"})
  388.  
  389. --local texScreenOverlay = surface.GetTextureID("effects/combine_binocoverlay")
  390. --local matMissileAvailable = Material("HUD/asm_available")
  391.  
  392. local SndNoPos = Sound("npc/combine_soldier/vo/sectorisnotsecure.wav")
  393. local SndNoPosB = Sound("buttons/button19.wav")
  394. local SndNotReady = Sound("buttons/button2.wav")
  395. local SndLost = Sound("npc/combine_soldier/vo/lostcontact.wav")
  396.  
  397. function SWEP:Think() end
  398.  
  399. usermessage.Hook("ASM-Update",function(um)
  400. local ent = um:ReadEntity()
  401. if IsValid(ent) && ent:GetClass() == "swep_asm" then
  402. ent:UpdateStatus(um:ReadShort())
  403. end
  404. end)
  405.  
  406. usermessage.Hook("ASM-Msg",function(um)
  407. local nId = um:ReadShort()
  408. if(nId==0) then
  409. MsgN("[Air-to-surface Missile SWEP] Counter-Strike: Source is not mounted. Using Toolgun model.")
  410. elseif(nId==1) then
  411. GAMEMODE:AddNotify("Could not find open sky above the specified position",NOTIFY_ERROR,5)
  412. LocalPlayer():EmitSound(SndNoPos)
  413. LocalPlayer():EmitSound(SndNoPosB)
  414. elseif(nId==2) then
  415. GAMEMODE:AddNotify("Missiles currently unavailable",NOTIFY_ERROR,5)
  416. LocalPlayer():EmitSound(SndNotReady)
  417. elseif(nId==3) then
  418. GAMEMODE:AddNotify("Lost contact with the missile",NOTIFY_GENERIC,5)
  419. LocalPlayer():EmitSound(SndLost)
  420. end
  421. end)
  422.  
  423. usermessage.Hook("ASM-Menu",function(um)
  424. local wep = LocalPlayer():GetActiveWeapon()
  425. if wep && wep:GetClass() == "swep_asm" then
  426. wep:MenuOpen(string.Explode(",",um:ReadString()))
  427. end
  428. end)
  429.  
  430. function SWEP:MenuCreate()
  431. if self.Menu then
  432. self.Menu:SetVisible(false)
  433. self.Menu:Remove()
  434. end
  435. self.Menu = vgui.Create("DFrame")
  436. self.Menu:SetName("ASM-Config")
  437. self.Menu:SetTitle("Air-to-surface Missile Settings")
  438. self.Menu:SetDraggable(true)
  439. self.Menu:ShowCloseButton(true)
  440. self.Menu:SetDeleteOnClose(false)
  441. self.Menu:SetSize(256,128)
  442. self.Menu:SetVisible(false)
  443.  
  444. self.Menu.ChkDmgSelf = vgui.Create("DCheckBoxLabel", self.Menu)
  445. self.Menu.ChkDmgSelf:SetPos(16,32)
  446. self.Menu.ChkDmgSelf:SetText("Damage owner")
  447. self.Menu.ChkDmgSelf:SetTooltip("If unchecked, the missile will not inflict damage or kill its owner.")
  448. self.Menu.ChkDmgSelf:SizeToContents()
  449.  
  450. self.Menu.ChkDmgFriend = vgui.Create("DCheckBoxLabel", self.Menu)
  451. self.Menu.ChkDmgFriend:SetPos(16,64)
  452. self.Menu.ChkDmgFriend:SetText("Friendly fire")
  453. self.Menu.ChkDmgFriend:SetTooltip("If checked, friendly NPCs will receive damage from the missiles and eventually die.")
  454. self.Menu.ChkDmgFriend:SizeToContents()
  455.  
  456. self.Menu.BtnSave = vgui.Create("DButton", self.Menu)
  457. self.Menu.BtnSave:SetText("Update settings")
  458. self.Menu.BtnSave:SetPos(16,96)
  459. self.Menu.BtnSave:SetSize(224,24)
  460. self.Menu.BtnSave.SWEP = self
  461. self.Menu.BtnSave.DoClick = function(button)
  462. RunConsoleCommand("ASM-Config",
  463. button.SWEP:EntIndex(),
  464. tostring(button.SWEP.Menu.ChkDmgSelf:GetChecked()),
  465. tostring(button.SWEP.Menu.ChkDmgFriend:GetChecked())
  466. )
  467. button.SWEP.Menu:SetVisible(false)
  468. end
  469. end
  470.  
  471. function SWEP:MenuOpen(tOpts)
  472. if not self.Menu then
  473. self:MenuCreate()
  474. end
  475. self.Menu.ChkDmgSelf:SetValue(tobool(tOpts[1]) or false)
  476. self.Menu.ChkDmgFriend:SetValue(tobool(tOpts[2]) or false)
  477. self.Menu:Center()
  478. self.Menu:SetVisible(true)
  479. self.Menu:MakePopup()
  480. end
  481.  
  482. function SWEP:UpdateStatus(status)
  483. local nLastStatus = self.Status
  484. self.Status = status
  485. if status == 0 then
  486. if (self.HtmlIcon) then self.HtmlIcon:SetVisible(true) end
  487. if nLastStatus == -1 then
  488. self:EmitSound(SndReady)
  489. self:EmitSound(SndReadyB)
  490. end
  491. else
  492. if (self.HtmlIcon) then self.HtmlIcon:SetVisible(false) end
  493. if status == 1 then
  494. self.Load = CurTime()+1.75
  495. elseif status == 2 then
  496. self:EmitSound(SndInbound)
  497. self.FadeCount = 0
  498. elseif status == 3 then
  499. self.FadeCount = 255
  500. elseif status == 4 then
  501. --cam.ApplyShake(LocalPlayer():GetActiveWeapon():GetNWEntity("Missile"):GetPos(),Angle(0,0,0),100)
  502. end
  503. end
  504. if self.Menu && status > 0 then
  505. self.Menu:SetVisible(false)
  506. end
  507. end
  508.  
  509. function SWEP:DrawInactiveHUD()
  510. if self.Status == 0 then
  511. draw.RoundedBoxEx(8,ScrW()-50,60,50,60,Color(224,224,224,255),true,false,true,false)
  512. draw.DrawText("Missile\nReady","HudHintTextLarge",ScrW()-4, 26,Color(224,224,224,255),TEXT_ALIGN_RIGHT)
  513. end
  514. end
  515.  
  516. function SWEP:CheckFriendly(ent)
  517. if ent == LocalPlayer() then return true end
  518. return false
  519. end
  520.  
  521. function SWEP:DrawHUD()
  522. if self.Status > 1 then
  523. local bNoMissile = false
  524. local eMissile = self:GetNWEntity("Missile")
  525. if (!IsValid(eMissile)) or (util.PointContents(eMissile:GetPos()) == CONTENTS_SOLID) then
  526. bNoMissile = true
  527. end
  528.  
  529. if self.Status == 2 then
  530. surface.SetDrawColor(0,0,0,self.FadeCount)
  531. surface.DrawRect(0,0,ScrW(),ScrH())
  532.  
  533. if(self.FadeCount < 255) then
  534. self.FadeCount=self.FadeCount+5
  535. end
  536. elseif self.Status > 4 or bNoMissile then
  537. surface.SetDrawColor(0,0,0,self.FadeCount)
  538. surface.DrawRect(0,0,ScrW(),ScrH())
  539.  
  540. if(self.FadeCount > 0) then
  541. self.FadeCount=self.FadeCount-5
  542. end
  543. elseif self.Status == 3 or self.Status == 4 then
  544. local col = {}
  545. col["$pp_colour_addr"] =0
  546. col["$pp_colour_addg"] = 0
  547. col["$pp_colour_addb"] = 0
  548. col["$pp_colour_brightness"] = 0.1
  549. col["$pp_colour_contrast"] = 1
  550. col["$pp_colour_colour"] = 0
  551. col["$pp_colour_mulr"] = 0
  552. col["$pp_colour_mulg"] = 0
  553. col["$pp_colour_mulb"] = 0
  554. DrawColorModify(col)
  555. DrawSharpen(1,2)
  556.  
  557. local h = ScrH()/2
  558. local w = ScrW()/2
  559. local ho = 2*h/3
  560.  
  561. surface.SetDrawColor(160,160,160,255)
  562. surface.DrawOutlinedRect(w-48,h-32,96,64)
  563.  
  564. surface.DrawLine(w, h-32, w, h-128)
  565. surface.DrawLine(w, h+32, w, h+128)
  566. surface.DrawLine(w-48, h, w-144, h)
  567. surface.DrawLine(w+48, h, w+144, h)
  568.  
  569. surface.DrawLine(w-ho, h-ho+64, w-ho, h-ho)
  570. surface.DrawLine(w-ho, h-ho, w-ho+64, h-ho)
  571. surface.DrawLine(w+ho-64, h-ho, w+ho, h-ho)
  572. surface.DrawLine(w+ho, h-ho, w+ho, h-ho+64)
  573. surface.DrawLine(w+ho, h+ho-64, w+ho, h+ho)
  574. surface.DrawLine(w+ho, h+ho, w+ho-64, h+ho)
  575. surface.DrawLine(w-ho+64, h+ho, w-ho, h+ho)
  576. surface.DrawLine(w-ho, h+ho, w-ho, h+ho-64)
  577.  
  578. local pos = eMissile:GetPos()
  579. surface.SetFont("AsmCamFont")
  580. surface.SetTextColor(64,64,64,255)
  581.  
  582. surface.SetTextPos(24,16)
  583. surface.DrawText(tostring(math.Round(pos.x)).." "..tostring(math.Round(pos.y)).." "..tostring(math.Round(pos.z)))
  584.  
  585. surface.SetTextPos(24,40)
  586. local dist = self.Owner:GetEyeTrace().HitPos:Distance(pos-Vector(0,0,eMissile:OBBMaxs().z))
  587. surface.DrawText(tostring(math.Round(dist)).." : "..tostring(math.Round(eMissile:GetVelocity():Length())))
  588.  
  589. surface.SetTextPos(24,64)
  590. surface.DrawText("5 295 ["..math.Round(CurTime()).."]")
  591.  
  592. local tEnts = ents.GetAll()
  593. for _,ent in pairs(tEnts) do
  594. if(ent:IsPlayer() or ent:IsNPC()) then
  595. local vPos = ent:GetPos()+Vector(0,0,0.5*ent:OBBMaxs().z)
  596. local scrPos = vPos:ToScreen()
  597. if self:CheckFriendly(ent) then
  598. surface.SetDrawColor(64,255,64,160)
  599. surface.DrawLine(scrPos.x-16,scrPos.y-16,scrPos.x+16,scrPos.y+16)
  600. surface.DrawLine(scrPos.x-16,scrPos.y+16,scrPos.x+16,scrPos.y-16)
  601. else
  602. surface.SetDrawColor(255,64,64,160)
  603. end
  604. surface.DrawOutlinedRect(scrPos.x-16, scrPos.y-16,32,32)
  605. end
  606. end
  607. end
  608. end
  609. --surface.SetMaterial(matMissileAvailable)
  610. --surface.SetDrawColor(255,255,255,255)
  611. --surface.DrawTexturedRect(32, 32, 512, 512)
  612. end
  613.  
  614. local GlowMat = CreateMaterial("AsmLedGlow","UnlitGeneric",{
  615. ["$basetexture"] = "sprites/light_glow01",
  616. ["$vertexcolor"] = "1",
  617. ["$vertexalpha"] = "1",
  618. ["$additive"] = "1",
  619. })
  620.  
  621. function SWEP:GetViewModelPosition(pos,ang)
  622. if self:GetModel() == "models/weapons/v_toolgun.mdl" then
  623. local offset = Vector(-6,5.6,0)
  624. offset:Rotate(ang)
  625. pos = pos + offset
  626. end
  627. return pos,ang
  628. end
  629.  
  630. function SWEP:ViewModelDrawn()
  631. if (self.Status ~= 3) && (self.Status ~= 4) then
  632. local ent = self.Owner:GetViewModel()
  633. local pos,ang,offset,res,height,z
  634. if ent:GetModel() == "models/weapons/v_c4.mdl" then
  635. pos,ang = ent:GetBonePosition(ent:LookupBone("v_weapon.c4"))
  636. if self.Status == 0 then
  637. offset = Vector(-1.6,2.8,-0.25)
  638. offset:Rotate(ang)
  639. render.SetMaterial(GlowMat)
  640. render.DrawQuadEasy(pos+offset,ang:Right() * -1,1.5,1.5,Color(255,128,128,255))
  641. end
  642. offset = Vector(-1.8,2.7,1.4)
  643. offset:Rotate(ang)
  644. ang:RotateAroundAxis(ang:Forward(),-90)
  645. ang:RotateAroundAxis(ang:Up(),180)
  646. res = 0.03
  647. height = 53
  648. z = 16
  649. else
  650. offset = Vector(1.04,2.8,-0.1)
  651. offset:Rotate(ang)
  652. ang:RotateAroundAxis(ang:Forward(),43.86)
  653. ang:RotateAroundAxis(ang:Up(),1)
  654. ang:RotateAroundAxis(ang:Right(),180)
  655. res = 0.0234
  656. height = 94
  657. z = 32
  658. end
  659. pos = pos + offset
  660. cam.Start3D2D(pos,ang,res)
  661. surface.SetDrawColor(4,32,4,255)
  662. surface.DrawRect(0,0,96,height)
  663. if self.Status == -1 then
  664. draw.SimpleText("Missiles","AsmScreenFont",48,z,Color(80,192,64,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
  665. draw.SimpleText("unavailable","AsmScreenFont",48,z+16,Color(80,192,64,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
  666. elseif self.Status == 0 then
  667. draw.SimpleText("Waiting for","AsmScreenFont",48,z,Color(80,192,64,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
  668. draw.SimpleText("target...","AsmScreenFont",48,z+16,Color(80,192,64,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
  669. elseif self.Status == 1 then
  670. draw.SimpleText("Requesting...","AsmScreenFont",48,z,Color(80,192,64,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
  671. surface.SetDrawColor(80,192,64,255)
  672. surface.DrawOutlinedRect(11,z+15,74,10)
  673. surface.SetDrawColor(112,224,96,255)
  674. surface.DrawRect(12,z+16,72*(1-((self.Load-CurTime())/1.75)),8)
  675. else
  676. draw.SimpleText("Inbound","AsmScreenFont",48,z+8,Color(80,192,64,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
  677. end
  678. //surface.SetTexture(texScreenOverlay)
  679. //surface.DrawTexturedRectUV(0,0,96,height,96,height)
  680. cam.End3D2D()
  681. end
  682. end
  683.  
  684. function SWEP:FreezeMovement()
  685. if (self.Status > 0) && (self.Status ~= 5) then
  686. return true
  687. end
  688. return false
  689. end
  690.  
  691. function SWEP:HUDShouldDraw(el)
  692. if(self.Status > 2 && self.Status < 7) then
  693. if (el=="CHudGMod") then return true end
  694. return false
  695. end
  696. return true
  697. end
  698.  
  699. -- Explosion effect
  700.  
  701. local EFFECT = {}
  702. function EFFECT:Init(data)
  703. self.Pos = data:GetOrigin()
  704. self.Radius = data:GetRadius()
  705.  
  706. sound.Play("ambient/explosions/explode_4.wav", self.Pos, 100, 140, 1)
  707. sound.Play("npc/env_headcrabcanister/explosion.wav", self.Pos, 100, 140, 1)
  708.  
  709. local em = ParticleEmitter(self.Pos)
  710. for n=1,180 do
  711. local wave = em:Add("particle/particle_noisesphere",self.Pos)
  712. wave:SetVelocity(Vector(math.sin(math.rad(n*2)),math.cos(math.rad(n*2)),0)*self.Radius*3)
  713. wave:SetAirResistance(128)
  714. wave:SetLifeTime(math.random(0.2,0.4))
  715. wave:SetDieTime(math.random(3,4))
  716. wave:SetStartSize(64)
  717. wave:SetEndSize(48)
  718. wave:SetColor(160,160,160)
  719. wave:SetRollDelta(math.random(-1,1))
  720. local fire = em:Add("effects/fire_cloud1",self.Pos+VectorRand()*self.Radius/2)
  721. fire:SetVelocity(Vector(math.random(-8,8),math.random(-8,8),math.random(8,16)):GetNormal()*math.random(128,1024))
  722. fire:SetAirResistance(256)
  723. fire:SetLifeTime(math.random(0.2,0.4))
  724. fire:SetDieTime(math.random(2,3))
  725. fire:SetStartSize(80)
  726. fire:SetEndSize(32)
  727. fire:SetColor(160,64,64,192)
  728. fire:SetRollDelta(math.random(-1,1))
  729. end
  730. for n=1,16 do
  731. local smoke = em:Add("particle/particle_noisesphere", self.Pos+48*VectorRand()*n)
  732. smoke:SetVelocity(VectorRand()*math.Rand(32,96))
  733. smoke:SetAirResistance(32)
  734. smoke:SetDieTime(8)
  735. smoke:SetStartSize((32-n)*2*math.Rand(8,16))
  736. smoke:SetEndSize((32-n)*math.Rand(8,16))
  737. smoke:SetColor(160,160,160)
  738. smoke:SetStartAlpha(math.Rand(224,255))
  739. smoke:SetEndAlpha(0)
  740. smoke:SetRollDelta(math.random(-1,1))
  741. end
  742. em:Finish()
  743. end
  744.  
  745. function EFFECT:Think() return false end
  746. function EFFECT:Render() end
  747.  
  748. effects.Register(EFFECT,"ASM-Explosion")
  749. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement