/ready Lua Help

I have had help creating something that where people type /ready they’re basically voting that they’re ready to start the round and when 3/4ths of the server type /ready, it will turn on player damage, etc… I have it how I’d like it, but it’s not really working. Could someone tell me what’s wrong with it. Also, if you know how to, could you make it that when a player has voted, then leaves the server, their vote gets deleted? Thanks! Here it is:

[lua]local ready = {}
local over = {}
hook.Add(“PlayerSay”,“War”,function(ply,text,toall)
if string.sub(text,1,6) == “/ready” then
if not table.HasValue(ready,ply:SteamID()) then
if GetConVarNumber(“sbox_plpldamage”) == 1 then
ply:ChatPrint(“You have voted to start the round.”)
table.insert(ready,ply:SteamID()) return end
if GetConVarNumber(“sbox_plpldamage”) == 0 then ply:ChatPrint(“The round has already started and killing is enabled.”) return end
if table.HasValue(ready,ply:SteamID()) then ply:ChatPrint(“You have already voted to start the round”) return end
if table.Count(ready) >= math.Round(table.Count(player.GetAll())*0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“The round has begun and killing is now enabled.”) end
local ready = {}
local over = {}
end
elseif string.sub(text,1,5) == “/over” then
if not table.HasValue(over,ply:SteamID()) then
if GetConVarNumber(“sbox_plpldamage”) == 0 then
ply:ChatPrint(“You have voted to end the round.”)
table.insert(over,ply:SteamID()) return end
if GetConVarNumber(“sbox_plpldamage”) == 1 then ply:ChatPrint(“The round has already ended and killing is disabled.”) return end
if table.HasValue(over,ply:SteamID()) then ply:ChatPrint(“You have already voted to end the round.”) return end
if table.Count(over) >= math.Round(table.Count(player.GetAll())*0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“The round has ended and killing is now disabled.”) end
local ready = {}
local over = {}
end
else return text end
end)[/lua]

-Jeff223

Is "sbox_plpldamage 0
" this suppose to plpl <- with this extra ‘l’.

Other than that, did you get any errors throughout the console?
If you really can’t get this work, try to put print(‘test’) from major moments and see which one it activates.

[lua]local ready = {}
local over = {}
hook.Add(“PlayerSay”,“War”,function(ply,text,toall)
if string.sub(text,1,6) == “/ready” then
local id = ply:UniqueID()
local var = GetConVarNumber(“sbox_plpldamage”)
if var == 0 then ply:ChatPrint(“The round has already started and killing is enabled.”) return end
if not table.HasValue(ready,id) then
ply:ChatPrint(“You have voted to start the round.”)
ready[id] = id
else ply:ChatPrint(“You have already voted to start the round”) end
if table.Count(ready) >= math.Round(table.Count(player.GetAll())*0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“The round has begun and killing is now enabled.”) end
local ready = {}
local over = {}
end
return
elseif string.sub(text,1,5) == “/over” then
local id = ply:UniqueID()
local var = GetConVarNumber(“sbox_plpldamage”)
if var == 1 then ply:ChatPrint(“The round has already ended and killing is disabled.”) return end
if not table.HasValue(over,id)
ply:ChatPrint(“You have voted to end the round.”)
over[id] = id
else ply:ChatPrint(“You have already voted to end the round.”) end
if table.Count(over) >= math.Round(table.Count(player.GetAll())*0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“The round has ended and killing is now disabled.”) end
local ready = {}
local over = {}
end
return
else return text end
end)

hook.Add(“PlayerDisconnected”,“WarDisconnect”,function(ply)
if ready[id] then table.remove(ready,id) end
if over[id] then table.remove(over,id) end
end)[/lua]

That should fix it.
By the way, the problem was that you always returned before the function could get to the comparing total number of players part, so it could never activate.

edit Kalik, it is “sbox_plpldamage” with two Ls. And the problem was the returns.

Doesn’t work at all. I type /ready and it does nothing.

That explains why I could never turn off plp damage on my game from the game. I always had to type plp and then select the drop down menu…Thanks.

