I need someone to fix my RockTheVote code please, PlayerSay hook doesn't work

Hello,
I’m noob in Lua, and desperately I tried many times to edit the code of my script without any results (and many lots of errors too). I didn’t made this RTV script myself, but one time it worked and I don’t know why now it doesn’t work.

I’d like to ask to someone here if he can help me to fix it. I deliver you the client and server script of my RockTheVote script.

In fact, the problem is PlayerSay hook. I removed these two files and added a simple PlayerSay hook and it worked. So I’m sure it’s these files who cause problems.

Please, help me and then I’d give you 5$ in reward from Paypal if the RTV script work again :D. Just that for something I tried from a month now to fix every day (honestly)…

Here is the code:

CLIENT SIDE:
[lua]require(“datastream”)

local Maps= {}
local NoMaps = {}
local Voted = false
local Nominate = false
local MapList = {}
local LastVote = “”
local DFrame

function MapsHook( handle, id, encoded, decoded )
for k, v in pairs(decoded[1]) do
Maps[k] = v
end
for k, v in pairs(decoded[2]) do
NoMaps[k] = v
end
end

datastream.Hook( “MapsHook”, MapsHook)

function RTVHud()
if Voted == true then
draw.RoundedBox( 6, -10, ScrH()/2-10, 255, 20, Color( 50, 10, 10, 150 ) )
draw.SimpleTextOutlined(“Press F4 to open your voting menu.”, “ScoreboardText”, 10, ScrH()/2, Color(0,0,0,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, 1, Color(255,255,255,255))
elseif Nominate == true then
draw.RoundedBox( 6, -10, ScrH()/2-10, 275, 20, Color( 50, 10, 10, 150 ) )
draw.SimpleTextOutlined(“Press F4 to open your nominate menu.”, “ScoreboardText”, 10, ScrH()/2, Color(0,0,0,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, 1, Color(255,255,255,255))
end
end

hook.Add(“HUDPaint”, “RTVHudHook”, RTVHud)

function RTVHook( handle, id, encoded, decoded )
Nominate = false
LastVote = “”
if ValidPanel(DFrame) then
DFrame:SetVisible(false)
DFrame:Remove()
end
if Voted == false then
Voted = true
for k, v in pairs(decoded) do
MapList[k] = v
end
else
Voted = false
end
end

datastream.Hook( “RTVHook”, RTVHook )

function NominateHook( handle, id, encoded, decoded )
Nominate = true
end

datastream.Hook( “NominateHook”, NominateHook )

function F4Hook( handle, id, encoded, decoded )
if Voted == true then
CreateRTVDerma()
elseif Nominate == true then
CreateNominateDerma()
end
end

datastream.Hook( “F4Hook”, F4Hook )

function CreateRTVDerma()
local Next
local Previous

DFrame = vgui.Create( "DFrame" )
DFrame:SetSize( 300,400 )
DFrame:SetPos( 30, 30 )
DFrame:SetTitle( "Rock The Vote" )
DFrame:MakePopup()

local Grid = vgui.Create( "DGrid", DFrame )
Grid:SetPos( 10, 50 )
Grid:SetCols( 1 )
Grid:SetColWide( 280 )

for k, v in pairs(MapList) do
	local Button = vgui.Create( "DButton", Grid )
	Button:SetSize( 280, 30 )
	Button:SetText( v )
	Button.DoClick = function( Button )
		local Changed = false
		if LastVote != "" then
			Changed = true
			datastream.StreamToServer( "LastMap", {LastVote})
		end
		LastVote = v
		datastream.StreamToServer( "SendVote", {LastVote, Changed})
		if ValidPanel(DFrame) then
			DFrame:SetVisible(false)
			DFrame:Remove()
		end
		if Changed == false then
			LocalPlayer():ChatPrint("ROCKTHEVOTE You have voted for "..LastVote..".")
		else
			LocalPlayer():ChatPrint("ROCKTHEVOTE You have changed your vote to "..LastVote..".")
		end
	end
	Grid:AddItem( Button )
end

local Button2 = vgui.Create( "DButton", Grid )
Button2:SetSize( 280, 30 )
Button2:SetText( "Close" )
Button2.DoClick = function( Button2 )
	if ValidPanel(DFrame) then
		DFrame:SetVisible(false)
		DFrame:Remove()
	end
end
Grid:AddItem( Button2 )

end

function CreateNominateDerma()
local Page = 1

DFrame = vgui.Create( "DFrame" )
DFrame:SetSize( 300,400 )
DFrame:SetPos( 30, 30 )
DFrame:SetTitle( "Nominate" )
DFrame:ShowCloseButton(false)
DFrame:MakePopup()

local Grid = vgui.Create( "DGrid", DFrame )
Grid:SetPos( 10, 50 )
Grid:SetCols( 1 )
Grid:SetColWide( 280 )

local TextEntry = vgui.Create("DTextEntry", DFrame)
TextEntry:SetText("")
TextEntry:SetPos(10, 30)
TextEntry:SetWide(280)
TextEntry.OnEnter = function()
	local Found
	local Stop = false
	local No = false
	for k, v in pairs(Maps) do
		if string.find(string.Trim(string.lower(v)), string.Trim(string.lower(TextEntry:GetValue()))) and Found == nil and !table.HasValue(NoMaps, v) then
			Found = v
		elseif string.find(string.Trim(string.lower(v)), string.Trim(string.lower(TextEntry:GetValue()))) and Found == nil and table.HasValue(NoMaps, v) then
			Found = v
			No = true
		elseif string.find(v, string.Trim(string.lower(TextEntry:GetValue()))) and Found != nil then
			Stop = true
			break
		end
	end
	if Found != nil and Stop == false and No == false then
		local Changed = false
		if LastVote != "" then
			Changed = true
			datastream.StreamToServer( "LastNominate", {LastVote})
		end
		LastVote = Found
		datastream.StreamToServer( "SendNominate", {LastVote, Changed})
		if ValidPanel(DFrame) then
			DFrame:SetVisible(false)
			DFrame:Remove()
		end
		Nominate = false
	elseif Found == nil then
		LocalPlayer():ChatPrint("ROCKTHEVOTE That is not a valid map.")
	elseif Stop == true then
		LocalPlayer():ChatPrint("ROCKTHEVOTE There are multiple maps with that name.")
	elseif No == true then
		LocalPlayer():ChatPrint("ROCKTHEVOTE That map has been played recently.")
	end
end

local Button1 = vgui.Create( "DButton", Grid )
Button1:SetSize( 280, 30 )
Button1:SetText( "Nominate Above Text" )
Button1.DoClick = function( Button1 )
	local Found
	local Stop = false
	local No = false
	for k, v in pairs(Maps) do
		if string.find(string.Trim(string.lower(v)), string.Trim(string.lower(TextEntry:GetValue()))) and Found == nil and !table.HasValue(NoMaps, v) then
			Found = v
		elseif string.find(string.Trim(string.lower(v)), string.Trim(string.lower(TextEntry:GetValue()))) and Found == nil and table.HasValue(NoMaps, v) then
			Found = v
			No = true
		elseif string.find(v, string.Trim(string.lower(TextEntry:GetValue()))) and Found != nil then
			Stop = true
			break
		end
	end
	if Found != nil and Stop == false and No == false then
		local Changed = false
		if LastVote != "" then
			Changed = true
			datastream.StreamToServer( "LastNominate", {LastVote})
		end
		LastVote = Found
		datastream.StreamToServer( "SendNominate", {LastVote, Changed})
		if ValidPanel(DFrame) then
			DFrame:SetVisible(false)
			DFrame:Remove()
		end
		Nominate = false
	elseif Found == nil then
		LocalPlayer():ChatPrint("ROCKTHEVOTE That is not a valid map.")
	elseif Stop == true then
		LocalPlayer():ChatPrint("ROCKTHEVOTE There are multiple maps with that name.")
	elseif No == true then
		LocalPlayer():ChatPrint("ROCKTHEVOTE That map has been played recently.")
	end
end
Grid:AddItem( Button1 )

local ButtonList = {}
for i = 1, 5 do
	ButtonList* = vgui.Create( "DButton", Grid )
	ButtonList*:SetSize( 280, 30 )
	ButtonList*:SetText( Maps[i+5*(Page-1)] )
	if table.HasValue(NoMaps, Maps[i+5*(Page-1)]) then
		ButtonList*:SetDisabled(true)
	end
	ButtonList*.DoClick = function(  )
		local Changed = false
		if LastVote != "" then
			Changed = true
			datastream.StreamToServer( "LastNominate", {LastVote})
		end
		LastVote = Maps[i+5*(Page-1)]
		datastream.StreamToServer( "SendNominate", {LastVote, Changed})
		if ValidPanel(DFrame) then
			DFrame:SetVisible(false)
			DFrame:Remove()
		end
		Nominate = false
	end
	Grid:AddItem( ButtonList* )
end

Next = vgui.Create( "DButton", Grid )
Next:SetSize( 280, 30 )
Next:SetText( "Next" )
Next.DoClick = function( Next )
	Page = Page + 1
	Previous:SetDisabled(false)
	for i = 1, 5 do
		if Maps[i+5*(Page-1)] != nil then
			ButtonList*:SetText( Maps[i+5*(Page-1)] )
			ButtonList*:SetDisabled(false)
			if table.HasValue(NoMaps, Maps[i+5*(Page-1)]) then
				ButtonList*:SetDisabled(true)
			end
			ButtonList*.DoClick = function(  )
				local Changed = false
				if LastVote != "" then
					Changed = true
					datastream.StreamToServer( "LastNominate", {LastVote})
				end
				LastVote = Maps[i+5*(Page-1)]
				datastream.StreamToServer( "SendNominate", {LastVote, Changed})
				if ValidPanel(DFrame) then
					DFrame:SetVisible(false)
					DFrame:Remove()
				end
				Nominate = false
			end
		else
			ButtonList*:SetText( "" )
			ButtonList*:SetDisabled(true)
			Next:SetDisabled(true)
		end
	end
end
Grid:AddItem( Next )

Previous = vgui.Create( "DButton", Grid )
Previous:SetSize( 280, 30 )
Previous:SetText( "Previous" )
Previous:SetDisabled(true)
Previous.DoClick = function( Previous )
	Page = Page - 1
	if Page == 1 then
		Previous:SetDisabled(true)
	end
	Next:SetDisabled(false)
	for i = 1, 5 do
		ButtonList*:SetText( Maps[i+5*(Page-1)] )
		ButtonList*:SetDisabled(false)
		if table.HasValue(NoMaps, Maps[i+5*(Page-1)]) then
			ButtonList*:SetDisabled(true)
		end
		ButtonList*.DoClick = function(  )
			local Changed = false
			if LastVote != "" then
				Changed = true
				datastream.StreamToServer( "LastNominate", {LastVote})
			end
			LastVote = Maps[i+5*(Page-1)]
			datastream.StreamToServer( "SendNominate", {LastVote, Changed})
			if ValidPanel(DFrame) then
				DFrame:SetVisible(false)
				DFrame:Remove()
			end
			Nominate = false
		end
	end
end
Grid:AddItem( Previous )

local Button2 = vgui.Create( "DButton", Grid )
Button2:SetSize( 280, 30 )
Button2:SetText( "Close" )
Button2.DoClick = function( Button2 )
	if ValidPanel(DFrame) then
		DFrame:SetVisible(false)
		DFrame:Remove()
	end
	Nominate = false
end
Grid:AddItem( Button2 )

end

datastream.Hook(“IncomingHook”, function() end)

[/lua]

SERVER SIDE:
[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("
“, NoMapString)
table.insert(NoMaps, game.GetMap())
if table.Count(NoMaps) == 6 then
table.remove(NoMaps, 1)
end
NoMapString = string.Implode(”
", NoMaps)
file.Write(“nomaps.txt”, NoMapString)

local MapString = file.Read("…/mapfile.txt")
local Maps = string.Explode("
", 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
")
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
pl:GetNWBool(“cantype”) == false then
return “”
else
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(PlNumRTVVar: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
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
")
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
")
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]

Thanks you so much for taking care of this thread!

no errors supplied( if there is any)
you’re using datastream, don’t.
way overcomplicated.

nobody is going to look through this wall of ridiculousness unless you give any errors, speaking for… basically everyone.

Here’s a fix, stop using datastream.