• Print

Author Topic: TipIndex (nil value)  (Read 4696 times)

0 Members and 1 Guest are viewing this topic.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
TipIndex (nil value)
« on: November 14, 2016, 07:14:50 pm »
So I'm writing this little script that will give Traitors a radar when a certain amount of votes is passed, but for whatever reason I'm getting this error:
Code: [Select]
[ERROR] gamemodes/terrortown/gamemode/cl_tips.lua:123: attempt to perform arithmetic on field 'TipIndex' (a nil value)
  1. NextTip - gamemodes/terrortown/gamemode/cl_tips.lua:123
    2. unknown - gamemodes/terrortown/gamemode/cl_tips.lua:213

Which I'm kind of confused because after googling around it seemed to have something to do with an addon that overwrites TipIndex or TTTTTips or something like that, but nothing in my script does that... Here's what I have:


EDIT: Just to clarify, I did some debugging and I had only this script installed (no other addons) and the error was still being thrown. Added everything back in one at a time without this script and no error until I put this in, so I'm sure it has to do something with this.

autorun/sh_config.lua:
Code: Lua
  1. if SERVER then
  2.  
  3.    AddCSLuaFile()
  4.  
  5. end
  6. -- DO NOT EDIT THESE.
  7.  
  8. MsgN( "Give Radar config initializing..." )
  9.  
  10. Radar = {}
  11. Radar.Config = {}
  12.  
  13. RadarConfigDefault= {
  14.    
  15.    Enable = true,
  16.    UseVotesOverPercent = false,
  17.    MinPlys = 5,
  18.    MinPercent = 0.66,
  19.    MinVotes = 10,
  20.    VoteMessage = " voted to give Traitors a Radar.",
  21.    RevokeMessage = " revoked their vote to give Traitors a Radar.",
  22.    SaveLoc = "giveradar/config.txt"
  23.    
  24. }
  25.  
  26. function CreateConfigFile()
  27.  
  28.    if not file.Exists( Radar.Config.Dir, "DATA" ) then
  29.  
  30.       file.CreateDir( Radar.Config.Dir )
  31.  
  32.    end
  33.  
  34.    if not file.Exists( Radar.Config.SaveLoc, "DATA" ) then
  35.  
  36.       file.Write( Radar.Config.SaveLoc, util.TableToJSON( RadarConfigDefault ) )
  37.  
  38.    end
  39.    
  40. end
  41. hook.Add( "Initialize", "Create Default Config File", CreateConfigFile )
  42.  
  43. -----------------------------------------------------------------------------------------------------------------------------
  44. --------------- You may edit anything from here on, make sure to read the comments to know what you're doing. ---------------
  45. -----------------------------------------------------------------------------------------------------------------------------
  46. --[[
  47.  
  48.    Enable - Defines whether or not this addon is enabled. Set to 'false' to disable.
  49.    Default: true
  50.  
  51. ]]--
  52. Radar.Config.Enable = true
  53.  
  54. --[[
  55.  
  56.    UseVotesNotPercent - Defines whether or not to use MinVotes over MinPercent. Set to 'true' to enable.
  57.    Default: false
  58.  
  59. ]]--
  60. Radar.Config.UseVotesOverPercent = false
  61.  
  62. --[[
  63.  
  64.    MinPlys - Defines the amount of players required to start a vote. This can be replaced with any whole number, but no greater than your maximum server size.
  65.    Default: 5
  66.  
  67. ]]--
  68. Radar.Config.MinPlys = 5
  69.  
  70. --[[
  71.  
  72.    MinPercent - Defines the minimum percentage of all players on the server required to pass the vote. This can be any number 0 < x < 1.
  73.    Default: 0.66 (2/3)
  74.  
  75. ]]--
  76. Radar.Config.MinPercent = 0.66
  77.  
  78. --[[
  79.  
  80.    MinVotes - Defines the minimum number of votes required to pass the vote. This will disable 'MinPercent'.
  81.    Only change if UseVotesOverPercent is set to 'true'.
  82.    Default: 10
  83.  
  84. ]]--
  85. Radar.Config.MinVotes = 10
  86.  
  87. --[[
  88.  
  89.    VoteMessage - Defines the message printed when someone actually votes.
  90.    LEAVE A SPACE AFTER THE FIRST "
  91.    
  92. ]]--
  93. Radar.Config.VoteMessage = " voted to give Traitors a Radar."
  94.  
  95. --[[
  96.  
  97.    RevokeMessage - Defines the message printed when someone revokes their vote
  98.    LEAVE A SPACE AFTER THE FIRST "
  99.  
  100. ]]--
  101. Radar.Config.RevokeMessage = " revoked their vote to give Traitors a Radar."
  102.  
  103. --[[
  104.  
  105.    Dir - Defines the directory (relative to garrysmod/data/) the default config folder will be made.
  106.    MUST BE FOLLOWED BY A BACKSLASH (/)
  107.    Default: "giveradar/"
  108.  
  109. ]]--
  110. Radar.Config.Dir = "giveradar/"
  111.  
  112. --[[
  113.  
  114.    DefaultFile - Defines the file (relative to garrysmod/data/Dir) the default config will be saved.
  115.    Default: "default.txt"
  116.  
  117. ]]--
  118. Radar.Config.DefaultFile = "default.txt"
  119.  
  120. --[[
  121.  
  122.    ConfigFile - Defines the file (relative to garrysmod/data/Dir) the actual config will be saved.
  123.    Default: "config.txt"
  124.  
  125. ]]
  126. Radar.Config.ConfigFile = "config.txt"
  127.  
  128. --[[
  129.  
  130.    Do not edit these
  131.    SaveLoc - Concatenates the 'Dir' and 'DefaultFile' to make it easier to write to.
  132.    ConfigLoc - Concatenates the 'Dir' and 'ConfigFile' to make it easier to write to.
  133.  
  134. ]]--
  135. Radar.Config.SaveLoc = Radar.Config.Dir .. Radar.Config.DefaultFile
  136. Radar.Config.ConfigLoc = Radar.Config.Dir .. Radar.Config.ConfigFile
  137.  
  138. RadarActualConfig = {
  139.  
  140.    Enable = Radar.Config.Enable,
  141.    UseVotesOverPercent = Radar.Config.UseVotesOverPercent,
  142.    MinPlys = Radar.Config.MinPlys,
  143.    MinPercent = Radar.Config.MinPercent,
  144.    MinVotes = Radar.Config.MinVotes,
  145.    VoteMessage = Radar.Config.VoteMessage,
  146.    RevokeMessage = Radar.Config.RevokeMessage,
  147.    SaveLoc = Radar.Config.SaveLoc,
  148.    ConfigLoc = Radar.Config.ConfigLog
  149.  
  150. }
  151.  
  152. if not file.Exists( Radar.Config.Dir, "DATA" ) then
  153.  
  154.    file.CreateDir( Radar.Config.Dir )
  155.  
  156. end
  157.  
  158. if not file.Exists( Radar.Config.ConfigLoc, "DATA" ) then
  159.  
  160.    file.Write( Radar.Config.ConfigLoc, util.TableToJSON( RadarActualConfig ) )
  161.  
  162. end
  163.  
  164. if Radar.Config.Enable then
  165.  
  166.  
  167.     MsgN( "Give Radar finished loading successfully!" )
  168.  
  169.  
  170. else
  171.  
  172.  
  173.     MsgN( "Give Radar is disabled. Change 'Radar.Config.Enable' to 'true' in 'lua/autorun/sh_config.lua' to enable." )
  174.  
  175.  
  176. end

