Ready Vote System

I’m requesting assistance on creating something that calculates how many people are on the server and when 3/4 of the people type /ready, it changes plpldamage to 1. After it is set to 1, it resets the votes back to 0. When the “war (I’m currently developing a gamemode)” is over, people type /over and it sets plpldamage back to 0 and when the vote is successful, it resets those votes as well and changes the map. Thanks!

-Jeff223

[lua]local ready = {}
hook.Add(“PlayerChat”,“War”,function(ply,text,toall)
if string.sub(text,1,6) == “/ready” then
if table.HasValue(ready,ply:SteamID()) then ply:ChatPrint(“You already confirmed you’re ready.”) return end
table.insert(ready,ply:SteamID())
if table.Count(ready) >= math.round(MaxPlayers()*.75) then
game.ConsoleCommand("sbox_plpldamage 1
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“War has started!”) end
end
elseif string.sub(text,1,5) == “/over” then
if table.HasValue(ready,ply:SteamID()) then
local players = {]
for _,v in ipairs(ready) do if v != ply:SteamID() then table.insert(players,v) end end
ready = players
if table.Count(ready) == 0 then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“War has ended.”) end
end
end
end
end)[/lua]

That’s a basic outline that you’d put in your /autorun/server. A few things…

When do you want war to be over? When everyone agrees?
What map do you want to change to?

When do you want war to be over? When 3/4 of the players type /over.

[editline]02:32AM[/editline]

So they’re basically agreeing that the map is over

[editline]02:34AM[/editline]

And I want it to say like “War has ended” then after about 10 seconds the map resets. The map that I will be using hasn’t been created yet. Just put an example map in there.

PS: Thank you so much for your quick response!

I have placed it in lua/autorun/server and it doesn’t work. It doesn’t even download to the client. Any help?

Sorry, I made that in like 10 minutes last night so there’s a few errors (i.e. it’s PlayerSay, not PlayerChat). Here’s an updated version…

[lua]local ready = {}
local over = {}
hook.Add(“PlayerSay”,“War”,function(ply,text,toall)
if string.sub(text,1,6) == “/ready” then
if GetConVarNumber(“sbox_plpldamage”) == 1 then ply:ChatPrint(“War has already started!”) return end
if table.HasValue(ready,ply:SteamID()) then ply:ChatPrint(“You already confirmed you’re ready.”) return end
table.insert(ready,ply:SteamID())
if table.Count(ready) >= math.Round(MaxPlayers()*0.75) then
game.ConsoleCommand("sbox_plpldamage 1
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“War has started!”) end
local ready = {}
local over = {}
end
elseif string.sub(text,1,5) == “/over” then
if GetConVarNumber(“sbox_plpldamage”) == 0 then ply:ChatPrint(“War is already over.”) return end
if table.HasValue(over,ply:SteamID()) then ply:ChatPrint(“You already confirmed you want war to end.”) return end
if table.Count(over) >= math.Round(MaxPlayers()*0.75) then
game.ConsoleCommand("sbox_plpldamage 0
")
for _,v in ipairs(player.GetAll()) do v:ChatPrint(“War has ended.”) end
local ready = {}
local over = {}
end
else return text end
end)[/lua]

Still goes in /autorun/server. It’s not supposed to download to the client, as it’s a serverside script.

It basically works, but when I type /ready (as being one person in the server), it doesn’t enable damage and say “The war has started”. Also, I was hoping to have something in there that would be somthing like this:
[lua]if not table.HasValue(ready,ply:SteamID()) then ply:ChatPrint(“You have voted to start the round.”) return end[/lua]

[editline]02:01PM[/editline]

I don’t know if it would be if not or what, but I can’t find an object command to say something like DoesNotHaveValue, so I thought it might be if not. Thanks!

  • Jeff223

That line you’ve got there looks fine Jeff, that’s what it should be due to the order everything is in.

Also, line 8, which has the table.count function should look like this:

[lua]if table.Count(ready) >= math.Round(table.Count(player.GetAll())*0.75) then[/lua]

Line 17 should look like this:

[lua]if table.Count(over) >= math.Round(table.Count(player.GetAll())*0.75) then [/lua]

Okay, I have edited it to how I would like it, but it doesn’t really work. Could you fix it? Thanks!:

[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]

Hi, I am Andres Kramack from http://www.cathybarryadultstore.com/.

It’s a ‘pleasure’ serving the public if you know what I mean and this message is

Here at Cathy Barry Adult Store, we offer a wide variety of dildos that come in all sizes from goblin-sized dicks to black-man draconic dicks. I know at Facepunch everyone loves good old dicks which is why I personally offer anyone with an association with Facepunch Forums a 50% discount code “DIL4FACEPUNCH”. Don’t forget, this offer lasts until the next Garry’s Mod update which we so much love.

Here are pictures of our products just for you!

Sponsored Images:

http://static.fjcdn.com/pictures/Gym+leaders+hate+him_ab471d_5017861.jpg

https://static.fjcdn.com/comments/That+one+with+the+lamp+got+me+_e68beb19422eea14289caa5f4d6dffb7.jpg

Got any questions? Visit my Steam Profile!