Jump to content

Checking the player if he is in a table or not


Recommended Posts

Okay i need to make a if statement to find if the player is in a specified table or not.

Here is the script that I made. Is this ok?

  
local vips =  
} 
[1]=”Anubhav”, 
[2]=”esporta”, 
  
} 
  
if (thePlayer == vips) then 
    outPutChatBox ("You are vip", source) 
else 
    outPutChatBox("You are not a vip", source) 
end 
end 
  

Link to comment
vips = { 
"Anubhav", 
"esporta", 
} 
  
local gPlayers = getElementsByType("player") 
for placeNumber, playerData in ipairs(gPlayers) do 
    local gAccount = getPlayerAccount(playerData) 
    if (gAccount ~= false) and (isGuestAccount(playerData) == false) then 
        local gAccountName = getAccountName(gAccount) 
        if (gAccountName ~= false) then 
            local isVip = false 
            for placeNumber2, stringData in ipairs(vips) do 
                if (gAccountName == stringData) then 
                    isVip = true 
                end 
            end 
            if (isVip == true) then 
                outputChatBox("You are a vip.", playerData) 
            elseif (isVip == false) then 
                outputChatBox("You are not a vip.", playerData) 
            end 
        end 
    end 
end 

Serverside and for all players. If you want it for 1 player only, you can edit the script.

Link to comment

Is it so hard do detect if the logged in player account name is contained in that table? Because I don't understand anything.

I am just trying to detect if the logged in player is registered in that vips table. Btw there is no guest accounts on server. They are supposed to login in order to play server.

Isn't it possible like this:

  
vips =  
{ 
"Anubhav", 
"esporta", 
"bilal", 
} 
  
local accname = getAccountName (source) 
  
if (accname == vips) then 
--script body 
end 
  

Link to comment
local vips =  
{ 
    "Anubhav", 
    "esporta", 
    "bilal", 
} 
  
local accname = getAccountName(source) 
if (vips[accname]) then 
    outputChatBox ("You are vip", source) 
else 
    outputChatBox("You are not a vip", source) 
end 

Link to comment
vips = { 
    "someguy", 
    "otherguy", 
    "anotherone" 
} 
  
function on_login (_, new_acc) 
    local acc_name = getAccountName(new_acc) 
    for i,vip_acc_name in ipairs(vips) do 
        if acc_name == vip_acc_name then 
            outputChatBox("Wellcome to your vip account.", source, 255, 255, 255, true) 
            return true 
        end 
    end 
    outputChatBox("You are not vip", source, 255, 255, 255, true) 
end 
addEventHandler('onPlayerLogin', root, on_login) 

:arrowup: i have not tested this.

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