• Print

Author Topic: Need Help!  (Read 4439 times)

0 Members and 1 Guest are viewing this topic.

Offline Ben Vandenberg

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Need Help!
« on: December 29, 2014, 10:48:46 am »
I am trying to add a gun to my server and after some testing i found out that it reloads instantly i would prefer it to reload at 3 sec
Code: Lua
  1. resource.AddFile("materials/vgui/ttt/icon_mp5.vmt")
  2.  
  3. -- First some standard GMod stuff
  4. if SERVER then
  5.    AddCSLuaFile( "mp5.lua" )
  6. end
  7.  
  8. if CLIENT then
  9.    SWEP.PrintName = "MP5"
  10.    SWEP.Slot      = 2 -- add 1 to get the slot number key
  11.  
  12.    SWEP.ViewModelFOV  = 72
  13.    SWEP.ViewModelFlip = true
  14.    
  15.    SWEP.Icon = "VGUI/ttt/icon_mp5"
  16. end
  17.  
  18. -- Always derive from weapon_tttbase.
  19. SWEP.Base            = "weapon_tttbase"
  20.  
  21. --- Standard GMod values
  22.  
  23. SWEP.HoldType         = "ar2"
  24.  
  25. SWEP.Primary.Delay       = 0.093
  26. SWEP.Primary.Recoil      = 1.2
  27. SWEP.Primary.Automatic   = true
  28. SWEP.Primary.Damage      = 11
  29. SWEP.Primary.Cone        = 0.03
  30. SWEP.Primary.Ammo        = "smg1"
  31. SWEP.Primary.ClipSize    = 30
  32. SWEP.Primary.ClipMax     = 60
  33. SWEP.Primary.DefaultClip = 30
  34. SWEP.Primary.Reload      = 5
  35. SWEP.Primary.Sound       = Sound( "Weapon_MP5Navy.Single" )
  36.  
  37. SWEP.IronSightsPos = Vector(4.84, 0.36, 1.84)
  38. SWEP.IronSightsAng = Vector(1.1, 0.3, 0)
  39.  
  40. SWEP.ViewModel  = "models/weapons/v_smg_mp5.mdl"
  41. SWEP.WorldModel = "models/weapons/w_smg_mp5.mdl"
  42.  
  43.  
  44. -- TTT --
  45. SWEP.Kind = WEAPON_HEAVY
  46. SWEP.AutoSpawnable = true
  47. SWEP.AmmoEnt = "item_ammo_smg1_ttt"
  48. SWEP.CanBuy = false
  49. SWEP.InLoadoutFor = nil
  50. SWEP.LimitedStock = false
  51. SWEP.AllowDrop = true
  52. SWEP.IsSilent = false
  53. SWEP.NoSights = false
My scoreboard also has a error
[ERROR] gamemodes/terrortown/gamemode/vgui/sb_team.lua:81: attempt to perform arithmetic on field 'Width' (a nil value)
  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_team.lua:81
