kizaru335

nxserv selector

Aug 10th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.10 KB | None | 0 0
  1. local scale = (ScrW() >= 2560 and 2) or (ScrW() / 175 >= 6 and 1) or 0.8
  2.  
  3. surface.CreateFont("wepsel", {
  4. size = 22 * scale,
  5. weight = 300 * scale,
  6. antialias = true,
  7. shadow = true,
  8. blursize = 0,
  9. font = "Arial"})
  10.  
  11. surface.CreateFont("small", {
  12. size = 22 * 0.7 * scale,
  13. weight = 300 * scale,
  14. antialias = true,
  15. shadow = true,
  16. blursize = 0,
  17. font = "Arial"})
  18.  
  19. local curTab = 0
  20. local curSlot = 1
  21. local alpha = 0
  22. local lastAction = -math.huge
  23. local loadout = {}
  24. local slide = {}
  25.  
  26. local newinv
  27. hook.Add("CreateMove", "wepsel", function(cmd)
  28. if newinv then
  29. local wep = LocalPlayer():GetWeapon(newinv)
  30. if wep:IsValid() and LocalPlayer():GetActiveWeapon() ~= wep then
  31. cmd:SelectWeapon(wep)
  32. else
  33. newinv = nil
  34. end
  35. end
  36. end)
  37.  
  38. local CWeapons = {}
  39. for _, y in pairs(file.Find("scripts/weapon_*.txt", "MOD")) do
  40. local t = util.KeyValuesToTable(file.Read("scripts/" .. y, "MOD"))
  41. CWeapons[y:match("(.+)%.txt")] = {
  42. Slot = t.bucket,
  43. SlotPos = t.bucket_position,
  44. TextureData = t.texturedata
  45. }
  46. end
  47.  
  48. local localization = {
  49. gmod_camera = DarkRP.getPhrase("gmod_camera"),
  50. gmod_tool = DarkRP.getPhrase("gmod_tool"),
  51. weapon_bugbait = DarkRP.getPhrase("weapon_bugbait"),
  52. weapon_physcannon = DarkRP.getPhrase("weapon_physcannon"),
  53. weapon_physgun = DarkRP.getPhrase("weapon_physgun"),
  54. }
  55.  
  56. local function findcurrent()
  57. if alpha <= 0 then
  58. table.Empty(slide)
  59. local class = IsValid(LocalPlayer():GetActiveWeapon()) and LocalPlayer():GetActiveWeapon():GetClass()
  60. for k1, v1 in pairs(loadout) do
  61. for k2, v2 in pairs(v1) do
  62. if v2.classname == class then
  63. curTab = k1
  64. curSlot = k2
  65. return
  66. end
  67. end
  68. end
  69. end
  70. end
  71.  
  72. local function update()
  73. table.Empty(loadout)
  74.  
  75. for k, v in pairs(LocalPlayer():GetWeapons()) do
  76. local classname = v:GetClass()
  77.  
  78. local Slot = CWeapons[classname] and CWeapons[classname].Slot or v.Slot or 1
  79.  
  80. loadout[Slot] = loadout[Slot] or {}
  81.  
  82. table.insert(loadout[Slot], {
  83. classname = classname,
  84. name = localization[classname] or v:GetPrintName(),
  85. new = (CurTime() - v:GetCreationTime()) < 60,
  86. slotpos = CWeapons[classname] and CWeapons[classname].SlotPos or v.SlotPos or 1
  87. })
  88. end
  89.  
  90. for k, v in pairs(loadout) do
  91. table.sort(v, function(a, b) return a.slotpos < b.slotpos end)
  92. end
  93. end
  94.  
  95. local FKeyBinds = {
  96. ["gm_showhelp"] = "ShowHelp",
  97. ["gm_showteam"] = "ShowTeam",
  98. ["gm_showspare1"] = "ShowSpare1",
  99. ["gm_showspare2"] = "ShowSpare2"
  100. }
  101.  
  102. function GAMEMODE:PlayerBindPress(ply, bind, pressed)
  103. self.BaseClass:PlayerBindPress(ply, bind, pressed)
  104.  
  105. local bnd = bind:lower():match("gm_[a-z]+[12]?")
  106. if bnd and FKeyBinds[bnd] then
  107. hook.Call(FKeyBinds[bnd], GAMEMODE)
  108. end
  109.  
  110. if not pressed or ply:InVehicle() then return end
  111.  
  112. bind = bind:lower()
  113.  
  114. if bind:sub(1, 4) == "slot" then
  115. local n = tonumber(bind:sub(5, 5) or 1) or 1
  116.  
  117. if n < 1 or n > 6 then return true end
  118.  
  119. n = n - 1
  120.  
  121. update()
  122.  
  123. if not loadout[n] then return true end
  124.  
  125. findcurrent()
  126.  
  127. if curTab == n and loadout[curTab] and (alpha > 0 or GetConVarNumber("hud_fastswitch") > 0) then
  128. curSlot = curSlot + 1
  129.  
  130. if curSlot > #loadout[curTab] then
  131. curSlot = 1
  132. end
  133. else
  134. curTab = n
  135. curSlot = 1
  136. end
  137.  
  138. if GetConVarNumber("hud_fastswitch") > 0 then
  139. newinv = loadout[curTab][curSlot].classname
  140. else
  141. alpha = 1
  142. lastAction = RealTime()
  143. end
  144.  
  145. surface.PlaySound("ambient/water/rain_drip1.wav")
  146.  
  147. return true
  148. elseif bind:find("invnext", nil, true) and not (ply:GetActiveWeapon():IsValid() and ply:GetActiveWeapon():GetClass() == "weapon_physgun" and ply:KeyDown(IN_ATTACK)) then
  149. update()
  150.  
  151. if #loadout < 1 then
  152. return true
  153. end
  154.  
  155. findcurrent()
  156.  
  157. curSlot = curSlot + 1
  158.  
  159. if curSlot > (loadout[curTab] and #loadout[curTab] or -1) then
  160. repeat
  161. curTab = curTab + 1
  162. if curTab > 5 then
  163. curTab = 0
  164. end
  165. until loadout[curTab]
  166. curSlot = 1
  167. end
  168.  
  169. if GetConVarNumber("hud_fastswitch") > 0 then
  170. newinv = loadout[curTab][curSlot].classname
  171. surface.PlaySound("ambient/water/rain_drip3.wav")
  172. else
  173. lastAction = RealTime()
  174. alpha = 1
  175. surface.PlaySound("ambient/water/rain_drip1.wav")
  176. end
  177.  
  178. return true
  179. elseif bind:find("invprev", nil, true) and not (ply:GetActiveWeapon():IsValid() and ply:GetActiveWeapon():GetClass() == "weapon_physgun" and ply:KeyDown(IN_ATTACK)) then
  180. update()
  181.  
  182. if #loadout < 1 then
  183. return true
  184. end
  185.  
  186. findcurrent()
  187.  
  188. curSlot = curSlot - 1
  189.  
  190. if curSlot < 1 then
  191. repeat
  192. curTab = curTab - 1
  193. if curTab < 0 then
  194. curTab = 5
  195. end
  196. until loadout[curTab]
  197. curSlot = #loadout[curTab]
  198. end
  199.  
  200. if GetConVarNumber("hud_fastswitch") > 0 then
  201. newinv = loadout[curTab][curSlot].classname
  202. surface.PlaySound("ambient/water/rain_drip3.wav")
  203. else
  204. lastAction = RealTime()
  205. alpha = 1
  206. surface.PlaySound("ambient/water/rain_drip1.wav")
  207. end
  208.  
  209. return true
  210. elseif bind:find("+attack", nil, true) and alpha > 0 then
  211. if loadout[curTab] and loadout[curTab][curSlot] and not bind:find("+attack2", nil, true) then
  212. newinv = loadout[curTab][curSlot].classname
  213. end
  214. surface.PlaySound("ambient/water/rain_drip3.wav")
  215. alpha = 0
  216.  
  217. return true
  218. end
  219. end
  220.  
  221. local width = 175 * scale
  222. local height = 22 * scale
  223. local margin = height / 4
  224. local c000127 = Color(0, 0, 0, 127)
  225. local c00200200 = Color(0, 0, 200, 200)
  226.  
  227. hook.Add("HUDPaint", "wepsel", function()
  228. if not IsValid(LocalPlayer()) then
  229. return
  230. end
  231.  
  232. if alpha < 1e-02 then
  233. if alpha ~= 0 then
  234. alpha = 0
  235. end
  236. return
  237. end
  238.  
  239. update()
  240.  
  241. if RealTime() - lastAction > 2 then
  242. alpha = Lerp(FrameTime() * 4, alpha, 0)
  243. end
  244.  
  245. surface.SetAlphaMultiplier(alpha)
  246.  
  247. surface.SetDrawColor(c000127)
  248. surface.SetTextColor(color_white)
  249. surface.SetFont("wepsel")
  250.  
  251. local thisWidth = 0
  252.  
  253. for i, v in pairs(loadout) do
  254. thisWidth = thisWidth + width + margin
  255. end
  256.  
  257. local offx = ScrW() - thisWidth
  258.  
  259. for i, v in pairs(loadout) do
  260. local offy = margin
  261.  
  262. surface.SetDrawColor(c000127)
  263. surface.DrawRect(offx, offy, height, height)
  264.  
  265. local w, h = surface.GetTextSize(i + 1)
  266. surface.SetTextPos(offx + (height - w) / 2, offy + (height - h) / 2)
  267. surface.DrawText(i + 1)
  268. offy = offy + h + margin
  269.  
  270. for j, wep in pairs(v) do
  271. local selected = curTab == i and curSlot == j
  272. --local height = selected and height * 2 + margin or height
  273.  
  274. local height = height + (height + margin) * (slide[wep.classname] or 0)
  275.  
  276. slide[wep.classname] = Lerp(FrameTime() * 10, slide[wep.classname] or 0, selected and 1 or 0)
  277.  
  278. surface.SetDrawColor(selected and c00200200 or (wep.new and Color(0, math.abs(math.sin(RealTime())) * 255, 0, 127) or c000127))
  279. surface.DrawRect(offx, offy, width, height)
  280.  
  281. surface.SetFont("wepsel")
  282. local w, h = surface.GetTextSize(wep.name)
  283. if w > width then
  284. surface.SetFont("small")
  285. w, h = surface.GetTextSize(wep.name)
  286. end
  287. surface.SetTextPos(offx + (width - w) / 2, offy + (height - h) / 2)
  288. surface.DrawText(wep.name)
  289.  
  290. offy = offy + height + margin
  291. end
  292.  
  293. offx = offx + width + margin
  294. end
  295.  
  296. surface.SetAlphaMultiplier(1)
  297. end)
Add Comment
Please, Sign In to add comment