Jump to content

Get all accounts problem


Tete omar

Recommended Posts

Hi , i have a problem with getting all accounts using getAccounts and pick the accounts which has a specific data , but it's just says:

bad argument @ 'getPlayerAccount' [Expected element at argument 1]

Here's my code

for i,v in ipairs(getAccounts()) do 
    local account=getPlayerAccount(v) 
    -- anyway, i won't show the rest .. 

Is there any way to solve that problem?

Link to comment

Thanks cadu12

But i have another problem

for i,v in ipairs(getElementsByType("player")) do 
    if(getPlayerDataName(v))then 
    -- yet again .. 

I've made a function that gets the data from the players whose are having this data , but it's results nil value

and here's the code

local function getPlayerGangName(player) 
    local account=getPlayerAccount(player) 
    if(account~=false)then 
        return tostring(getAccountData(account,"data")) 
    else 
        return false 
    end 
    return true 
end 

Link to comment

If you are using 'getElementsByType("player")' > Use 'getPlayerAccount(v)' becuase 'v' returns 'player', not 'account'

Other problem, about your new function, I can't getting understand what you are talking about. Should be 'gang', and not 'data'?

Link to comment

I'm sorry for dis-appearing the rest of the code, but that's exactly what i used:

for i,v in ipairs(getElementsByType("player")) do 
    local account=getPlayerAccount(v) 
    if(getPlayerGangName(v))then 
        triggerClientEvent(v,"memberLoggedIn",v,getAccountName(account),getPlayerName(source)) 
    end 
end 

I'm notifying the other players who has the same data name that a player(who has the same data name) is joined by someway.

Link to comment

I guess that you want to do something like that?

addEventHandler("onPlayerLogin", root, 
function(_, acc) 
    for i,v in ipairs(getElementsByType("player")) do 
        if (getPlayerGangName(v) == getPlayerGangName(source)) then 
            triggerClientEvent(v, "memberLoggedIn", v, getAccountName(acc), getPlayerName(source)) 
        end 
    end 
end) 

otherwise, try to explain better.

Link to comment
I guess that you want to do something like that?
addEventHandler("onPlayerLogin", root, 
function(_, acc) 
    for i,v in ipairs(getElementsByType("player")) do 
        if (getPlayerGangName(v) == getPlayerGangName(source)) then 
            triggerClientEvent(v, "memberLoggedIn", v, getAccountName(acc), getPlayerName(source)) 
        end 
    end 
end) 

otherwise, try to explain better.

Look

addEventHandler("onPlayerChangeNick",root, 
    function(old,new) 
        for i,v in ipairs(getElementsByType("player")) do 
            if(getPlayerGangName(v))then 
                triggerClientEvent(v,"nickChanged",v,old,new) 
          
            end 
        end 
    end 
) 

When i change my nick , it doesn't outputs an error or something

And here:

for i,v in ipairs(getElementsByType("player")) do 
    if(getPlayerGangName(v))then 
        outputChatBox("Memeber "..getPlayerName(source).." has joined the gang as a " .. permission,v,0,255,0) 
    triggerClientEvent(v,"memberLoggedIn",v,getAccountName(getPlayerAccount(source)),getPlayerName(source)) 
    end 
end 

it outputs Bad argument @ 'getPlayerAccount' [Expected element at argument 1] for each account in the server

Tell me where's the difference between the two codes ? , i don't see anything that brings these errors , and by the way , the code isn't full, if you want to see the full code i can you show you.

Link to comment

What I think you're trying to do, is when a player logs in, you want to tell his gang that he is now online.

addEventHandler("onPlayerJoin",root,function() 
    for _,v in ipairs(getElementsByType("player")) do 
        if getPlayerGangName(v) then --btw make sure that this function is before this script 
            outputChatBox("Memeber "..getPlayerName(source).." has joined the gang as a " .. permission,v,0,255,0) --permission isn't defined 
            triggerClientEvent(source,"memberLoggedIn",source,getAccountName(getPlayerAccount(source)),getPlayerName(source)) 
        end 
    end 
end) 

If this is wrong please show us your full code or you could pm me your full code.

Link to comment

Here's the full code

addEventHandler("onPlayerLogin",root, 
    function(_,acc) 
        if(getAccountData(acc,"gangs"))then 
            local permission=getAccountData(acc,"permission") 
            if(permissions[permission])then 
                triggerClientEvent(source,"ganging",source,permission) 
                outputChatBox("You've joined group ("..getPlayerGangName(source)..") as a ("..permission ..")",source,255,255,0) 
                for i,v in ipairs(getAccounts()) do 
                    if(getPlayerGangName(v))then 
                        local player=getAccountPlayer(v) 
                        if(isElement(player))then 
                            triggerClientEvent(source,"recieveingPlayers",source,"online",getAccountName(getPlayerAccount(player)),getPlayerName(player)) 
                        else 
                            triggerClientEvent(source,"recieveingPlayers",source,"offline",getAccountName(getPlayerAccount(player))) 
                        end 
                    end 
                end 
                for i,v in ipairs(getElementsByType("player")) do 
                    if(getPlayerGangName(v))then 
                        outputChatBox("Memeber "..getPlayerName(source).." has joined the group as a " .. permission,v,0,255,0) 
                        triggerClientEvent(v,"memberLoggedIn",v,getAccountName(getPlayerAccount(source)),getPlayerName(source)) 
                    end 
                end 
                return true 
            end 
            return false 
        end 
    end 
) 

