"Sorting" coordinates?
Hi all,
This is my first foray into modding. I've put together a super simple mod that list that just prints out a list of the new rare mobs/one-time-loot world objects in WoD. Here's a sample of what I have so far: Lua Code:
I have the above working for every zone using data I scraped from Wowpedia. My question is, is there any way to kind of sort the items based on a relative closeness to player position? I don't need to find "distance", I was just thinking something simple like ((player X coord - item X coord) or (item X coord - player X coord)) based on whichever is higher, then sorting based on the lower result. Are there any examples of how I would store my values into an array/table and sort that, then write that out to the screen? I'm mainly an SQL guy, so I've been learning the basics of lua/non-scripted programming as I go. |
Quote:
If you have a table like Lua Code:
Lua Code:
Lua Code:
|
nvm, semlar edited :)
|
That is quite helpful. I understand how the table.sort is working, and how you populate the initial table, but I'm having a lot of trouble adding subsequent items to the table.
I'm especially having trouble getting it to work since I'll have 4 values per line in the table, and almost every example I've come across just shows how to handle a key and single value. I'm assuming that using my initial code, I'll be changing each Print to some method of inserting a new row into my table, then doing the sort at the end, then printing the sorted table. edit: I think I have it working, here is my concept code: Lua Code:
Is the "for ipairs" the best way for printing out my sorted table? Also, for the items I do not have the coordinates for, is there a more elegant method than setting their coordinates to 1000, 1000? |
I don't know how much of this you already figured out, but
Quote:
Code:
local value = {34132, 70.5, 63.5, "scout"} Quote:
Quote:
|
All times are GMT -6. The time now is 07:12 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI