Jump to content

[HELP] Why not working loop?


Tokio

Recommended Posts

client: 

local Admins = {} 
  
addEvent("updateAdmins",true) 
addEventHandler("updateAdmins",root, 
function(t) 
Admins = t 
end) 
  
function isPlayerAdmin(player) 
    if(Admins[player]) then 
        return true 
    end 
    return false 
end 


function asdi()
for k,v in ipairs(Admins) do 
    outputChatBox(k) 
end 
end
addCommandHandler("asd",asdi)

server:

local Admins = {} 
  
function isPlayerAdmin(player) 
    if(Admins[player]) then 
        return true 
    end 
    return false 
end 
  
addEventHandler("onPlayerLogin",root, 
function() 
if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Admin" ))then 
if not(Admins[source])then 
 Admins[source]= source 
 triggerClientEvent("updateAdmins",source,Admins) 
end 
end 
end) 
  
addEventHandler("onPlayerQuit",root, 
function() 
if(Admins[source])then 
 Admins[source]= nil 
  triggerClientEvent("updateAdmins",source,Admins) 
end 
end) 

No errors, no warnings... What wrong?

Edited by Tokio
Link to comment
  • Moderators

HUNGARIAN

A táblázatodban a sorok indexe a player elementje és nem számok, növekvő sorrendben.

Ezért ipairs helyett pairs-t kell használnod.

Lényegében ezt veheted egy "szabálynak" is, ha saját indexű sorokat használsz, és nem table.insert-el adod hozzá a sorokat a táblázathoz, akkor pairs-t kell használni és jó lesz.

 

ENGLISH

Because you use custom indexed array (index is the player's element), you need to use pairs instead of ipairs.

 

for element, value in pairs(Admins) do
	outputChatBox(getPlayerName(element) .. " is admin!")
end

 

  • Thanks 1
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...