Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.85 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. SWEP.PrintName = "Magic Wand Rewrite"
  4. SWEP.Category = "Harry Potter"
  5. SWEP.Purpose = ""
  6.  
  7. SWEP.Weight = 5
  8.  
  9. SWEP.Spawnable = true
  10. SWEP.UseHands = true
  11. SWEP.DrawAmmo = false
  12.  
  13. SWEP.ViewModelFOV = 56
  14. SWEP.Slot = 2
  15. SWEP.SlotPos = 5
  16.  
  17. SWEP.Primary.ClipSize = -1
  18. SWEP.Primary.DefaultClip = -1
  19. SWEP.Primary.Automatic = false
  20. SWEP.Primary.Ammo = "none"
  21.  
  22. SWEP.Secondary.ClipSize = -1
  23. SWEP.Secondary.DefaultClip = -1
  24. SWEP.Secondary.Automatic = false
  25. SWEP.Secondary.Ammo = "none"
  26.  
  27. SWEP.ViewModel = Model("models/hpwrewrite/c_magicwand.mdl")
  28. SWEP.WorldModel = Model("models/hpwrewrite/w_magicwand.mdl")
  29.  
  30. SWEP.BobScale = 0.26
  31. SWEP.SwayScale = 0.8
  32.  
  33. AccessorFunc(SWEP, "m_hpw_accuracy_penalty", "HPWAccuracyPenalty", FORCE_NUMBER)
  34.  
  35. --local setup = CreateConVar("hpwrewrite_setup", "0", { FCVAR_ARCHIVE, FCVAR_PROTECTED, FCVAR_REPLICATED })
  36.  
  37. if CLIENT then
  38. killicon.Add("weapon_hpwr_stick", "hpwrewrite/killicon", Color(255, 80, 0, 255))
  39.  
  40. hook.Add("OnContextMenuOpen", "hpwrewrite_wand_handler_open", function()
  41. local self = LocalPlayer():GetActiveWeapon()
  42. if HpwRewrite.IsValidWand(self) then
  43. self.HpwRewrite.ShouldSetPos = true
  44. self.HpwRewrite.Select = true
  45. end
  46. end)
  47.  
  48. hook.Add("OnContextMenuClose", "hpwrewrite_wand_handler_close", function()
  49. local self = LocalPlayer():GetActiveWeapon()
  50. if HpwRewrite.IsValidWand(self) then
  51. self.HpwRewrite.Select = false
  52. end
  53. end)
  54.  
  55. --[[net.Receive("hpwrewrite_setup", function(len)
  56. if not HpwRewrite.CheckAdmin(ply) or not ply:IsSuperAdmin() or setup:GetBool() then return end
  57.  
  58. local time = SysTime()
  59. local win = HpwRewrite.VGUI:CreateWindow(800, 425)
  60.  
  61. local alpha = 0
  62. win.Paint = function(self, w, h)
  63. Derma_DrawBackgroundBlur(self, time)
  64.  
  65. alpha = math.Approach(alpha, 150, RealFrameTime() * 60)
  66. local col = Color(255, 255, 255, alpha)
  67. draw.RoundedBox(0, 0, 0, ScrW(), ScrH(), col)
  68. end
  69.  
  70. win.PaintOver = function() end
  71.  
  72. local lab = HpwRewrite.VGUI:CreateLabel("Should we enable spell learning?", nil, nil, win)
  73. lab:SetFont("HPW_guibiggest")
  74. lab:Dock(TOP)
  75. lab:InvalidateParent(true)
  76. lab:SetColor(HpwRewrite.Colors.DarkGrey2)
  77. lab:SetContentAlignment(5)
  78. lab:SizeToContents()
  79.  
  80. local yes = HpwRewrite.VGUI:CreateButton("Yes!", 85, 155, 300, 200, win, function()
  81. net.Start("hpwrewrite_setup")
  82. net.WriteBit(false)
  83. net.SendToServer()
  84.  
  85. win:Close()
  86. end)
  87. yes.MainColor = Color(50, 160, 50)
  88. yes.EnterColor = Color(50, 200, 50)
  89. yes:SetFont("HPW_guibiggest")
  90.  
  91. local no = HpwRewrite.VGUI:CreateButton("No!", 410, 155, 300, 200, win, function()
  92. net.Start("hpwrewrite_setup")
  93. net.WriteBit(true)
  94. net.SendToServer()
  95.  
  96. win:Close()
  97. end)
  98. no.MainColor = Color(160, 50, 50)
  99. no.EnterColor = Color(200, 50, 50)
  100.  
  101. no:SetFont("HPW_guibiggest")
  102. end)]]
  103.  
  104. function SWEP:AdjustMouseSensitivity()
  105. if HpwRewrite.FM:GetValue(self.Owner) then return 0.3 end
  106. end
  107.  
  108. SWEP.WepSelectIcon = surface.GetTextureID("vgui/hpwrewrite/selection/wep_sel")
  109. function SWEP:DrawWeaponSelection(x, y, wide, tall, alpha)
  110. x = x + wide / 2
  111. y = y + tall / 2
  112.  
  113. tall = tall * 0.75
  114.  
  115. x = x - tall / 2
  116. y = y - tall / 2 - 10
  117.  
  118. surface.SetDrawColor(255, 255, 255, alpha)
  119. surface.SetTexture(self.WepSelectIcon)
  120.  
  121. surface.DrawTexturedRect(x, y, tall, tall)
  122. end
  123.  
  124. function SWEP:FirstCellPos()
  125. return ScrW() / 2 - 305 + HpwRewrite.CVars.XOffset:GetInt(), ScrH() - 130 + HpwRewrite.CVars.YOffset:GetInt()
  126. end
  127.  
  128. local cellSize = 68
  129.  
  130. function SWEP:GetCellPosition(index)
  131. local x, y = self:FirstCellPos()
  132. return x + (index - 1) * cellSize + 32, y + 32
  133. end
  134.  
  135. function SWEP:CalculateCellOffset()
  136. local mx, my = input.GetCursorPos()
  137. local x, y = self:FirstCellPos()
  138.  
  139. local st1 = (my - y) / cellSize
  140. local st2 = (mx - x) / cellSize
  141.  
  142. if st2 > 9 or st2 < 0 then return 0 end
  143. if st1 > 1 or st1 < 0 then return 0 end
  144.  
  145. return math.Clamp(math.floor(st2) + 1, 1, 9)
  146. end
  147.  
  148. local glow = Material("hpwrewrite/sprites/magicsprite")
  149. function SWEP:DrawSpriteStuff(vm)
  150. local obj = vm:LookupBone("spritemagic")
  151. local pos = self.Owner:EyePos()
  152. local val = 1
  153.  
  154. local curskin = HpwRewrite:GetPlayerSkin(self.Owner, self:GetWandCurrentSkin())
  155. if curskin then curskin:DrawMagicSprite(self, vm, obj) end
  156.  
  157. if self.HpwRewrite.SpriteAlpha > 0 then
  158. local curspell = HpwRewrite:GetPlayerSpell(self.Owner, self:GetWandCurrentSpell())
  159. if curspell and curspell.Name == self.HpwRewrite.LastAttackerSpellName then curspell:DrawMagicSprite(self, vm, obj) end
  160.  
  161. self.HpwRewrite.SpriteAlpha = math.Approach(self.HpwRewrite.SpriteAlpha, 0, FrameTime() * self.HpwRewrite.SpriteTime)
  162. else
  163. return
  164. end
  165.  
  166. if obj then
  167. local m = vm:GetBoneMatrix(obj)
  168. if m then
  169. pos = m:GetTranslation()
  170.  
  171. if curskin and curskin.AdjustSpritePosition then
  172. pos = pos + curskin:AdjustSpritePosition(vm, m, curspell)
  173. end
  174.  
  175. val = self.HpwRewrite.SpriteColor.a / 255
  176.  
  177. self.HpwRewrite.SpriteColor.a = Lerp(FrameTime() * 16, self.HpwRewrite.SpriteColor.a, self.HpwRewrite.SpriteAlpha)
  178.  
  179. render.SetMaterial(glow)
  180. local white = Color(255, 255, 255, self.HpwRewrite.SpriteColor.a)
  181. local sin = math.sin(CurTime() * 24) * 0.3
  182.  
  183. for i = 1, 8 do
  184. local size = (i * 3 * val + sin) * self.HpwRewrite.SpriteSize
  185. render.DrawSprite(pos, size, size, self.HpwRewrite.SpriteColor)
  186. render.DrawSprite(pos, 7 * val * self.HpwRewrite.SpriteSize, 7 * val * self.HpwRewrite.SpriteSize, white)
  187. end
  188. end
  189. end
  190.  
  191. local dlight = DynamicLight(vm:EntIndex())
  192. if dlight then
  193. dlight.pos = pos + Vector(3, 0, 0) -- Moved a bit to solve light inside wand bug
  194. dlight.r = self.HpwRewrite.SpriteColor.r
  195. dlight.g = self.HpwRewrite.SpriteColor.g
  196. dlight.b = self.HpwRewrite.SpriteColor.b
  197. dlight.brightness = 2
  198. dlight.Decay = 1000
  199. dlight.Style = 5
  200. dlight.Size = 160 * val
  201. dlight.DieTime = CurTime() + 0.1
  202. end
  203. end
  204.  
  205. -- Better than DrawWorldModel
  206. -- TODO: fix wand:DrawModel()
  207.  
  208. --[[hook.Add("PostDrawOpaqueRenderables", "hpwrewrite_weapon_spritedrawing_handler", function()
  209. for k, v in pairs(ents.FindByClass(HpwRewrite.WandClass)) do
  210. if not v:GetNoDraw() then
  211. v:DrawModel()
  212.  
  213. if IsValid(v.Owner) then
  214. v:DrawSpriteStuff(v)
  215.  
  216. local curskin = HpwRewrite:GetPlayerSkin(v.Owner, v:GetWandCurrentSkin())
  217. if curskin then curskin:DrawWorldModel(v) end
  218.  
  219. local curspell = HpwRewrite:GetPlayerSpell(v.Owner, v:GetWandCurrentSpell())
  220. if curspell then curspell:DrawWorldModel(v) end
  221. end
  222. end
  223. end
  224. end)]]
  225.  
  226. -- TODO: Leave it empty
  227. function SWEP:DrawWorldModel()
  228. self:DrawModel()
  229.  
  230. if IsValid(self.Owner) then
  231. self:DrawSpriteStuff(self)
  232.  
  233. local curskin = HpwRewrite:GetPlayerSkin(self.Owner, self:GetWandCurrentSkin())
  234. if curskin then curskin:DrawWorldModel(self) end
  235.  
  236. local curspell = HpwRewrite:GetPlayerSpell(self.Owner, self:GetWandCurrentSpell())
  237. if curspell then curspell:DrawWorldModel(self) end
  238. end
  239. end
  240.  
  241. function SWEP:PostDrawViewModel(vm, wep, ply)
  242. local curskin = HpwRewrite:GetPlayerSkin(self.Owner, self:GetWandCurrentSkin())
  243. if curskin then curskin:PostDrawViewModel(self, vm) end
  244.  
  245. local curspell = HpwRewrite:GetPlayerSpell(self.Owner, self:GetWandCurrentSpell())
  246. if curspell then curspell:PostDrawViewModel(self, vm) end
  247.  
  248. cam.IgnoreZ(true)
  249. self:DrawSpriteStuff(vm)
  250. cam.IgnoreZ(false)
  251. end
  252.  
  253. local spellbar = Material("vgui/hpwrewrite/spellbar")
  254. local leftBar = Material("vgui/hpwrewrite/leftbar")
  255. local leftBarEmpty = Material("vgui/hpwrewrite/leftbarempty")
  256. local gradient = Material("vgui/gradient_up")
  257. local centerGradient = Material("gui/center_gradient")
  258. local waitBeforeHide = 0
  259.  
  260. local hintMenu = HpwRewrite.Language:GetWord("#menu_hint")
  261. local treeWord = HpwRewrite.Language:GetWord("#spelltreeword")
  262. local curSpellWord = HpwRewrite.Language:GetWord("#curspell")
  263. local quickBarHint = HpwRewrite.Language:GetWord("#quick_bar_hint")
  264.  
  265. function SWEP:DrawHUD()
  266. if HpwRewrite.CVars.NoHud:GetBool() then return end
  267.  
  268. -- Spells
  269. if HpwRewrite.CVars.DrawSpellBar:GetBool() then
  270. local x, y = self:FirstCellPos()
  271.  
  272. for i = 1, 9 do
  273. local x = x + (i - 1) * cellSize
  274. local w, h = 64, 64
  275. local bind = HpwRewrite.BM.Binds[i]
  276.  
  277. local spell, key
  278.  
  279. if bind then
  280. spell = bind.Spell
  281. key = bind.Key
  282. end
  283.  
  284. HpwRewrite:DrawSpellRect(spell, key, x, y, w, h)
  285. end
  286. end
  287.  
  288. local xoffset = HpwRewrite.CVars.XOffset:GetInt()
  289. local yoffset = HpwRewrite.CVars.YOffset:GetInt()
  290.  
  291. local x = ScrW() / 2 - 305 + xoffset
  292. local y = ScrH() - 62 + yoffset
  293.  
  294. local mmorpg = HpwRewrite.CVars.MmorpgStyle:GetBool()
  295.  
  296. -- Spellbar
  297. if HpwRewrite.CVars.DrawCurrentSpell:GetBool() then
  298. if mmorpg then
  299. surface.SetMaterial(spellbar)
  300. surface.SetDrawColor(Color(255, 255, 255, 255))
  301. surface.DrawTexturedRect(x - 3, y - 75, 616, 220)
  302. else
  303. draw.RoundedBox(0, x, y, 608, 70, Color(0, 0, 0, 150))
  304. end
  305.  
  306.  
  307. local spellName = self:GetWandCurrentSpell()
  308. if spellName == "" then spellName = "None" end
  309.  
  310. local text = curSpellWord .. spellName
  311. draw.SimpleText(text, "HPW_font2", x + 17, y + 13, HpwRewrite.Colors.Black, TEXT_ALIGN_LEFT)
  312. draw.SimpleText(text, "HPW_font2", x + 16, y + 12, HpwRewrite.Colors.White, TEXT_ALIGN_LEFT)
  313. end
  314.  
  315. if self.HpwRewrite.PrintHelp and HpwRewrite.CVars.DrawHint:GetBool() and not self.HpwRewrite.Select then
  316. draw.SimpleText(Format(hintMenu, HpwRewrite.BM.Keys[HpwRewrite.CVars.MenuKey:GetInt()] or "NONE"), "HPW_font3", x + 305, y - 108, Color(255, 255, 255, 150 + math.sin(CurTime() * 4) * 100), TEXT_ALIGN_CENTER)
  317. elseif self.HpwRewrite.Select then
  318. draw.SimpleText(treeWord .. HpwRewrite.BM.CurTree, "HPW_font3", x + 305, y - 108, Color(255, 255, 255, 150 + math.sin(CurTime() * 4) * 100), TEXT_ALIGN_CENTER)
  319. end
  320.  
  321. if self.HpwRewrite.Select and HpwRewrite.CVars.DrawSelHint:GetBool() then
  322. draw.SimpleText(quickBarHint, "HPW_font3", ScrW() / 2, 64, Color(255, 255, 255, 200 + math.sin(CurTime() * 4) * 55), TEXT_ALIGN_CENTER)
  323. end
  324.  
  325. -- Left side accuracy bar
  326. local accVal = self:GetHPWAccuracyValue()
  327.  
  328. if waitBeforeHide and accVal > 0 then
  329. waitBeforeHide = nil
  330. elseif not waitBeforeHide then
  331. waitBeforeHide = CurTime() + 1.5
  332. end
  333.  
  334. if accVal > 0 or (waitBeforeHide and CurTime() < waitBeforeHide) then
  335. local mainH = 147
  336.  
  337. local length = math.floor(accVal * mainH)
  338. local w = ScrW()
  339. local h = ScrH()
  340.  
  341. local colVal = accVal * 255
  342.  
  343. if mmorpg then
  344. local x = x - 30
  345. local y = y - mainH / 2 + 1
  346. local color = Color(colVal, 255 - colVal, 0, 255 - colVal)
  347.  
  348. surface.SetDrawColor(HpwRewrite.Colors.White)
  349. surface.SetMaterial(leftBar)
  350. surface.DrawTexturedRect(x, y, 30, mainH)
  351.  
  352. draw.RoundedBox(0, x + 4, y + length + 10, 20, mainH - 16 - length, color)
  353.  
  354. surface.SetMaterial(gradient)
  355. surface.DrawTexturedRect(x + 4, y + length + 5, 20, 6)
  356.  
  357. surface.SetDrawColor(HpwRewrite.Colors.White)
  358. surface.SetMaterial(leftBarEmpty)
  359. surface.DrawTexturedRect(x, y, 30, mainH)
  360.  
  361. if accVal > 0.6 then
  362. surface.SetDrawColor(Color(255, 0, 0, 90 + math.sin(CurTime() * 16) * 80))
  363. surface.SetMaterial(centerGradient)
  364. surface.DrawTexturedRect(x, y, 30, mainH)
  365. end
  366. else
  367. local x = x - 24
  368. local y = y - mainH / 2 + 5
  369. local color = Color(colVal, 255 - colVal, 0, 255 - colVal)
  370.  
  371. draw.RoundedBox(0, x, y, 20, mainH - 9, Color(0, 0, 0, 200))
  372. draw.RoundedBox(0, x, y + length, 20, mainH - 9 - length, color)
  373.  
  374. if accVal > 0.6 then
  375. draw.RoundedBox(0, x, y, 20, mainH, Color(255, 0, 0, 90 + math.sin(CurTime() * 16) * 80))
  376. end
  377. end
  378. end
  379. end
  380.  
  381. -- Wand net system is too big
  382. net.Receive("HpwRewriteSpriteSend", function(len)
  383. local stuff = tobool(net.ReadBit())
  384. local wep = net.ReadEntity()
  385.  
  386. if not wep:IsValid() then return end
  387. if not wep.HpwRewrite then HpwRewrite:LogDebug("Wand table doesn't exist!") return end
  388.  
  389. -- if the server knows that player used the same spell as before we won't receive anymore data (Saving a lot of bits)
  390. if stuff then
  391. wep.HpwRewrite.SpriteAlpha = 255
  392. return
  393. end
  394.  
  395. -- Other data
  396. local r = net.ReadUInt(8)
  397. local g = net.ReadUInt(8)
  398. local b = net.ReadUInt(8)
  399. local time = net.ReadUInt(11)
  400. local size = net.ReadFloat()
  401. local name = net.ReadString()
  402.  
  403. wep.HpwRewrite.SpriteAlpha = 255
  404. wep.HpwRewrite.SpriteColor = Color(r, g, b, (wep.HpwRewrite.SpriteColor.a))
  405. wep.HpwRewrite.SpriteTime = time
  406. wep.HpwRewrite.SpriteSize = size
  407. wep.HpwRewrite.LastAttackerSpellName = name
  408. end)
  409. else
  410. util.AddNetworkString("HpwRewriteSpriteSend")
  411.  
  412. --[[util.AddNetworkString("hpwrewrite_setup")
  413.  
  414. net.Receive("hpwrewrite_setup", function(len, ply)
  415. if not HpwRewrite.CheckAdmin(ply) or not ply:IsSuperAdmin() then return end
  416.  
  417. local val = tostring(net.ReadBit())
  418. if val != "0" and val != "1" then print("Wrong argument! Expected", "1/0", "Got", val) return end
  419.  
  420. RunConsoleCommand("hpwrewrite_sv_nolearning", val)
  421. RunConsoleCommand("hpwrewrite_setup", "1")
  422. end)]]
  423. function SWEP:HPWDecreaseAccuracy(amount)
  424. -- 0 accuracy is the best one
  425. if not self.HpwRewrite.Accuracy then self.HpwRewrite.Accuracy = 0 end
  426.  
  427. if not HpwRewrite.CVars.NoAccuracy:GetBool() then
  428. if self.GetHPWAccuracyPenalty then amount = amount * self:GetHPWAccuracyPenalty() end -- useless if
  429.  
  430. self.HpwRewrite.Accuracy = math.Approach(self.HpwRewrite.Accuracy, 1, amount)
  431. self.HpwRewrite.CooldownAccuracy = CurTime() + 1.2
  432. end
  433. end
  434. function SWEP:ApplyAccuracyPenalty(vec)
  435. -- TODO: check if its quite optimized
  436. --vec:Rotate(AngleRand() * (self.HpwRewrite.Accuracy or 0) * 0.06)
  437. end
  438. function SWEP:RequestSprite(name, col, time, size, forcedata)
  439. if self.HpwRewrite.BlockSprite then return end
  440. size = size or 1
  441.  
  442. local noData = name == self.HpwRewrite.LastAttackerSpellName
  443. if forcedata then noData = false end
  444.  
  445. net.Start("HpwRewriteSpriteSend")
  446. net.WriteBit(noData)
  447. net.WriteEntity(self)
  448.  
  449. if not noData then
  450. net.WriteUInt(col.r, 8)
  451. net.WriteUInt(col.g, 8)
  452. net.WriteUInt(col.b, 8)
  453. net.WriteUInt(time, 11)
  454. net.WriteFloat(size)
  455. net.WriteString(name)
  456. end
  457. net.Broadcast()
  458.  
  459. self.HpwRewrite.LastAttackerSpellName = name
  460. end
  461.  
  462. function SWEP:UpdateClientsideSkin(ply)
  463. net.Start("hpwrewrite_vm_wm")
  464. net.WriteEntity(self)
  465. net.WriteString(self.ViewModel)
  466. net.WriteString(self.WorldModel)
  467. if IsValid(ply) then
  468. net.Send(ply)
  469. else
  470. net.Broadcast()
  471. end
  472. end
  473.  
  474. function SWEP:HPWSetWandSkin(name)
  475. local wep = self.Owner:GetActiveWeapon()
  476. if wep != self then HpwRewrite:LogDebug(self.Owner:Name() .. "'s weapon isn't wand, cannot change skin!") return end
  477.  
  478. local isDefSkin = false
  479.  
  480. -- Skip checking and giving skin if name is DefaultSkin
  481. if name == HpwRewrite.DefaultSkin then
  482. HpwRewrite:PlayerGiveSpell(self.Owner, HpwRewrite.DefaultSkin, nil, true)
  483. isDefSkin = true
  484. else
  485. if not HpwRewrite:CanUseSpell(self.Owner, name) then
  486. if self:GetWandCurrentSkin() == name then self:HPWSetWandSkin(HpwRewrite.DefaultSkin) end
  487. return
  488. end
  489. end
  490.  
  491. local oldskin = self:GetWandCurrentSkin()
  492. local skin = HpwRewrite:GetPlayerSkin(self.Owner, name)
  493. if not skin then print(name .. " does not exist!") return end
  494.  
  495. HpwRewrite:LogDebug(self.Owner:Name() .. " changing skin to " .. name)
  496.  
  497. if not skin:PreSkinSelect(self) then
  498. HpwRewrite:LogDebug(self.Owner:Name() .. " attempted to change his skin to " .. name)
  499. if not isDefSkin then return end
  500. end
  501.  
  502. self:Holster(nil, true)
  503. self:SetHoldType(skin.HoldType)
  504.  
  505. local vm = skin.ViewModel
  506. local wm = skin.WorldModel
  507.  
  508. self.ViewModel = vm
  509. self.WorldModel = wm
  510.  
  511. self.Owner:GetViewModel():SetWeaponModel(vm, self)
  512. self:SetWandCurrentSkin(name)
  513.  
  514. self:UpdateClientsideSkin()
  515. self:Deploy(true)
  516.  
  517. skin:OnSkinSelect(self)
  518.  
  519. oldskin = HpwRewrite:GetPlayerSkin(self.Owner, oldskin)
  520. if oldskin then oldskin:OnSkinHolster(self) end
  521.  
  522. self:CheckSpellUseable(self:GetWandCurrentSpell())
  523.  
  524. -- Notifying those people who has problems with models from .gma
  525. -- It should help them
  526. if game.SinglePlayer() and not HpwRewrite.CVars.ErrorNotify:GetBool() and not util.IsValidModel(skin.ViewModel) then
  527. HpwRewrite:DoNotify(self.Owner, "Seems like the wand addon was not installed correctly! Try to deinstall and install it then restart the game several times.", 1, 14)
  528. RunConsoleCommand("hpwrewrite_sv_error_notify", "1")
  529. end
  530.  
  531. return true
  532. end
  533.  
  534. function SWEP:HPWSetCurrentSpell(name)
  535. local oldspellname = self:GetWandCurrentSpell()
  536.  
  537. if not HpwRewrite:CanUseSpell(self.Owner, name) then
  538. if name == oldspellname then self:HPWRemoveCurSpell() end
  539. HpwRewrite:LogDebug(self.Owner:Name() .. " attempted to change his spell to " .. name)
  540. return
  541. end
  542.  
  543. if name == oldspellname then return true end -- true
  544.  
  545. local oldspell = HpwRewrite:GetPlayerSpell(self.Owner, oldspellname)
  546. local newspell = HpwRewrite:GetPlayerSpell(self.Owner, name)
  547.  
  548. if not newspell:OnSelect(self) then
  549. HpwRewrite:LogDebug(self.Owner:Name() .. " attempted to change his spell to " .. name)
  550. return
  551. end
  552.  
  553. self.Primary.Automatic = false
  554. if newspell.AutoFire then
  555. self.Primary.Automatic = true
  556. end
  557.  
  558. if oldspell then oldspell:OnHolster(self) end
  559.  
  560. self:SetWandCurrentSpell(name)
  561. HpwRewrite:LogDebug(self.Owner:Name() .. " changed spell to " .. name)
  562.  
  563. return true
  564. end
  565.  
  566. function SWEP:HPWRemoveCurSpell()
  567. local oldspell = HpwRewrite:GetPlayerSpell(self.Owner, self:GetWandCurrentSpell())
  568. if oldspell then oldspell:OnHolster(self) end
  569.  
  570. self.Primary.Automatic = false
  571. self:SetWandCurrentSpell("")
  572. end
  573.  
  574. function SWEP:HPWGetAimEntity(distance, mins, maxs)
  575. distance = distance or 1000
  576.  
  577. local ply = self.Owner
  578.  
  579. local tr
  580. local pos1 = ply:GetShootPos()
  581. local pos2 = ply:GetShootPos() + ply:GetAimVector() * distance
  582.  
  583. if mins and maxs then
  584. tr = util.TraceHull({
  585. start = pos1,
  586. endpos = pos2,
  587. filter = ply,
  588. mins = mins,
  589. maxs = maxs
  590. })
  591. else
  592. tr = util.TraceLine({
  593. start = pos1,
  594. endpos = pos2,
  595. filter = ply
  596. })
  597. end
  598.  
  599. if self.HoldingSelfCast then return ply, tr end
  600. return tr.Entity, tr
  601. end
  602.  
  603.  
  604.  
  605. function SWEP:HPWSpawnSpell(curspell)
  606. local pos = self:GetSpellSpawnPosition()
  607. local dir = (self.Owner:GetEyeTrace().HitPos - pos):GetNormal()
  608.  
  609. self:ApplyAccuracyPenalty(dir)
  610.  
  611.  
  612. local ent = ents.Create("entity_hpwand_flyingspell")
  613. ent:SetPos(pos)
  614. ent:SetAngles(dir:Angle())
  615. ent:SetFlyDirection(dir)
  616. ent:SetSpellData(curspell)
  617. ent:SetupOwner(self.Owner)
  618. ent:Spawn()
  619.  
  620. curspell:OnSpellSpawned(self, ent)
  621.  
  622. if curspell.CanSelfCast and self.HoldingSelfCast then
  623. local data = { }
  624.  
  625. data.HitEntity = self.Owner
  626. data.HitPos = self.Owner:LocalToWorld(self.Owner:OBBCenter())
  627. data.Speed = 0
  628. data.HitNormal = Vector(0, 0, 0)
  629.  
  630. ent:PhysicsCollide(data, ent:GetPhysicsObject())
  631. end
  632.  
  633.  
  634. self.HoldingSelfCast = false
  635. end
  636.  
  637. function SWEP:HPWDoSprite(curspell)
  638. local col = curspell.SpriteColor
  639. if col then
  640. local force = false
  641. if curspell.ForceSpriteSending then force = true end
  642. self:RequestSprite(curspell.Name, col, curspell.SpriteTime or 600, curspell.SpriteSize, force)
  643. end
  644. end
  645.  
  646. function SWEP:HPWDoSpell(curspell)
  647. self:HPWSpawnSpell(curspell)
  648. self:HPWDoSprite(curspell)
  649. end
  650.  
  651. function SWEP:AnimationSpeedTimer(speed, seconds)
  652. if speed <= 0 then return end
  653.  
  654. self.HpwRewrite.AnimationSpeed = speed
  655.  
  656. timer.Create("hpwrewrite_adnimation_" .. self:EntIndex(), seconds, 1, function()
  657. if IsValid(self) then self.HpwRewrite.AnimationSpeed = 1 end
  658. end)
  659. end
  660.  
  661. function SWEP:CanContinue(curspell)
  662. return IsValid(self.Owner) and self == self.Owner:GetActiveWeapon() and curspell and HpwRewrite:CanUseSpell(self.Owner, curspell.Name)
  663. end
  664.  
  665. function SWEP:AttackSpell(curspell)
  666. if curspell:OnFire(self) then
  667. if curspell.UseClientsideOnFire then
  668. net.Start("hpwrewrite_ClientsidePrimaryAttack")
  669. net.WriteEntity(self)
  670. net.WriteUInt(curspell.UniqueID, 9) -- 2^9 = 512 will there be more than 512 spells?
  671. if curspell.ClientsideOnFireShouldBroadcast then
  672. net.Broadcast()
  673. else
  674. net.Send(self.Owner)
  675. end
  676. end
  677.  
  678. if curspell.ApplyDelay then
  679. timer.Simple(self:HPWSeqDuration2() * curspell.ApplyDelay, function()
  680. if IsValid(self) and self:CanContinue(curspell) then self:HPWDoSpell(curspell) end
  681. end)
  682. else
  683. self:HPWDoSpell(curspell)
  684. end
  685. else
  686. self:HPWDoSprite(curspell)
  687. self:HPWDecreaseAccuracy(curspell.AccuracyDecreaseVal) -- for spells without entity
  688. end
  689. end
  690.  
  691. -- TODO: add more sounds
  692. local sounds = {
  693. "hpwrewrite/wand/maincast.wav"
  694. }
  695.  
  696. function SWEP:PlayCastSound()
  697. local name = table.Random(sounds)
  698. local override = false
  699.  
  700. local skin = HpwRewrite:GetPlayerSkin(self.Owner, self:GetWandCurrentSkin())
  701. if skin then
  702. local cast
  703.  
  704. cast, override = skin:GetCastSound(self)
  705. if override then return end
  706.  
  707. if cast then name = cast end
  708. end
  709.  
  710. self:EmitSound(name, 70, math.random(95, 105), 1, CHAN_WEAPON)
  711. end
  712. end
  713.  
  714. function SWEP:SetupDataTables()
  715. self:NetworkVar("String", 0, "WandCurrentSpell")
  716. self:NetworkVar("String", 1, "WandCurrentSkin")
  717. self:NetworkVar("Float", 0, "WandNextIdle")
  718. self:NetworkVar("Float", 1, "HPWAccuracyValue") -- for clientside only
  719. end
  720.  
  721. function SWEP:GetSpellSpawnPosition()
  722. local ang = self.Owner:EyeAngles()
  723. local pos = self.Owner:EyePos() + ang:Right() * 2 + ang:Forward() * 16
  724.  
  725. if HpwRewrite.CVars.AlwaysCenter:GetBool() then
  726. pos = self.Owner:EyePos() + ang:Forward() * 10
  727. else
  728. local skin = HpwRewrite:GetPlayerSkin(self.Owner, self:GetWandCurrentSkin())
  729. if skin then
  730. pos = skin:GetSpellPosition(self, pos)
  731. end
  732. end
  733.  
  734. return pos
  735. end
  736.  
  737. function SWEP:CheckSpellUseable(name)
  738. if not HpwRewrite:CanUseSpell(self.Owner, name) then
  739. if SERVER then
  740. if self:GetWandCurrentSkin() == name then self:HPWSetWandSkin(HpwRewrite.DefaultSkin) end
  741. if self:GetWandCurrentSpell() == name then self:HPWRemoveCurSpell() end
  742. end
  743.  
  744. return false
  745. end
  746.  
  747. return true
  748. end
  749.  
  750. function SWEP:HPWSeqDuration2()
  751. return self.HpwRewrite.SequenceDuration
  752. end
  753.  
  754. function SWEP:HPWSendAnimation(act)
  755. self.HpwRewrite.SequenceDuration = 1 -- TODO: choose whether leave it or delete
  756.  
  757. if not act then return end
  758. if not game.SinglePlayer() and not IsFirstTimePredicted() then return end
  759.  
  760. local vm = self.Owner:GetViewModel()
  761. if not IsValid(vm) then return end
  762.  
  763. local seq = vm:SelectWeightedSequence(act)
  764. if not seq or seq == -1 then return end
  765.  
  766. vm:SendViewModelMatchingSequence(seq)
  767.  
  768. local val = self.HpwRewrite.AnimationSpeed * HpwRewrite.CVars.AnimSpeed:GetFloat()
  769.  
  770. vm:SetPlaybackRate(1 * val)
  771. self.HpwRewrite.SequenceDuration = vm:SequenceDuration(seq) / val
  772.  
  773. self:SetWandNextIdle(CurTime() + self.HpwRewrite.SequenceDuration)
  774. end
  775.  
  776. function SWEP:Initialize()
  777. if self.HpwRewrite then table.Empty(self.HpwRewrite) end
  778.  
  779. self.HpwRewrite = { }
  780. self.HpwRewrite.SequenceDuration = 0
  781. self.HpwRewrite.AnimationSpeed = 1
  782. self.HpwRewrite.BlockSprite = false
  783. self.HpwRewrite.LastAttackerSpellName = nil
  784.  
  785. if CLIENT then
  786. self.HpwRewrite.PrintHelp = true
  787. self.HpwRewrite.Select = false
  788. self.HpwRewrite.ShouldSetPos = false
  789. self.HpwRewrite.CurrentSpellPr = ""
  790.  
  791. self.HpwRewrite.SpriteAlpha = 0
  792. self.HpwRewrite.SpriteTime = 1
  793. self.HpwRewrite.SpriteSize = 1
  794. self.HpwRewrite.SpriteColor = Color(0, 0, 0, 0)
  795.  
  796. if LocalPlayer() == self.Owner then
  797. if not HpwRewrite.CVars.DisableMsg:GetBool() and not HpwRewrite.MessagePrinted then
  798. HpwRewrite:DoNotify("You can disable magic wand hints in SpawnMenu > Options > Wand Settings > Client > Disable popup hints", 3, 13)
  799.  
  800. timer.Simple(3, function()
  801. if not HpwRewrite.CVars.DisableMsg:GetBool() then
  802. HpwRewrite:DoNotify("Need help? Go to SpawnMenu > Options > Wand Settings > Online Help", 3, 18)
  803. end
  804. end)
  805.  
  806. if HpwRewrite.CVars.NoLearning:GetBool() then
  807. if self.Owner:IsSuperAdmin() then
  808. timer.Simple(8, function()
  809. if not HpwRewrite.CVars.DisableMsg:GetBool() then
  810. HpwRewrite:DoNotify("You can enable learning in SpawnMenu > Options > Wand Settings > Server > Disable learning", 3, 14)
  811. end
  812. end)
  813. end
  814. else
  815. timer.Simple(7, function()
  816. if not HpwRewrite.CVars.DisableMsg:GetBool() then
  817. HpwRewrite:DoNotify("To get spells go to SpawnMenu > Entities > Harry Potter Spell Books and spawn books", 3, 17)
  818. end
  819. end)
  820.  
  821. if self.Owner:IsSuperAdmin() then
  822. timer.Simple(14, function()
  823. if not HpwRewrite.CVars.DisableMsg:GetBool() then
  824. HpwRewrite:DoNotify("You can disable learning in SpawnMenu > Options > Wand Settings > Server > Disable learning", 3, 14)
  825. end
  826. end)
  827. end
  828. end
  829.  
  830. HpwRewrite.MessagePrinted = true
  831. else
  832. HpwRewrite:LogDebug("Popup hints are disabled or already printed")
  833. end
  834. end
  835. else
  836. self.HpwRewrite.ShouldBlockMouse = false
  837. timer.Simple(0, function()
  838. if not IsValid(self) then return end
  839. if not IsValid(self.Owner) then return end
  840. self.HpwRewrite.ShouldBlockMouse = tobool(self.Owner:GetInfoNum("hpwrewrite_cl_blockleftmouse", 0))
  841. end)
  842. self.HpwRewrite.Accuracy = 0
  843. self.HpwRewrite.UpdateAccuracy = 0
  844. self.HpwRewrite.CooldownAccuracy = 0
  845.  
  846. self:SetHPWAccuracyPenalty(1)
  847. self:SetHPWAccuracyValue(0)
  848.  
  849. -- Annoying window to setup learning config
  850. -- Leave it under comment
  851.  
  852. --[[local ply = self.Owner
  853. if HpwRewrite.CheckAdmin(ply) and ply:IsSuperAdmin() and not setup:GetBool() then
  854. net.Start("hpwrewrite_setup")
  855. net.Send(ply)
  856.  
  857. RunConsoleCommand("hpwrewrite_setup", "1")
  858. end]]
  859. end
  860. end
  861.  
  862. function SWEP:EmptySpellAttack()
  863. self.Owner:SetAnimation(PLAYER_ATTACK1)
  864. self:HPWSendAnimation(ACT_VM_PRIMARYATTACK)
  865. self:SetNextPrimaryFire(CurTime() + self:HPWSeqDuration2())
  866.  
  867. if SERVER then
  868. self:RequestSprite("", ColorRand(), 500, 0.6, true)
  869.  
  870. for i = 1, math.random(4, 8) do
  871. timer.Simple(math.Rand(0, 0.4), function()
  872. if IsValid(self) and IsValid(self.Owner) then
  873.  
  874. end
  875. end)
  876. end
  877.  
  878. local tr = util.TraceLine({
  879. start = self.Owner:GetShootPos(),
  880. endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 256,
  881. filter = self.Owner
  882. })
  883.  
  884. local ent = tr.Entity
  885. if IsValid(ent) and not (ent:IsNPC() or ent:IsPlayer()) then
  886. local phys = ent:GetPhysicsObject()
  887. if IsValid(phys) then
  888. phys:ApplyForceOffset(self.Owner:GetAimVector() * math.Clamp(phys:GetMass() * 100, 1, 700), tr.HitPos)
  889. ent:TakeDamage(5, self.Owner, self)
  890. end
  891. end
  892. end
  893. end
  894.  
  895. function SWEP:OnRemove()
  896. timer.Remove("hpwrewrite_skinhelper" .. self:EntIndex())
  897.  
  898. if IsValid(self.Owner) then
  899. local lastSpell = self:GetWandCurrentSpell()
  900. if lastSpell != "" then self.Owner:SetPData("WeaponHpwrStick_LastSpell", lastSpell) end
  901.  
  902. local lastSkin = self:GetWandCurrentSkin()
  903. if lastSkin != "" then self.Owner:SetPData("WeaponHpwrStick_LastSkin", lastSkin) end
  904. end
  905. end
  906.  
  907. function SWEP:Holster(wep, anim)
  908. self:OnRemove()
  909.  
  910. if CLIENT then
  911. self.HpwRewrite.Select = false
  912. end
  913.  
  914. local curspell = HpwRewrite:GetPlayerSpell(self.Owner, self:GetWandCurrentSpell())
  915. if curspell then curspell:OnWandHolster(self) end
  916.  
  917. return true
  918. end
  919.  
  920. function SWEP:Deploy(anim)
  921. if self.Owner:IsNPC() then print("Wand won't handle NPC owner! Removing...") self:Remove() return end
  922. if not self.Owner:IsPlayer() then print("Wand owner should be a player! Removing...") self:Remove() return end
  923.  
  924. if not self.HpwRewrite then
  925. self.HpwRewrite = { }
  926. ErrorNoHalt("Wand's HpwRewrite table has been initialized in the Deploy function! Please, contact addon's developers\n")
  927. end
  928.  
  929. self:HPWSendAnimation(ACT_VM_DRAW)
  930. //self:SetNextPrimaryFire(CurTime() + self:HPWSeqDuration2())
  931.  
  932. if SERVER then
  933. if not self.Owner.HpwRewrite then
  934. self.Owner.HpwRewrite = { }
  935. HpwRewrite:LogDebug(self.Owner:Name() .. " HpwRewrite namespace has been initialized in SWEP")
  936.  
  937. print("Your HpwRewrite table has been initialized in the Deploy function! Please, contact addon's developers")
  938. end
  939.  
  940. if not anim then
  941. -- TODO: do something to remove this timer
  942. -- Seems like gmod doesn't like doing it in the same frame as you deploy
  943. timer.Create("hpwrewrite_skinhelper" .. self:EntIndex(), FrameTime(), 1, function()
  944. if not IsValid(self) or not IsValid(self.Owner) then return end
  945. if not self.Owner:GetPData("WeaponHpwrStick_LastSkin") then
  946. self.Owner:SetPData("WeaponHpwrStick_LastSkin", HpwRewrite.DefaultSkin)
  947. end
  948.  
  949. self:HPWSetWandSkin(self.Owner:GetPData("WeaponHpwrStick_LastSkin"))
  950. end)
  951. end
  952.  
  953. local oldspell = self.Owner:GetPData("WeaponHpwrStick_LastSpell")
  954. if oldspell then
  955. self:HPWSetCurrentSpell(oldspell)
  956. end
  957.  
  958. local curspell = HpwRewrite:GetPlayerSpell(self.Owner, self:GetWandCurrentSpell())
  959. if curspell then curspell:OnWandDeploy(self) end
  960. end
  961.  
  962. return true
  963. end
  964.  
  965. function SWEP:MakeSparks(col, lifetime)
  966. local ef = EffectData()
  967. ef:SetEntity(self.Owner)
  968. ef:SetStart(Vector(col.r, col.g, col.b))
  969. ef:SetScale(lifetime)
  970. util.Effect("EffectHpwRewriteSparks", ef, true, true)
  971. end
  972.  
  973. function SWEP:PrimaryAttack(spellName)
  974. if self.Owner:InVehicle() and not self.Owner:GetAllowWeaponsInVehicle() then return end
  975. if self.HpwRewrite.ShouldBlockMouse and not spellName then return end
  976.  
  977. if CurTime() < self:GetNextPrimaryFire() then return end
  978. if HpwRewrite.FM:GetValue(self.Owner) then return end
  979.  
  980. -- Protection
  981. self:SetNextPrimaryFire(CurTime() + 1.5)
  982.  
  983. -- Check if we have skin
  984. local skintab = HpwRewrite:GetPlayerSkin(self.Owner, self:GetWandCurrentSkin())
  985. if not skintab then
  986. if SERVER then self:HPWSetWandSkin(HpwRewrite.DefaultSkin) end
  987. return
  988. end
  989.  
  990. -- Quick attack
  991. if SERVER and spellName then
  992. if self:HPWSetCurrentSpell(spellName) then
  993. if game.SinglePlayer() then self:CallOnClient("PrimaryAttack") end
  994. else
  995. HpwRewrite:LogDebug(self.Owner:Name() .. " attempted to use quick attack with " .. spellName)
  996. return
  997. end
  998. end
  999.  
  1000. -- Making anims, checking if we can attack
  1001. local curspell = self:GetWandCurrentSpell()
  1002. local name = curspell
  1003. if not self:CheckSpellUseable(name) then self:EmptySpellAttack() return end
  1004.  
  1005. curspell = HpwRewrite:GetPlayerSpell(self.Owner, name)
  1006. if not curspell then self:EmptySpellAttack() return end
  1007.  
  1008. self.HpwRewrite.AnimationSpeed = curspell.AnimSpeedCoef or 1
  1009. self.HoldingSelfCast = curspell.ShouldReverseSelfCast
  1010. self.HpwRewrite.DidAnimations = false
  1011.  
  1012. if curspell.PlayAnimation then
  1013. self.Owner:SetAnimation(PLAYER_ATTACK1)
  1014.  
  1015. local newAnim = curspell:GetAnimations(self)
  1016. if newAnim then
  1017. self:HPWSendAnimation(ACT_VM_PRIMARYATTACK) -- if theres no newAnim
  1018. self:HPWSendAnimation(newAnim)
  1019. else
  1020. if skintab.ForceAnim then
  1021. self:HPWSendAnimation(table.Random(skintab.ForceAnim))
  1022. else
  1023. self:HPWSendAnimation(ACT_VM_PRIMARYATTACK)
  1024. end
  1025.  
  1026. if curspell.ForceAnim then self:HPWSendAnimation(table.Random(curspell.ForceAnim)) end
  1027. end
  1028.  
  1029. if curspell.CanSelfCast then
  1030. if HpwRewrite:IsHoldingSelfCast(self.Owner) then
  1031. if SERVER then
  1032. timer.Create("hpwrewrite_timer_selfcastspr" .. self:EntIndex(), self:HPWSeqDuration2() * 0.7, 1, function()
  1033. if IsValid(self) and self:CanContinue(curspell) then
  1034. self:HPWDoSprite(curspell)
  1035. end
  1036. end)
  1037. end
  1038.  
  1039. self.HoldingSelfCast = not curspell.ShouldReverseSelfCast
  1040. end
  1041.  
  1042. if curspell.DoSelfCastAnim then
  1043. if HpwRewrite:IsHoldingSelfCast(self.Owner) then
  1044. if not curspell.ShouldReverseSelfCast then
  1045. self:HPWSendAnimation(ACT_VM_HITCENTER)
  1046. end
  1047. else
  1048. if curspell.ShouldReverseSelfCast then
  1049. self:HPWSendAnimation(ACT_VM_HITCENTER)
  1050. end
  1051. end
  1052. end
  1053. end
  1054.  
  1055. self:SetNextPrimaryFire(CurTime() + self:HPWSeqDuration2())
  1056. self.HpwRewrite.DidAnimations = true
  1057. end
  1058.  
  1059. if curspell.ForceDelay then
  1060. self.HpwRewrite.Accuracy = 1
  1061. self:SetNextPrimaryFire(CurTime() + curspell.ForceDelay)
  1062. self.HpwRewrite.TimeTick = FrameTime() / curspell.ForceDelay
  1063. end
  1064.  
  1065. -- Fire, fire, FIRE !!!
  1066. if SERVER and not self.Owner.HpwRewrite.BlockSpelling then -- The second expression is for Mimblewimble and so on
  1067. skintab:OnFire(self)
  1068.  
  1069. if curspell:PreFire(self) then
  1070. if curspell.DoSparks then
  1071. self:MakeSparks(curspell.SpriteColor, curspell.SparksLifeTime or 0.4)
  1072. end
  1073.  
  1074. if curspell.ApplyFireDelay then
  1075. timer.Simple(self:HPWSeqDuration2() * curspell.ApplyFireDelay, function()
  1076. if IsValid(self) and self:CanContinue(curspell) then self:AttackSpell(curspell) end
  1077. end)
  1078. else
  1079. self:AttackSpell(curspell)
  1080. end
  1081.  
  1082. if curspell.ShouldSay and not HpwRewrite.CVars.NoSay:GetBool() then
  1083. self.Owner:Say((curspell.WhatToSay or name) .. "!")
  1084. end
  1085. end
  1086. end
  1087.  
  1088. self.HpwRewrite.AnimationSpeed = 1
  1089. self.HpwRewrite.DidAnimations = false
  1090. end
  1091.  
  1092. function SWEP:Think()
  1093. if not IsValid(self.Owner) then return end
  1094.  
  1095. local idle = self:GetWandNextIdle()
  1096. if idle > 0 and CurTime() > idle then
  1097. self:HPWSendAnimation(ACT_VM_IDLE)
  1098. end
  1099.  
  1100. local curspell = HpwRewrite:GetPlayerSpell(self.Owner, self:GetWandCurrentSpell())
  1101. if curspell then curspell:Think(self) end
  1102.  
  1103. local curskin = HpwRewrite:GetPlayerSkin(self.Owner, self:GetWandCurrentSkin())
  1104. if curskin then curskin:Think(self) end
  1105.  
  1106. if SERVER then
  1107. if self.HpwRewrite.Accuracy == 0 then self.HpwRewrite.TimeTick = 0 end
  1108. self.HpwRewrite.Accuracy = math.Approach(self.HpwRewrite.Accuracy, 0, self.HpwRewrite.TimeTick or 0)
  1109. self:SetHPWAccuracyValue(self.HpwRewrite.Accuracy)
  1110. end
  1111.  
  1112. -- Selecting
  1113. if CLIENT and LocalPlayer() == self.Owner then
  1114. if HpwRewrite.FM:GetValue() then return end
  1115.  
  1116. -- Selecting spell by mouse and context menu
  1117. if vgui.CursorVisible() and self.HpwRewrite.Select and not HpwRewrite.CVars.NoChoosing:GetBool() and HpwRewrite.CVars.DrawSpellBar:GetBool() and not HpwRewrite.CVars.NoHud:GetBool() then
  1118. local bind = HpwRewrite.BM.Binds[self:CalculateCellOffset()]
  1119.  
  1120. if self.HpwRewrite.ShouldSetPos then
  1121. local spell
  1122. for k, v in pairs(HpwRewrite.BM.Binds) do
  1123. if v.Spell == self:GetWandCurrentSpell() then
  1124. spell = k
  1125. break
  1126. end
  1127. end
  1128.  
  1129. if spell then
  1130. local x, y = self:GetCellPosition(spell)
  1131. input.SetCursorPos(x, y)
  1132. end
  1133.  
  1134. self.HpwRewrite.ShouldSetPos = false
  1135. end
  1136.  
  1137. if bind and bind.Spell != self.HpwRewrite.CurrentSpellPr then
  1138. HpwRewrite:RequestSpell(bind.Spell)
  1139. self.HpwRewrite.CurrentSpellPr = bind.Spell
  1140. end
  1141. end
  1142.  
  1143. -- Main menu
  1144. if not vgui.CursorVisible() then
  1145. if not self.HpwRewrite.WasMenuKeyPressed then self.HpwRewrite.WasMenuKeyPressed = false end
  1146.  
  1147. local key = HpwRewrite.CVars.MenuKey:GetInt()
  1148. local oldpressed = self.HpwRewrite.WasMenuKeyPressed
  1149. self.HpwRewrite.WasMenuKeyPressed = key >= 107 and input.IsMouseDown(key) or input.IsKeyDown(key)
  1150.  
  1151. if oldpressed != self.HpwRewrite.WasMenuKeyPressed and self.HpwRewrite.WasMenuKeyPressed then
  1152. if self:GetWandCurrentSkin() == "" then
  1153. HpwRewrite:RequestSpell(HpwRewrite.DefaultSkin)
  1154. end
  1155.  
  1156. HpwRewrite.VGUI:OpenNewSpellManager()
  1157. if self.HpwRewrite.PrintHelp then self.HpwRewrite.PrintHelp = false end
  1158. end
  1159. end
  1160. end
  1161.  
  1162. if self.OldOwner != nil and self.OldOwner != self.Owner then
  1163. self:Initialize()
  1164. end
  1165.  
  1166. self.OldOwner = self.Owner
  1167.  
  1168. self:NextThink(CurTime())
  1169. return true
  1170. end
  1171.  
  1172. function SWEP:SecondaryAttack()
  1173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement