Tete omar Posted December 10, 2012 Share Posted December 10, 2012 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
Cadu12 Posted December 10, 2012 Share Posted December 10, 2012 There is no need to use getPlayerAccount, just use getAccountData(v, "...") Link to comment
Tete omar Posted December 10, 2012 Author Share Posted December 10, 2012 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
Cadu12 Posted December 10, 2012 Share Posted December 10, 2012 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
Tete omar Posted December 10, 2012 Author Share Posted December 10, 2012 Sorry forget about getPlayerDataName this is the code which has all focus for i,v in ipairs(getElementsByType("player")) do if(getPlayerGangName(v))then -- yet again .. Link to comment
Cadu12 Posted December 10, 2012 Share Posted December 10, 2012 So, is problem already solved? Link to comment
Tete omar Posted December 10, 2012 Author Share Posted December 10, 2012 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
Cadu12 Posted December 10, 2012 Share Posted December 10, 2012 Replace 'source' with 'v'. Next time, fix your eyes Link to comment
Tete omar Posted December 10, 2012 Author Share Posted December 10, 2012 The source is the player who just logged in , so i'm getting his name & account , and i don't see any problem in my code, and 'v' is the players who has the same data type, so i'm notifying them that a member of them has just logged in Link to comment
Cadu12 Posted December 10, 2012 Share Posted December 10, 2012 Well, next time, you should write if your isnt FULL code, becuase we can't get know if your code is full. You're welcome Link to comment
Tete omar Posted December 10, 2012 Author Share Posted December 10, 2012 But i still need help Link to comment
TAPL Posted December 10, 2012 Share Posted December 10, 2012 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
Tete omar Posted December 12, 2012 Author Share Posted December 12, 2012 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
myonlake Posted December 12, 2012 Share Posted December 12, 2012 Change "source" to "v". "Source" is the resource if you use your code during the start of the resource. Link to comment
Tete omar Posted December 12, 2012 Author Share Posted December 12, 2012 Change "source" to "v". "Source" is the resource if you use your code during the start of the resource. No .. , the code starts when the player(who have the data) logins in Link to comment
myonlake Posted December 12, 2012 Share Posted December 12, 2012 Better give us the full code in that case. There's nothing wrong with the code as far as I can see. Link to comment
Jaysds1 Posted December 12, 2012 Share Posted December 12, 2012 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
Tete omar Posted December 12, 2012 Author Share Posted December 12, 2012 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
Jaysds1 Posted December 12, 2012 Share Posted December 12, 2012 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
Tete omar Posted December 12, 2012 Author Share Posted December 12, 2012 Same error & thanks it outputs 1 error , not too many ones. Link to comment
Jaysds1 Posted December 12, 2012 Share Posted December 12, 2012 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
Tete omar Posted December 12, 2012 Author Share Posted December 12, 2012 Sorry , same error Link to comment
Tete omar Posted December 12, 2012 Author Share Posted December 12, 2012 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
Jaysds1 Posted December 12, 2012 Share Posted December 12, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now