Return a table menu

User Tag List

Results 1 to 9 of 9
  1. #1
    TheChosenPessimist's Avatar Sergeant
    Reputation
    17
    Join Date
    Oct 2010
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Return a table

    Code:
    local PlayersInZone = pUnit:GetPlayersInZone(1583)
    
    function GetPlayers(pUnit, event)
    	PlayersInZone[1]
    end
    The command GetPlayerInZone() returns the players in the zone. How do i put this in a variable?

    You can see my attempt above.

    Thank you for any help.

    Emulating human behaviour since 1993

    Return a table
  2. #2
    Meiya Stormsinger's Avatar Contributor

    Reputation
    163
    Join Date
    Mar 2009
    Posts
    196
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    local PlayersInZone = pUnit:GetPlayersInZone(1583)
    
    function GetPlayers(pUnit, event)
    for k,v in pairs (PlayersInZone) do
    v:dostuff...
    end
    end
    This will get all the players in the zone, and v = the players... So ...

    Code:
    v:SendBroadcastMessage("Mmmmm cake")
    Would make all the players in zone 1583 send a message to themselves saying "Mmmmm cake".

    This is an easy way to do it, i'm not entirely sure on how to return tables, and there is no table defined either so we can't get a value either.

    Hope this helps.

  3. #3
    TheChosenPessimist's Avatar Sergeant
    Reputation
    17
    Join Date
    Oct 2010
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Meiya Stormsinger View Post
    Code:
    local PlayersInZone = pUnit:GetPlayersInZone(1583)
    
    function GetPlayers(pUnit, event)
    for k,v in pairs (PlayersInZone) do
    v:dostuff...
    end
    end
    This will get all the players in the zone, and v = the players... So ...

    Code:
    v:SendBroadcastMessage("Mmmmm cake")
    Would make all the players in zone 1583 send a message to themselves saying "Mmmmm cake".

    This is an easy way to do it, i'm not entirely sure on how to return tables, and there is no table defined either so we can't get a value either.

    Hope this helps.
    Not quite the explanation i was looking for.

    GetPlayersInZone(zone id) : Returns a table containing all the players in the zone.
    I would like to specify one of the players.
    Like so:
    GetPlayersInZone[1]

    Get my point?

    Emulating human behaviour since 1993

  4. #4
    Meiya Stormsinger's Avatar Contributor

    Reputation
    163
    Join Date
    Mar 2009
    Posts
    196
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try using

    Code:
    Players = {}
    local PlayersInZone = pUnit:GetPlayersInZone(#)
    dostuff...
    table.getn (PlayersInZone)



    That should return the number. Not entirely sure though, try looking around in the guides section otherwise. If you can't find anything i can look this over when i get home as i'm currently in school.
    Last edited by Meiya Stormsinger; 10-19-2010 at 02:09 AM.

  5. #5
    stoneharry's Avatar Moderator Harry


    Reputation
    1618
    Join Date
    Sep 2007
    Posts
    4,564
    Thanks G/R
    151/150
    Trade Feedback
    0 (0%)
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by TheChosenPessimist View Post
    Not quite the explanation i was looking for.



    I would like to specify one of the players.
    Like so:
    GetPlayersInZone[1]

    Get my point?
    I've never really looked into how tables work in Lua, I would assume that it is columns and rows though.

    Code:
    for _,v in pairs (pUnit:GetPlayersInZone()) do
    _ because there is only 1 column, and v would be the rows. So try using v[0] and see if it returns something, use a script like such:
    Code:
    function x()
    local i = -1
    while (i~=5) do
    i = i + 1
    print(v[i])
    end







  6. #6
    TheChosenPessimist's Avatar Sergeant
    Reputation
    17
    Join Date
    Oct 2010
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by stoneharry View Post


    I've never really looked into how tables work in Lua, I would assume that it is columns and rows though.

    Code:
    for _,v in pairs (pUnit:GetPlayersInZone()) do
    _ because there is only 1 column, and v would be the rows. So try using v[0] and see if it returns something, use a script like such:
    Code:
    function x()
    local i = -1
    while (i~=5) do
    i = i + 1
    print(v[i])
    end






    There's not only one column? Or is it?

    When you use GetPlayersInZone() it returns the following:

    GetPlayersInZone = {1, 2, 3, 4, 5, 6}

    1-6 being players.

    I hope im not missunderstanding you.

    Emulating human behaviour since 1993

  7. #7
    Dynashock's Avatar Contributor

    Reputation
    176
    Join Date
    Nov 2007
    Posts
    203
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GetPlayersInZone() returns an indexed table. Thus if you were to print its content (using "for k,v in ipairs(GetPlayersInZone()) do print (k,v) end") you would get the following:
    Code:
    1      playerdata
    2      playerdata
    3      playerdata
    4      playerdata
    Tables in Lua start off with index 1, unlike arrays in C-like languages which start off at 0.

    If I were to retrieve the player which is the first in the table I would use GetPlayersInZone()[1]. However, the value returned by GetPlayersInZone() could be nil (as there could be zero players in the zone), thus you'd be better off by assigning the table to a local variable (to avoid polluting the global namespace), then checking if the table contains any playerdata at index 1, and then finally perform an action on the player.
    For instance:
    Code:
    local zonePlayers = GetPlayersInZone(some zone);
    if (zonePlayers[1] ~= nil) then
        zonePlayers[1]:DoSomething();
    end
    If you wanted to store the player in another value it is as simple as assigning any other variable, i.e. local player = zonePlayers[1].
    Last edited by Dynashock; 10-19-2010 at 07:21 AM.
    Ignorance is bliss.

  8. #8
    TheChosenPessimist's Avatar Sergeant
    Reputation
    17
    Join Date
    Oct 2010
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Dynashock View Post
    GetPlayersInZone() returns an indexed table. Thus if you were to print its content (using "for k,v in ipairs(GetPlayersInZone()) do print (k,v) end") you would get the following:
    Code:
    1      playerdata
    2      playerdata
    3      playerdata
    4      playerdata
    Tables in Lua start off with index 1, unlike arrays in C-like languages which start off at 0.

    If I were to retrieve the player which is the first in the table I would use GetPlayersInZone()[1]. However, the value returned by GetPlayersInZone() could be nil (as there could be zero players in the zone), thus you'd be better off by assigning the table to a local variable (to avoid polluting the global namespace), then checking if the table contains any playerdata at index 1, and then finally perform an action on the player.
    For instance:
    Code:
    local zonePlayers = GetPlayersInZone(some zone);
    if (zonePlayers[1] ~= nil) then
        zonePlayers[1]:DoSomething();
    end
    If you wanted to store the player in another value it is as simple as assigning any other variable, i.e. local player = zonePlayers[1].
    Thank you for the answer, this is the answer i was looking for.

    Emulating human behaviour since 1993

  9. #9
    Meiya Stormsinger's Avatar Contributor

    Reputation
    163
    Join Date
    Mar 2009
    Posts
    196
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's Dynashock for ya !

Similar Threads

  1. [Question] Lua Callback: Return table of values
    By DrakeFish in forum WoW Memory Editing
    Replies: 6
    Last Post: 06-18-2011, 10:44 PM
  2. World of Warcraft 2: Return of the Gnomes
    By Hakonj in forum Art & Graphic Design
    Replies: 16
    Last Post: 04-01-2007, 09:31 AM
  3. I have returned!
    By jinkotsu in forum Community Chat
    Replies: 5
    Last Post: 02-23-2007, 02:16 PM
  4. [Guide] Basic DBC Table Review
    By Fault in forum WoW ME Tools & Guides
    Replies: 4
    Last Post: 12-02-2006, 04:36 AM
  5. Table Of Contents
    By oninuva in forum World of Warcraft Guides
    Replies: 0
    Last Post: 04-23-2006, 01:45 PM
All times are GMT -5. The time now is 01:37 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search