Jump to content

getAccounts() is causing LAG


crabby

Recommended Posts

i use this function

function gridlist(clan) 
theTable = {} 
for index, ac in pairs(getAccounts()) do 
local keyclan = getAccountData(ac,"ortakveri") 
if keyclan and keyclan == clan then 
local nick = getAccountData(ac,"nick") 
table.insert(theTable, {nick}) 
triggerClientEvent(source,"gridlist",source,theTable) 
end 
end 
end 

Link to comment

You're triggering the client event with the table for each account.

function gridlist(clan) 
theTable = {} 
for index, ac in pairs(getAccounts()) do 
local keyclan = getAccountData(ac,"ortakveri") 
if keyclan == clan then 
local nick = getAccountData(ac,"nick") 
table.insert(theTable, {nick}) 
end 
end 
triggerClientEvent(source,"gridlist",resourceRoot,theTable) 
end 

I doubt source is defined here, make sure it is.

Also, you don't need to store each 'nick' in a table, since there are no other values added.

Link to comment

thx but still have lag and i have 4000+ account. i use this function but i again have a problem. clan have more member but just view a member.

I want to get members loop clan data only once and members use this clan data tables on client side

--Serverside 
function gridlist(clan) 
theTable = {} 
for index, ac in pairs(getAccounts()) do 
local keyclan = getAccountData(ac,"ortakveri") 
if keyclan and keyclan == clan then 
local nick = getAccountData(ac,"nick") 
local accname= getAccountName(ac) 
table.insert(theTable, {nick,accname}) 
triggerClientEvent(source,"gridlist",resourceRoot,theTable,clan) 
end 
end 
end 
  
  
--Clientside 
  
local clanTable = {} 
  
addEvent("gridlist",true) 
addEventHandler("gridlist",root, 
function(theTable,clan) 
clanTable[clan] = theTable -- i use this table on gridlist 
end) 

Link to comment

Well of course if you have over 4000 accounts and loop through them all, while triggering a client event with every entry it's gonna lag.

Lets say you have 4500 accounts, for every 1 account it founds it will do this;

local nick = getAccountData(ac,"nick") 
local accname= getAccountName(ac) 
table.insert(theTable, {nick,accname}) 
triggerClientEvent(source,"gridlist",resourceRoot,theTable,clan) 

Now you repeat this for the remaining 4499 accounts. Hardly very efficient. And since I don't know what you're trying to do, I can't really help you make it any better.

First of all, trigger the client event ONCE and not 4000+ times. To do that, simply move the event out of the loop - it makes no sense to have it inside the loop.

function gridlist(clan) 
    theTable = {} 
    for index, ac in pairs(getAccounts()) do 
        local keyclan = getAccountData(ac, "ortakveri") 
        if keyclan and keyclan == clan then 
            local nick = getAccountData(ac, "nick") 
            local accname= getAccountName(ac) 
            table.insert(theTable, {nick, accname}) 
        end 
    end -- Loop stops executing here 
    triggerClientEvent(source,"gridlist", resourceRoot, theTable, clan) 
end 

Edit: You might have to make the table theTable global instead of local, I can't recall how strict Lua is with local variables.

Link to comment

i dont have 4000+ users accounts and this users number just example but my friend in server have users and i make for him this script and we have lag.

everybody thank you very much for help. i did not know resourceRoot and Loop stops executing but now teach its.

Link to comment
i dont have 4000+ users accounts and this users number just example but my friend in server have users and i make for him this script and we have lag.

everybody thank you very much for help. i did not know resourceRoot and Loop stops executing but now teach its.

Why would you say you have over 4 000 accounts when you don't? :roll: Did you manage to fix it, or is it still lagging? Did you apply our changes to the loop or not?

Link to comment
  • 4 months later...

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