I have been stuck on what to do for this script i need for my server, I need it to make people auto join another server when the first one is full. For example my server limit is at 26 and i want to have it where once there is 25/26 on it will start to force connect to server #2. This is as far as i got:
[CODE]
if(SERVER) then
ServerLimit = 25
for _,v in pairs(players.GetAll()) do
if v = 25 then
end
end
end
[/CODE]
im not sure what i need to so after this. All help will be appreciated!
Just do if v == #players.GetAll()
Instead of looping through the full list.
Edit:
To get a player to join another server do: ply:SendLua( [[RunConsoleCommand( "connect", "IP" )]] )
[code]
//If you want to do it your way
if(SERVER) then
local i = 0
for _,v in ipairs(players.GetAll()) do
if i == 25 then
(Whatevertheidentifieris):ConCommand("connect [ip]")
local i = 0
else
local i = i + 1
end
end
end
// OR (better way)
if SERVER then
if ( v == #players.GetAll() ) do
(Whatevertheidentifieris):ConCommand("connect [ip]")
end
end
//Both of these ways you'll need to hook it on PlayerInitalSpawn or OnConnect.
[/code]
Not Tested and made in 5 mins
[QUOTE=Exploderguy;47843216][code]
if(SERVER) then
i = 0
for _,v in ipairs(players.GetAll()) do
if i == 25 then
(Whatevertheidentifieris):ConCommand("connect [ip]")
i = 0
else
i = i + 1
end
end
end
[/code]
Not Tested and made in 5 mins[/QUOTE]
1. You cant use concommand to connect to a different server, its blocked.
2. Looping through the list is completely useless.
Don't forget to localize...
If you want it to be clientside
[code]
hook.Add("InitPostEntity", "server_kickjoin", function() --earliest hook where clientside lua has been loaded (i think)
if (#player.GetAll() == 26) then --Since your player is already "connected", 26 here
LocalPlayer():ConCommand("connect iphere")
end
end)
[/code]
I tried playing around making it serverside only, but it's awkward because ConCommand() wasn't initialized on the player entity yet. Neither net messages nor SendLua worked. I managed to make it work with a timer set to 1 delaying the SendLua, but that's bad practice. Just make it clientside.
[QUOTE=Lolcats;47843689]If you want it to be clientside
[code]
hook.Add("InitPostEntity", "server_kickjoin", function() --earliest hook where clientside lua has been loaded (i think)
if (#player.GetAll() == 26) then --Since your player is already "connected", 26 here
LocalPlayer():ConCommand("connect iphere")
end
end)
[/code]
I tried playing around making it serverside only, but it's awkward because ConCommand() wasn't initialized on the player entity yet. Neither net messages nor SendLua worked. I managed to make it work with a timer set to 1 delaying the SendLua, but that's bad practice. Just make it clientside.[/QUOTE]
That's a great idea using it on client side, but again you can't use concommand, only with RunConsoleCommand.
[QUOTE=tzahush;47843725]That's a great idea using it on client side, but again you can't use concommand, only with RunConsoleCommand.[/QUOTE]
ConCommand when called clientside doesn't have connect on the blacklist. Code is fully working, just checked.
[QUOTE=Lolcats;47843733]ConCommand when called clientside doesn't have connect on the blacklist. Code is fully working, just checked.[/QUOTE]
Really?
Thought it was blacklisted in both scenarios, my bad.
Sorry, you need to Log In to post a reply to this thread.