• RTV function
    7 replies, posted
I have this RTV function here, but the only problem is that when I, or any other player says rtv, it doesn't work like it's supposed to. I've been at it for quite a while and I was wondering if anyone knew what the problem is. Much appreciation. Also: There are no errors upon using the command, but upon server entry is says something about a NULL entity. [lua] require("datastream") IncludeClientFile("autorun/client/cl_rtv.lua") RTVVar = CreateConVar( "rtv_percentage", "0.6", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) if !file.Exists("nomaps.txt") then file.Write("nomaps.txt", "clue") end local NoMapString = file.Read("nomaps.txt") local NoMaps = string.Explode("\n", NoMapString) table.insert(NoMaps, game.GetMap()) if table.Count(NoMaps) == 6 then table.remove(NoMaps, 1) end NoMapString = string.Implode("\n", NoMaps) file.Write("nomaps.txt", NoMapString) local MapString = file.Read("../mapfile.txt") local Maps = string.Explode("\n", MapString) local Voted = false local VoteNum = 0 local MapVotes = {} local MapList = {} local PlayerVotes = {} local CanVote = false local NextMap timer.Simple(120, function() CanVote = true end) timer.Simple(1200, function() for k, v in pairs(player.GetAll()) do v:ChatPrint("ROCKTHEVOTE Map vote in 5 minutes.") end timer.Simple(300, function() if Voted == false then StartVote() end end) timer.Simple(500, function() game.ConsoleCommand("changegamemode mg_canal_smash_b2 minigame\n") end) end) function SendMaps( pl ) datastream.StreamToClients( pl, "MapsHook", {Maps, NoMaps} ) if Voted == true then table.insert(PlayerVotes, pl:SteamID()) pl:ChatPrint("ROCKTHEVOTE Starting voting process...") datastream.StreamToClients( pl, "RTVHook", MapList ) end end hook.Add( "PlayerInitialSpawn", "SendMapsHook", SendMaps ) function RTV( pl, text, team, death ) if string.Trim(string.lower(text)) == "rtv" then if CanVote == true then local PlNum = 0 for k, v in pairs(player.GetAll()) do PlNum = PlNum +1 end if !table.HasValue(PlayerVotes, pl:SteamID()) and Voted == false then VoteNum = VoteNum + 1 table.insert(PlayerVotes, pl:SteamID()) for k, v in pairs(player.GetAll()) do v:ChatPrint("ROCKTHEVOTE "..pl:Nick().." has voted to change map. ("..VoteNum.." votes, "..math.ceil(PlNum*RTVVar:GetFloat()).." required)") end if VoteNum >= PlNum*RTVVar:GetFloat() and Voted == false then StartVote() end elseif table.HasValue(PlayerVotes, pl:SteamID()) and Voted == false then pl:ChatPrint("ROCKTHEVOTE You have already voted. ("..VoteNum.." votes, "..math.ceil(PlNum*RTVVar:GetFloat()).." required)") elseif Voted == true then pl:ChatPrint("ROCKTHEVOTE There has already been a map vote.") end else pl:ChatPrint("ROCKTHEVOTE Voting is protected for the first 120 seconds.") end elseif string.Trim(string.lower(text)) == "nominate" then if Voted == false then datastream.StreamToClients( pl, "NominateHook", {} ) else pl:ChatPrint("ROCKTHEVOTE There has already been a map vote.") end elseif string.Trim(string.lower(text)) == "timeleft" then pl:ChatPrint("ROCKTHEVOTE "..tostring(math.floor(2500-CurTime())).." seconds until map vote") end end hook.Add( "PlayerSay", "RTV", RTV ) function StartVote() if !timer.IsTimer("votetimer") then timer.Create("votetimer", 30, 1, ChangeMap) end while table.Count(MapList) < 7 do local num= math.random(1, table.Count(Maps)) while table.HasValue(MapList, Maps[num]) or table.HasValue(NoMaps, Maps[num]) do num = math.random(1, table.Count(Maps)) end table.insert(MapList, Maps[num]) end for k, v in pairs(player.GetAll()) do table.insert(PlayerVotes, v:SteamID()) v:ChatPrint("ROCKTHEVOTE Starting voting process...") datastream.StreamToClients( v, "RTVHook", MapList ) end Voted = true end function SendF4( pl ) datastream.StreamToClients( pl,"F4Hook", {} ) end hook.Add("ShowSpare2", "SendF4Hook", SendF4) function LastMap( pl, handler, id, encoded, decoded ) MapVotes[decoded[1]] = MapVotes[decoded[1]]-1 end datastream.Hook( "LastMap", LastMap ) function SendVote( pl, handler, id, encoded, decoded ) if MapVotes[decoded[1]] == nil then MapVotes[decoded[1]] = 0 end MapVotes[decoded[1]] = MapVotes[decoded[1]]+1 print(pl:Nick().." voted for "..decoded[1]) if decoded[2] == true then for k, v in pairs(player.GetAll()) do v:PrintMessage(HUD_PRINTCONSOLE, pl:Nick().." changed his vote to "..decoded[1]) end else for k, v in pairs(player.GetAll()) do v:PrintMessage(HUD_PRINTCONSOLE, pl:Nick().." voted for "..decoded[1]) end end end datastream.Hook( "SendVote",SendVote ) function LastNominate( pl, handler, id, encoded, decoded ) local x = 0 for k, v in pairs(MapList) do if v == decoded[1] then x = k end end table.remove(MapList, x) end datastream.Hook( "LastNominate", LastNominate ) function SendNominate( pl, handler, id, encoded, decoded ) if !table.HasValue(MapList, decoded[1]) then if table.Count(MapList) <7 then table.insert(MapList, decoded[1]) for k, v in pairs(player.GetAll()) do if decoded[2] == false then v:ChatPrint("ROCKTHEVOTE "..pl:Nick().." has nominated "..decoded[1]) else v:ChatPrint("ROCKTHEVOTE "..pl:Nick().." changed his nomination to "..decoded[1]) end end else pl:ChatPrint("ROCKTHEVOTE There are already 7 nominated maps.") end else pl:ChatPrint("ROCKTHEVOTE This map has already been nominated.") end end datastream.Hook( "SendNominate",SendNominate ) function ChangeMap() local PlNum = 0 for k, v in pairs(player.GetAll()) do PlNum = PlNum +1 end if table.GetWinningKey(MapVotes) != nil then NextMap = table.GetWinningKey(MapVotes) for k, v in pairs(player.GetAll()) do datastream.StreamToClients( v,"RTVHook", MapList ) v:ChatPrint("ROCKTHEVOTE Voting has finished. The next map will be "..NextMap..". Changing in 5 seconds...") end timer.Simple(5, function() game.ConsoleCommand("changegamemode "..NextMap.." minigame\n") end) else NextMap = Maps[1] for k, v in pairs(player.GetAll()) do datastream.StreamToClients( v,"RTVHook", MapList ) v:ChatPrint("ROCKTHEVOTE Voting has finished. The next map will be "..NextMap..". Changing in 5 seconds...") end timer.Simple(5, function() game.ConsoleCommand("changegamemode "..MapList[1].." minigame\n") end) end end function Disconnect(pl) if table.HasValue(PlayerVotes, pl:SteamID()) then VoteNum = VoteNum - 1 for k, v in pairs(PlayerVotes) do if v == pl:SteamID() then table.remove(PlayerVotes, k) end end end local PlNum = 0 for k, v in pairs(player.GetAll()) do if v != pl then PlNum = PlNum +1 end end if VoteNum >= PlNum*RTVVar:GetFloat() then if Voted == false then StartVote() end end end hook.Add("PlayerDisconnected", "Playerdisconn", Disconnect) [/lua]
What do you mean when it doesn't work like its supposed to when someone else rtvs?
Yes, I think there is something wrong with one of the functions. More specifically, This function: [lua] function RTV( pl, text, team, death ) if string.Trim(string.lower(text)) == "rtv" then if CanVote == true then local PlNum = 0 for k, v in pairs(player.GetAll()) do PlNum = PlNum +1 end if !table.HasValue(PlayerVotes, pl:SteamID()) and Voted == false then VoteNum = VoteNum + 1 table.insert(PlayerVotes, pl:SteamID()) for k, v in pairs(player.GetAll()) do v:ChatPrint("ROCKTHEVOTE "..pl:Nick().." has voted to change map. ("..VoteNum.." votes, "..math.ceil(PlNum*RTVVar:GetFloat()).." required)") end if VoteNum >= PlNum*RTVVar:GetFloat() and Voted == false then StartVote() end elseif table.HasValue(PlayerVotes, pl:SteamID()) and Voted == false then pl:ChatPrint("ROCKTHEVOTE You have already voted. ("..VoteNum.." votes, "..math.ceil(PlNum*RTVVar:GetFloat()).." required)") elseif Voted == true then pl:ChatPrint("ROCKTHEVOTE There has already been a map vote.") end else pl:ChatPrint("ROCKTHEVOTE Voting is protected for the first 120 seconds.") end elseif string.Trim(string.lower(text)) == "nominate" then if Voted == false then datastream.StreamToClients( pl, "NominateHook", {} ) else pl:ChatPrint("ROCKTHEVOTE There has already been a map vote.") end elseif string.Trim(string.lower(text)) == "timeleft" then pl:ChatPrint("ROCKTHEVOTE "..tostring(math.floor(2500-CurTime())).." seconds until map vote") end end hook.Add( "PlayerSay", "RTV", RTV ) [/lua]
[QUOTE=vegasx;30170701]lots of code with no tabs[/QUOTE] Please, I beg of you, use tabs in your code. It makes it much easier to understand and read, so that we can help you better. Example: [lua]function LastNominate( pl, handler, id, encoded, decoded ) local x = 0 for k, v in pairs(MapList) do if v == decoded[1] then x = k end end table.remove(MapList, x) end[/lua]
Umm, when it says something about a NULL entity, it should also tell you what line had the error, posting that line number helps greatly, also if that's not the entire file tell us which line is the one from the error. So do what CmdrMatthew said and put tabs in and them post the full error as it appears in the console.
[lua]local PlNum = 0 for k, v in pairs(player.GetAll()) do PlNum = PlNum +1 end[/lua] Why would you do that when you can just do this: [lua]local PlNum = #player.GetAll()[/lua]
OP clearly didn't write, thus this is a request.
Also, im not gonna bother looking through that wreck of a script but the chat box if custom could be causing problems.
Sorry, you need to Log In to post a reply to this thread.