Link to comment

try this:

addEventHandler("onPlayerLogin",root,function(_,acc) 
    if not getAccountData(acc,"gangs")then return end 
    local permission=getAccountData(acc,"permission") 
    if not permissions[permission] then return end 
    triggerClientEvent(source,"ganging",source,permission) 
    outputChatBox("You've joined group ("..getPlayerGangName(source)..") as a ("..permission ..")",source,255,255,0) 
    for _,v in ipairs(getAccounts()) do 
        if not getPlayerGangName(v)then return end 
        local player=getAccountPlayer(v) 
        local accName = getAccountName(getPlayerAccount(player)) 
        if player and isElement(player)then 
            triggerClientEvent(source,"recieveingPlayers",source,"online",accName,getPlayerName(player)) 
        else 
            triggerClientEvent(source,"recieveingPlayers",source,"offline",accName) 
        end 
    end 
    for _,v in ipairs(getElementsByType("player")) do 
        if not getPlayerGangName(v)then return end 
        outputChatBox("Memeber "..getPlayerName(source).." has joined the group as a " .. permission,v,0,255,0) 
        triggerClientEvent(v,"memberLoggedIn",v,getAccountName(getPlayerAccount(source)),getPlayerName(source)) 
    end 
end) 

Link to comment

I think i know what the error was, try this:

addEventHandler("onPlayerLogin",root,function(_,acc) 
    if not getAccountData(acc,"gangs")then return end 
    local permission=getAccountData(acc,"permission") 
    if not permissions[permission] then return end 
    triggerClientEvent(source,"ganging",source,permission) 
    outputChatBox("You've joined group ("..getPlayerGangName(source)..") as a ("..permission ..")",source,255,255,0) 
    for _,v in ipairs(getAccounts()) do 
        if not getPlayerGangName(v)then return end 
        local player=getAccountPlayer(v) 
        local accName = getAccountName(v) 
        if player and isElement(player)then 
            triggerClientEvent(source,"recieveingPlayers",source,"online",accName,getPlayerName(player)) 
        else 
            triggerClientEvent(source,"recieveingPlayers",source,"offline",accName) 
        end 
    end 
    for _,v in ipairs(getElementsByType("player")) do 
        if not getPlayerGangName(v)then return end 
        outputChatBox("Memeber "..getPlayerName(source).." has joined the group as a " .. permission,v,0,255,0) 
        triggerClientEvent(v,"memberLoggedIn",v,getAccountName(getPlayerAccount(source)),getPlayerName(source)) 
    end 
end) 

Link to comment

I used the exact 'getPlayerGangName' function when the player changes his nick , but it doesn't appears any errors at all when i change my nick , i don't know why it doesn't work here?!

look

addEventHandler("onPlayerChangeNick",root, 
    function(old,new) 
        for i,v in ipairs(getElementsByType("player")) do 
            if(getPlayerGangName(v))then 
                triggerClientEvent(v,"nickChanged",v,old,new) 
            end 
        end 
    end 
) 

That worked perfectly with no errors or bugs

What is the error?

Bad argument @ 'getPlayerAccount' [Expected element at argument 1]

And here's the custom function

local function getPlayerGangName(player) 
    local account=getPlayerAccount(player) -- the error issued here 
    if(account~=false)then 
        return tostring(getAccountData(account,"gangs")) 
    else 
        return false 
    end 
    return true 
end 

Link to comment

oh, that's why,

on line 8 you are sending an account not a player argument.

try this:

addEventHandler("onPlayerLogin",root,function(_,acc) 
    if not getAccountData(acc,"gangs")then return end 
    local permission=getAccountData(acc,"permission") 
    if not permissions[permission] then return end 
    triggerClientEvent(source,"ganging",source,permission) 
    outputChatBox("You've joined group ("..getPlayerGangName(source)..") as a ("..permission ..")",source,255,255,0) 
    for _,v in ipairs(getAccounts()) do 
        local player=getAccountPlayer(v) 
        if not getPlayerGangName(player)then return end 
        local accName = getAccountName(v) 
        if player and isElement(player)then 
            triggerClientEvent(source,"recieveingPlayers",source,"online",accName,getPlayerName(player)) 
        else 
            triggerClientEvent(source,"recieveingPlayers",source,"offline",accName) 
        end 
    end 
    for _,v in ipairs(getElementsByType("player")) do 
        if not getPlayerGangName(v)then return end 
        outputChatBox("Memeber "..getPlayerName(source).." has joined the group as a " .. permission,v,0,255,0) 
        triggerClientEvent(v,"memberLoggedIn",v,getAccountName(getPlayerAccount(source)),getPlayerName(source)) 
    end 
end) 

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