I need help making a function that sets the prop limit to 10 when the player amount on my server gets to 8. I was using #player.GetAll but i need help.
Pseudocode here we go:
[code]if playerCount is higher or equal to 8 then
set the prop limit to 8
else
set it to something higher
end
hook to 'whenever a player joins or leaves'
[/code]
[b][url=http://wiki.garrysmod.com/?title=Player.GetAll]Player.GetAll [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], [b][url=http://wiki.garrysmod.com/?title=Hook.Add]Hook.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerConnect]Gamemode.PlayerConnect [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerDisconnected]Gamemode.PlayerDisconnected [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], [url=http://wiki.garrysmod.com/?title=Sbox_maxprops]sbox_maxprops[/url] might help you.
[lua]local PlayerPropInfo = {
1 = "100",
2 = "50",
5 = "10"
}
function PropModifier_PlayerSpawn()
local Count = table.Count(player.GetAll())
for k,v in pairs(PlayerPropInfo) do
if Count == k then
RunConsoleCommand("sbox_maxprops",v)
break
end
end
end
hook.Add("PlayerSpawn","PropModifier_PlayerSpawn",PropModifier_PlayerSpawn)[/lua]
Something like this should work.
[lua]local proplimits = {
1 = "100",
2 = "50",
5 = "10"
}
local function reconsider()
local limit = proplimits[#player.GetAll()];
if (limit) then
RunConsoleCommand("sbox_maxprops", limit);
end
end
hook.Add("PlayerAuthed", "Variable prop limits", reconsider);
hook.Add("PlayerDisconnected", "Variable prop limits", reconsider);[/lua]
[QUOTE=Lexic;26409175]-snip-[/QUOTE]
That won't work with player amounts not in the table. For example, there are five players, one leaves, the limit is still 10.
That will work, it will be set to 50 once there are only 2 players left!
Sorry, you need to Log In to post a reply to this thread.