Jump to content

[Question] kick player if their serial is not in table


kieran

Recommended Posts

I made a short script that allows only certain serials to join, but the problem is in my for loop it checks every serial from a table, then it kicks the player if their serial is not in that table, of course it kicks them if the first serial it gets isn't equal to theirs.....  And I am struggling to come up with a way to fix it, here is code.

local allowedAccountSerials = 
{--Table of all allowed serials
    { "1K23GKG4K12B4B4K12B4K1B4J1BK1B43" },
    { "F2412KL4NHLK1NH41NH24KJ14K1B4144" },
    { "FB1244HK4HK1H1H4K14H12HK4K1H4142" },
    { "89AF8AFAW90F8A08FAW9FAF8ASF9WAF8" },
}
 
addEventHandler("onPlayerJoin", getRootElement(),
    function()
        local playerSerial = getPlayerSerial(source) --Get players serial
        for i = 1, #allowedAccountSerials do --For all serials in the list
            if playerSerial ~= allowedAccountSerials[i] then --If the players serial doesn't match one in the table
                kickPlayer(source, "Serial " ..playerSerial.. " is not allowed to join.") --Kick them
				return
			else
				outputChatBox(source, "Welcome to the server "..playerSerial)
            end
        end
    end
)

I'm trying to get this to work for map editor as any player could come and ruin the map when I start editor on my server, thanks for any help/input.

Link to comment

Much easier way.

local allowedAccountSerials = {
	["1K23GKG4K12B4B4K12B4K1B4J1BK1B43"] = true,
	["F2412KL4NHLK1NH41NH24KJ14K1B4144"] = true,
	["FB1244HK4HK1H1H4K14H12HK4K1H4142"] = true,
    ["89AF8AFAW90F8A08FAW9FAF8ASF9WAF8"] = true
}
 
addEventHandler("onPlayerJoin", getRootElement(), function()
	local playerSerial = getPlayerSerial(source) --Get players serial
	if not allowedAccountSerials[playerSerial] then
		kickPlayer(source, "Serial " ..playerSerial.. " is not allowed to join.") --Kick them
		return
	else
		outputChatBox(source, "Welcome to the server "..playerSerial)
	end
end)

 

  • Thanks 1
Link to comment
43 minutes ago, NeXuS™ said:

Much easier way.


local allowedAccountSerials = {
	["1K23GKG4K12B4B4K12B4K1B4J1BK1B43"] = true,
	["F2412KL4NHLK1NH41NH24KJ14K1B4144"] = true,
	["FB1244HK4HK1H1H4K14H12HK4K1H4142"] = true,
    ["89AF8AFAW90F8A08FAW9FAF8ASF9WAF8"] = true
}
 
addEventHandler("onPlayerJoin", getRootElement(), function()
	local playerSerial = getPlayerSerial(source) --Get players serial
	if not allowedAccountSerials[playerSerial] then
		kickPlayer(source, "Serial " ..playerSerial.. " is not allowed to join.") --Kick them
		return
	else
		outputChatBox(source, "Welcome to the server "..playerSerial)
	end
end)

 

Thanks a lot, forgot you could do tables/lists like that! :D

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...