My Shot at this:
[lua]local ready = {}
local over = {}
hook.Add(“PlayerSay”,“War”,function(ply,text,toall)
if string.sub(text,1,6) == “/ready” then
local id = ply:UniqueID()
local var = GetConVarNumber(“sbox_plpldamage”)
if var == 0 then ply:ChatPrint(“The round has already started and killing is enabled.”) return “” end
if not table.HasValue(ready,id) then
ply:ChatPrint(“You have voted to start the round.”)
ready[id] = id
else ply:ChatPrint(“You have already voted to start the round”) return “” end
if table.Count(ready) >= math.Round(table.Count(player.GetAll())*0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“The round has begun and killing is now enabled.”) end
local ready = {}
local over = {}
end
return text
elseif string.sub(text,1,5) == “/over” then
local id = ply:UniqueID()
local var = GetConVarNumber(“sbox_plpldamage”)
if var == 1 then ply:ChatPrint(“The round has already ended and killing is disabled.”) return “” end
if not table.HasValue(over,id)
ply:ChatPrint(“You have voted to end the round.”)
over[id] = id
else ply:ChatPrint(“You have already voted to end the round.”) return “” end
if table.Count(over) >= math.Round(table.Count(player.GetAll())*0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“The round has ended and killing is now disabled.”) end
local ready = {}
local over = {}
end
return “”
else return text end
end)

hook.Add(“PlayerDisconnected”,“WarDisconnect”,function(ply)
if ready[id] then table.remove(ready,id) end
if over[id] then table.remove(over,id) end
end)[/lua]

I don’t know if return “” makes a difference, but if someone know’s please tell me why that WOULDnt work.

It wouldn’t make a difference. It has to be some mistake we missed in the beginning

Add local id = ply:UniqueID() to the top of your disconnect function, or you’ll get errors.
What happens when you say /ready?

Okay, I’ll add that, thanks! And nothing happens when I type /ready.

so you type /ready and get no response, your text not even showing up in the chatbox and no errors in console
or
you type /ready and it acts as if you hadn’t loaded your script by printing ‘jeff223: /ready’ to the chat area?
(You did put your script in a server autorun or loaded it before trying, right?)

Yes, I know how to add it to the server. It worked before, but I made a few changes to it, but it still doesn’t work.

You didn’t answer my question.

Should work, you had a few errors and where confusing keys with variables.

[lua]
local ready = {}
local over = {}

hook.Add(“PlayerSay”, “War”, function(ply,text,toall)
local id = ply:UniqueID()
local var = GetConVarNumber(“sbox_plpldamage”)
local players = player.GetAll()
if string.sub(text,1,6) == “/ready” then
if var == 0 then ply:ChatPrint(“The round has already started and killing is enabled.”) return end
if table.HasValue(ready, id)
ply:ChatPrint(“You have already voted to start the round”)
else
ply:ChatPrint(“You have voted to start the round.”)
table.insert(ready, id)
if #ready >= math.Round(#players0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _, v in pairs(players) do
v:ChatPrint(“The round has begun and killing is now enabled.”)
end
ready = {}
over = {}
end
end
return
elseif string.sub(text,1,5) == “/over” then
if var == 1 then ply:ChatPrint(“The round has already ended and killing is disabled.”) return end
if table.HasValue(over, id)
ply:ChatPrint(“You have already voted to end the round.”)
else
ply:ChatPrint(“You have voted to end the round.”)
table.insert(over, id)
if #over >= math.Round(#players
0.75) then
game.ConsoleCommand("sbox_plpldamage 1
")
for _, v in pairs(players) do
v:ChatPrint(“The round has begun and killing is now enabled.”)
end
ready = {}
over = {}
end
end
else
return text
end
end)

hook.Add(“PlayerDisconnected”, “WarDisconnect”, function(ply)
local id = ply:UniqueID()
if table.HasValue(ready, id) then
table.remove(ready, id)
end
if table.HasValue(over, id) then
table.remove(over, id)
end
end)
[/lua]

Edit:

You might have the numbers mixed around also, player damage will turn off when 3/4 of the server type /ready and the same with /over. If that’s the case then switch the 1’s and 0’s around in lines 9, 16, 26, and 33.

Sorry, you weren’t confusing keys and variables that was the first guy who tried to fix it, I must have copied what he had on accident.

Doesn’t work. I get no response when I type /ready or /over