lua/giveradar/giveradar.lua:
Code: Lua
  1. include( "autorun/sh_config.lua" )
  2.  
  3. Radar = Radar or {} -- DO NOT CHANGE THESE OR IT WILL BREAK
  4. Radar.Config = Radar.Config or {}
  5.  
  6. if not Radar.Config.Enable then return end -- No need to run this if Give Radar is disabled.
  7. if not Radar.Enable then return end -- Just a double-check to make sure it doesn't run.
  8.  
  9.  -- These are where the default chat commands are set up. Not currently integrated to ULX.
  10. Radar.VoteCommands = {
  11.  
  12.    "!giveradar",
  13.    "!voteradar",
  14.    "/giveradar",
  15.    "/voteradar"
  16.  
  17. }
  18.  
  19. Radar.RevokeCommands = {
  20.  
  21.    "!revoke",
  22.    "/revoke",
  23.    "!revokeradar",
  24.    "/revokeradar"
  25.  
  26. }
  27.  
  28. Radar.TotalVotes = 0
  29. Radar.Wait = 20 -- The time in seconds the player needs to wait before revoking his vote to prevent chat spam.
  30. Radar._Wait = CurTime() + Radar.Wait
  31. Radar.Given = false -- Global bool, basically every round the radar isn't given.
  32.  
  33. -- Set up config again just in-case.
  34.  
  35. Radar.MinPlys = Radar.Config.MinPlys or 5
  36. Radar.UseVotesOverPercent = Radar.Config.UseVotesOverPercent or false
  37. Radar.MinPercent = Radar.Config.MinPercent or 0.66
  38. Radar.MinVotes = Radar.Config.MinVotes or 10
  39. Radar.VoteMessage = Radar.Config.VoteMessage or " voted to give Traitors a Radar."
  40. Radar.RevokeMessage = Radar.Config.RevokeMessage or " revoked their vote to give Traitors a Radar."
  41.  
  42. if not Radar.UseVotesOverPercent then
  43.  
  44.    function Radar.ShouldGive()
  45.  
  46.       if Radar.TotalVotes >= math.Round( #player.GetAll() * Radar.MinPercent ) then
  47.  
  48.          return true
  49.  
  50.       end
  51.      
  52.       return false
  53.  
  54.    end
  55.  
  56.    function Radar.GiveRadar()
  57.  
  58.       for k,v in pairs( player.GetAll() ) do
  59.  
  60.          if v:IsActiveTraitor() then
  61.  
  62.             v:Give( EQUIP_RADAR )
  63.             PrintMessage( HUD_PRINTTALK, "Vote passed: Traitors have been given a Radar." )
  64.  
  65.          end
  66.          
  67.       end
  68.  
  69.       Radar.Given = true
  70.      
  71.    end
  72.  
  73.    function Radar.CanVote( ply )
  74.  
  75.       local players = table.Count( player.GetAll() )
  76.  
  77.       if ply.Voted then
  78.  
  79.          return false, "You've already voted."
  80.  
  81.       elseif Radar._Wait >= CurTime() then
  82.  
  83.          return false, "You must wait a few more seconds before you can vote again"
  84.  
  85.       elseif Radar.Given then
  86.  
  87.          return false, "Traitors have already been given a Radar."
  88.  
  89.       elseif players < RTV.MinPlys then
  90.  
  91.          return false, "You need at least " .. RTV.MinPlys .. " players to vote."
  92.  
  93.       end
  94.      
  95.       return true
  96.  
  97.    end
  98.  
  99.    function Radar.AddVote( ply )
  100.  
  101.       if Radar.CanVote( ply ) then
  102.  
  103.          Radar.TotalVotes = Radar.TotalVotes + 1
  104.          ply.Voted = true
  105.          MsgN( ply:Nick() .. Radar.VoteMessage )
  106.          PrintMessage( HUD_PRINTTALK, ply:Nick() .. Radar.VoteMessage .. "(" .. Radar.TotalVotes .. "/" .. math.Round( #player.GetAll() * Radar.MinPercent ) .. ")" )
  107.  
  108.          if Radar.ShouldGive() then
  109.  
  110.             Radar.GiveRadar()
  111.  
  112.          end
  113.      
  114.       end
  115.      
  116.    end
  117.  
  118.    function Radar.RemoveVote( ply )
  119.  
  120.       Radar.TotalVotes = Radar.TotalVoles - 1
  121.       ply.Voted = false
  122.       MsgN( ply:Nick() .. Radar.RevokeMessage )
  123.       PrintMessage( HUD_PRINTTALK, ply:Nick() .. Radar.RevokeMessage .. "(" .. Radar.TotalVotes .. "/" .. math.Round( #player.GetAll() * Radar.MinPercent ) .. ")" )
  124.  
  125.       if Radar.ShouldGive() then
  126.      
  127.          Radar.GiveRadar()
  128.  
  129.       end
  130.  
  131.    end
  132.    hook.Add( "PlayerDisconnected", "Radar.RemoveVote", Radar.RemoveVote )
  133.  
  134.    function Radar.StartRemove( ply )
  135.    
  136.       if not ply.Voted then
  137.    
  138.          ply:PrintMessage( HUD_PRINTTALK, "You have not voted yet." )
  139.    
  140.       else
  141.    
  142.          Radar.RemoveVote( ply )
  143.    
  144.       end
  145.    
  146.    end
  147.    
  148.    function Radar.StartVote( ply )
  149.    
  150.       local can, err = Radar.CanVote( ply )
  151.    
  152.       if not can then
  153.    
  154.          ply:PrintMessage( HUD_PRINTTALK, err )
  155.          return
  156.    
  157.       end
  158.      
  159.       Radar.AddVote( ply )
  160.    
  161.    end
  162.    
  163.    concommand.Add( "give_radar", Radar.StartVote )
  164.    
  165.    function ChatCommandsCheck( ply, text )
  166.    
  167.       if table.HasValue( Radar.VoteCommands, string.lower( text ) ) then
  168.  
  169.          Radar.StartVote( ply )
  170.    
  171.       end
  172.    
  173.       if table.HasValue( Radar.RevokeCommands, string.lower( text ) ) then
  174.    
  175.          Radar.StartRemove( ply )
  176.    
  177.       end
  178.          
  179.    end
  180.    hook.Add( "PlayerSay", "ChatCommandsCheck", ChatCommandsCheck )
  181.  
  182. else
  183.  
  184.    function Radar.ShouldGive()
  185.  
  186.       if Radar.TotalVotes >= Radar.MinVotes then
  187.  
  188.          return true
  189.  
  190.       end
  191.      
  192.       return false
  193.  
  194.    end
  195.    
  196.    function Radar.GiveRadar()
  197.  
  198.       for k,v in pairs( player.GetAll() ) do
  199.  
  200.          if v:IsActiveTraitor() then
  201.  
  202.             v:Give( EQUIP_RADAR )
  203.  
  204.          end
  205.          
  206.       end
  207.  
  208.       Radar.Given = true
  209.      
  210.    end
  211.  
  212.    function Radar.CanVote( ply )
  213.  
  214.       local players = table.Count( player.GetAll() )
  215.  
  216.       if ply.Voted then
  217.  
  218.          return false, "You've already voted."
  219.  
  220.       elseif Radar._Wait >= CurTime() then
  221.  
  222.          return false, "You must wait a few more seconds before you can vote again"
  223.  
  224.       elseif Radar.Given then
  225.  
  226.          return false, "Traitors have already been given a Radar."
  227.  
  228.       elseif players < RTV.MinPlys then
  229.  
  230.          return false, "You need at least " .. RTV.MinPlys .. " players to vote."
  231.  
  232.       end
  233.      
  234.       return true
  235.  
  236.    end
  237.  
  238.    function Radar.AddVote( ply )
  239.  
  240.       if Radar.CanVote( ply ) then
  241.  
  242.          Radar.TotalVotes = Radar.TotalVotes + 1
  243.          ply.Voted = true
  244.          MsgN( ply:Nick() .. Radar.VoteMessage )
  245.          PrintMessage( HUD_PRINTTALK, ply:Nick() .. Radar.VoteMessage .. "(" .. Radar.TotalVotes .. "/" .. math.Round( #player.GetAll() * Radar.MinVotes ) .. ")" )
  246.  
  247.          if Radar.ShouldGive() then
  248.  
  249.             Radar.GiveRadar()
  250.  
  251.          end
  252.      
  253.       end
  254.      
  255.    end
  256.  
  257.    function Radar.RemoveVote( ply )
  258.  
  259.       Radar.TotalVotes = math.Clamp( Radar.TotalVotes - 1, 0, math.huge )
  260.       ply.Voted = false
  261.       MsgN( ply:Nick() .. Radar.RevokeMessage )
  262.       PrintMessage( HUD_PRINTTALK, ply:Nick() .. Radar.RevokeMessage .. "(" .. Radar.TotalVotes .. "/" .. math.Round( #player.GetAll() * Radar.MinVotes ) .. ")" )
  263.  
  264.       if Radar.ShouldGive() then
  265.      
  266.          Radar.GiveRadar()
  267.  
  268.       end
  269.  
  270.    end
  271.    hook.Add( "PlayerDisconnected", "Radar.RemoveVote", Radar.RemoveVote )
  272.    
  273.    function Radar.StartRemove( ply )
  274.    
  275.       if not ply.Voted then
  276.    
  277.          ply:PrintMessage( HUD_PRINTTALK, "You have not voted yet." )
  278.    
  279.       else
  280.    
  281.          Radar.RemoveVote( ply )
  282.    
  283.       end
  284.    
  285.    end
  286.  
  287.    function Radar.StartVote( ply )
  288.    
  289.       local can, err = Radar.CanVote( ply )
  290.    
  291.       if not can then
  292.    
  293.          ply:PrintMessage( HUD_PRINTTALK, err )
  294.          return
  295.    
  296.       end
  297.      
  298.       Radar.AddVote( ply )
  299.    
  300.    end
  301.    concommand.Add( "vote_radar", Radar.StartVote )
  302.    
  303.    function ChatCommandsCheck( ply, text )
  304.    
  305.       if table.HasValue( Radar.VoteCommands, string.lower( text ) ) then
  306.  
  307.          Radar.StartVote( ply )
  308.    
  309.       end
  310.    
  311.       if table.HasValue( Radar.RevokeCommands, string.lower( text ) ) then
  312.    
  313.          Radar.StartRemove( ply )
  314.    
  315.       end
  316.          
  317.    end
  318.    hook.Add( "PlayerSay", "ChatCommandsCheck", ChatCommandsCheck )
  319.  
  320. end
  321.  
  322. function Radar.Restore()
  323.  
  324.    Radar.Given = false
  325.    for k,v in pairs( player.GetAll() ) do
  326.  
  327.       if v.Voted then
  328.  
  329.          v.Voted = false
  330.  
  331.       end
  332.      
  333.    end
  334.    MsgN( "End of round detected. Give radar votes have been reset." )
  335.  
  336. end
  337. hook.Add( "TTTEndRound", "Radar.Restore", Radar.Restore )
« Last Edit: November 15, 2016, 07:32:16 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print