Jump to content

On Player Logout, reconnect him


Benevolence

Recommended Posts

So I want to make it so if the player logs out, it reconnects him to the server. There's a /reconnect command I can just make it triggered if they logout but I'm not sure how so my nooby self decided to do it the hard way and ended up with a non-working code that doesn't do the job.

function joinserverHandlerFunction (playerSource, serverIP, serverPort, serverPassword) 
local serverIP = "69.245.157.67" 
local serverPort = "22003" 
local serverPassword = "confidential" 
    if serverIP and serverPort then --if IP and Port were specified 
        if serverPassword then --if also a password was specified 
            redirectPlayer (playerSource, serverIP, tonumber(serverPort), serverPassword) --redirect the player 
        else -- else if no password was specified 
            redirectPlayer (playerSource, serverIP, tonumber(serverPort))  --redirect the player without using the serverPassword parameter 
        end 
    end 
end 
addEventHandler("onPlayerLogout",getRootElement(),loggedOut) 

Could someone fix this for me or at least give me the efficient-easier code that I want please :idea:

Link to comment

Here try this

-- /ReconnectLG 
function ReconnectLG(thePlayer, commandName, targetPlayer) 
 local port = getServerPort() 
                    local password = getServerPassword() 
                     
                    redirectPlayer(targetPlayer, "69.245.157.67", port, password) 
                     
                  getPlayerName(thePlayer) .." reconnected ".. targetPlayerName , 4) 
                end 
            end 
        end 
    end 
end 
addCommandHandler("reconnectLG", forceReconnect, false, false) 

This might work i havent tested it yet you use the command reconnectLG change it if it works.

Link to comment
Here try this
-- /ReconnectLG 
function ReconnectLG(thePlayer, commandName, targetPlayer) 
 local port = getServerPort() 
                    local password = getServerPassword() 
                     
                    redirectPlayer(targetPlayer, "69.245.157.67", port, password) 
                     
                  getPlayerName(thePlayer) .." reconnected ".. targetPlayerName , 4) 
                end 
            end 
        end 
    end 
end 
addCommandHandler("reconnectLG", forceReconnect, false, false) 

This might work i havent tested it yet you use the command reconnectLG change it if it works.

No but I want it so when a player logs out it automatically reconnects them to the server.

Link to comment

Try and replace the command with this

-- /ReconnectLG 
function forceReconnect(thePlayer, commandName, targetPlayer) 
 local port = getServerPort() 
                    local password = getServerPassword() 
                    
                    redirectPlayer(targetPlayer, "69.245.157.67", port, password) 
                    
                  getPlayerName(thePlayer) .." reconnected ".. targetPlayerName , 4) 
                end 
            end 
        end 
    end 
end 
addCommandHandler("logout", forceReconnect, false, false) 

Link to comment
So I want to make it so if the player logs out, it reconnects him to the server. There's a /reconnect command I can just make it triggered if they logout but I'm not sure how so my nooby self decided to do it the hard way and ended up with a non-working code that doesn't do the job.
function joinserverHandlerFunction (playerSource, serverIP, serverPort, serverPassword) 
local serverIP = "69.245.157.67" 
local serverPort = "22003" 
local serverPassword = "confidential" 
    if serverIP and serverPort then --if IP and Port were specified 
        if serverPassword then --if also a password was specified 
            redirectPlayer (playerSource, serverIP, tonumber(serverPort), serverPassword) --redirect the player 
        else -- else if no password was specified 
            redirectPlayer (playerSource, serverIP, tonumber(serverPort))  --redirect the player without using the serverPassword parameter 
        end 
    end 
end 
addEventHandler("ojoinserverHandlerFunction",getRootElement(),loggedOut) 

Could someone fix this for me or at least give me the efficient-easier code that I want please :idea:

Ok, first of all the script is wrong.

You have named the function: joinserverHandlerFunction, and used the event "joinserverHandlerFunction", No such thing as joinserverHandlerFunction, and u have loggedOut (HUH), that should be the function, let me fix this.

I see what your trying, but i can't help that much:

function logoutreconnect (thePlayer) 
local serverIP = "69.245.157.67" 
local serverPort = "22003" 
local serverPassword = "confidential" 
redirectPlayer (thePlayer, serverIP, tonumber(serverPort), serverPassword) 
end 
addEventHandler("onPlayerLogout",getRootElement(),logoutreconnect) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...