[editline]01:39PM[/editline]

Sorry Lexic, it acts as if I haven’t even loaded the script.

Type this in console

lua_openscript autorun/server/file.lua

and replace “file” with the filename. Then tell me what error you get. Also, use rcon if it’s a dedicated server.

Oops, looks like we forgot then on line 11:



Running script autorun/server/ready.lua...
autorun/server/ready.lua:11: 'then' expected near 'ply'


[editline]05:24PM[/editline]

And on line 28…

[editline]05:27PM[/editline]

IT WORKS! I need to check the player disconnect thing and then I should be done.
[lua]local ready = {}
local over = {}

hook.Add(“PlayerSay”, “War”, function(ply,text,toall)
local id = ply:UniqueID()
local var = GetConVarNumber(“sbox_plpldamage”)
local players = player.GetAll()
if string.sub(text,1,6) == “/ready” then
if var == 0 then ply:ChatPrint(“The round has already started and killing is enabled.”) return end
if table.HasValue(ready, id) then
ply:ChatPrint(“You have already voted to start the round”)
else
ply:ChatPrint(“You have voted to start the round.”)
table.insert(ready, id)
if #ready >= math.Round(#players0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _, v in pairs(players) do
v:ChatPrint(“The round has begun and killing is now enabled.”)
end
ready = {}
over = {}
end
end
return
elseif string.sub(text,1,5) == “/over” then
if var == 1 then ply:ChatPrint(“The round has already ended and killing is disabled.”) return end
if table.HasValue(over, id) then
ply:ChatPrint(“You have already voted to end the round.”)
else
ply:ChatPrint(“You have voted to end the round.”)
table.insert(over, id)
if #over >= math.Round(#players
0.75) then
game.ConsoleCommand("sbox_plpldamage 1
")
for _, v in pairs(players) do
v:ChatPrint(“The round has ended and killing is now disabled.”)
end
ready = {}
over = {}
end
end
else
return text
end
end)

hook.Add(“PlayerDisconnected”, “WarDisconnect”, function(ply)
local id = ply:UniqueID()
if table.HasValue(ready, id) then
table.remove(ready, id)
end
if table.HasValue(over, id) then
table.remove(over, id)
end
end)[/lua]

-snip

Everything works except the PlayerDisconnect thing. If someone disconnects, it still keeps their vote in there.

[lua] for k,v in ipairs(ready) do
if v = id then
ready[k] = nil
end
end[/lua]
And again for the other.

Uhh, where am I supposed to put this Lexic?

I forgot table.remove() removes by keys, this will work now.

[lua]
local ready = {}
local over = {}

hook.Add(“PlayerSay”, “War”, function(ply,text,toall)
local id = ply:UniqueID()
local var = GetConVarNumber(“sbox_plpldamage”)
local players = player.GetAll()
if string.sub(text,1,6) == “/ready” then
if var == 0 then ply:ChatPrint(“The round has already started and killing is enabled.”) return end
if table.HasValue(ready, id) then
ply:ChatPrint(“You have already voted to start the round”)
else
ply:ChatPrint(“You have voted to start the round.”)
table.insert(ready, id)
if #ready >= math.Round(#players0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _, v in pairs(players) do
v:ChatPrint(“The round has begun and killing is now enabled.”)
end
ready = {}
over = {}
end
end
return
elseif string.sub(text,1,5) == “/over” then
if var == 1 then ply:ChatPrint(“The round has already ended and killing is disabled.”) return end
if table.HasValue(over, id) then
ply:ChatPrint(“You have already voted to end the round.”)
else
ply:ChatPrint(“You have voted to end the round.”)
table.insert(over, id)
if #over >= math.Round(#players
0.75) then
game.ConsoleCommand("sbox_plpldamage 1
")
for _, v in pairs(players) do
v:ChatPrint(“The round has begun and killing is now enabled.”)
end
ready = {}
over = {}
end
end
else
return text
end
end)

hook.Add(“PlayerDisconnected”, “WarDisconnect”, function(ply)
local id = ply:UniqueID()
for k, v in pairs(ready) do
if v == id then
table.remove(ready, k)
end
end
for k, v in pairs(over) do
if v == id then
table.remove(over, k)
end
end
end)
[/lua]