This is my current script
Code: Lua
  1. ---- Unlike sandbox, we have teams to deal with, so here's an extra panel in the
  2. ---- hierarchy that handles a set of player rows belonging to its team.
  3.  
  4. include("sb_row.lua")
  5.  
  6. local function CompareScore(pa, pb)
  7.    if not ValidPanel(pa) then return false end
  8.    if not ValidPanel(pb) then return true end
  9.  
  10.    local a = pa:GetPlayer()
  11.    local b = pb:GetPlayer()
  12.  
  13.    if not IsValid(a) then return false end
  14.    if not IsValid(b) then return true end
  15.  
  16.    if a:Frags() == b:Frags() then return a:Deaths() < b:Deaths() end
  17.  
  18.    return a:Frags() > b:Frags()
  19. end
  20.  
  21. local PANEL = {}
  22.  
  23. function PANEL:Init()
  24.    self.name = "Unnamed"
  25.  
  26.    self.color = COLOR_WHITE
  27.  
  28.    self.rows = {}
  29.    self.rowcount = 0
  30.  
  31.    self.rows_sorted = {}
  32.  
  33.    self.group = "spec"
  34. end
  35.  
  36. function PANEL:SetGroupInfo(name, color, group)
  37.    self.name = name
  38.    self.color = color
  39.    self.group = group
  40. end
  41.  
  42. local bgcolor = Color(20,20,20, 150)
  43. function PANEL:Paint()
  44.    -- Darkened background
  45.    draw.RoundedBox(8, 0, 0, self:GetWide(), self:GetTall(), bgcolor)
  46.  
  47.    surface.SetFont("treb_small")
  48.  
  49.    -- Header bg
  50.    local txt = self.name .. " (" .. self.rowcount .. ")"
  51.    local w, h = surface.GetTextSize(txt)
  52.    draw.RoundedBox(8, 0, 0, w + 24, 20, self.color)
  53.  
  54.    -- Shadow
  55.    surface.SetTextPos(11, 11 - h/2)
  56.    surface.SetTextColor(0,0,0, 200)
  57.    surface.DrawText(txt)
  58.  
  59.    -- Text
  60.    surface.SetTextPos(10, 10 - h/2)
  61.    surface.SetTextColor(255,255,255,255)
  62.    surface.DrawText(txt)
  63.  
  64.    -- Alternating row background
  65.    local y = 24
  66.    for i, row in ipairs(self.rows_sorted) do
  67.       if (i % 2) != 0 then
  68.          surface.SetDrawColor(75,75,75, 100)
  69.          surface.DrawRect(0, y, self:GetWide(), row:GetTall())
  70.       end
  71.  
  72.       y = y + row:GetTall() + 1
  73.    end
  74.  
  75.    -- Column darkening
  76.    local scr = sboard_panel.ply_frame.scroll.Enabled and 16 or 0
  77.    surface.SetDrawColor(0,0,0, 80)
  78.    if sboard_panel.cols then
  79.       local cx = self:GetWide() - scr
  80.       for k,v in ipairs(sboard_panel.cols) do
  81.          cx = cx - v.Width
  82.          if k % 2 == 1 then -- Draw for odd numbered columns
  83.             surface.DrawRect(cx-v.Width/2, 0, v.Width, self:GetTall())
  84.          end
  85.       end
  86.    else
  87.       -- If columns are not setup yet, fall back to darkening the areas for the
  88.       -- default columns
  89.       surface.DrawRect(self:GetWide() - 175 - 25 - scr, 0, 50, self:GetTall())
  90.       surface.DrawRect(self:GetWide() - 75 - 25 - scr, 0, 50, self:GetTall())
  91.    end
  92. end
  93.  
  94. function PANEL:AddPlayerRow(ply)
  95.    if ScoreGroup(ply) == self.group and not self.rows[ply] then
  96.       local row = vgui.Create("TTTScorePlayerRow", self)
  97.       row:SetPlayer(ply)
  98.       self.rows[ply] = row
  99.       self.rowcount = table.Count(self.rows)
  100.  
  101. --      row:InvalidateLayout()
  102.  
  103.       -- must force layout immediately or it takes its sweet time to do so
  104.       self:PerformLayout()
  105.       --self:InvalidateLayout()
  106.    end
  107. end
  108.  
  109. function PANEL:HasPlayerRow(ply)
  110.    return self.rows[ply] != nil
  111. end
  112.  
  113. function PANEL:HasRows()
  114.    return self.rowcount > 0
  115. end
  116.  
  117. function PANEL:UpdateSortCache()
  118.    self.rows_sorted = {}
  119.    for k,v in pairs(self.rows) do
  120.       table.insert(self.rows_sorted, v)
  121.    end
  122.  
  123.    table.sort(self.rows_sorted, CompareScore)
  124. end
  125.  
  126. function PANEL:UpdatePlayerData()
  127.    local to_remove = {}
  128.    for k,v in pairs(self.rows) do
  129.       -- Player still belongs in this group?
  130.       if ValidPanel(v) and IsValid(v:GetPlayer()) and ScoreGroup(v:GetPlayer()) == self.group then
  131.          v:UpdatePlayerData()
  132.       else
  133.          -- can't remove now, will break pairs
  134.          table.insert(to_remove, k)
  135.       end
  136.    end
  137.  
  138.    if #to_remove == 0 then return end
  139.  
  140.    for k,ply in pairs(to_remove) do
  141.       local pnl = self.rows[ply]
  142.       if ValidPanel(pnl) then
  143.          pnl:Remove()
  144.       end
  145.  
  146. --      print(CurTime(), "Removed player", ply)
  147.  
  148.       self.rows[ply] = nil
  149.    end
  150.    self.rowcount = table.Count(self.rows)
  151.  
  152.    self:UpdateSortCache()
  153.  
  154.    self:InvalidateLayout()
  155. end
  156.  
  157.  
  158. function PANEL:PerformLayout()
  159.    if self.rowcount < 1 then
  160.       self:SetVisible(false)
  161.       return
  162.    end
  163.  
  164.    self:SetSize(self:GetWide(), 30 + self.rowcount + self.rowcount * SB_ROW_HEIGHT)
  165.  
  166.    -- Sort and layout player rows
  167.    self:UpdateSortCache()
  168.  
  169.    local y = 24
  170.    for k, v in ipairs(self.rows_sorted) do
  171.       v:SetPos(0, y)
  172.       v:SetSize(self:GetWide(), v:GetTall())
  173.  
  174.       y = y + v:GetTall() + 1
  175.    end
  176.  
  177.    self:SetSize(self:GetWide(), 30 + (y - 24))
  178. end
  179.  
  180. vgui.Register("TTTScoreGroup", PANEL, "Panel")
Any help is appreciated, thanks.
« Last Edit: December 30, 2014, 07:23:08 am by Ben Vandenberg »

  • Print