How do you get iPlot from pPlot?

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
This is a weird thing to get stuck on. I can easily get a pPlot object from an iPlot index, and from there I can get coordinates or whatever. But I can't for the life of me figure out how to go the other way from pPlot (or x,y) back to iPlot (short of cycling through all iPlots for a match, but that would be ridiculous). Can anyone tell me how to do it?
 
Never mind. No single function for it as far as I can tell, but you can get iPlot from pPlot by:

local iW, iH = Map.GetGridSize()
local x, y = pPlot:GetX(), pPlot:GetY()
local iPlot = y * iW + x
 
No, there isn't a Plot:GetID() function like there is for most of the others... but really, why would you WANT its ID? It's useless for anything other than indexing the plot array to begin with. This is probably why they didn't put that function in; the Lua functions we do have are those that are used by the vanilla game in all of its varying UI elements and scenarios, and if there was no reason to try to extract iPlot, then they wouldn't have bothered giving that access function.

If you explain what you need it for, then someone might be able to find you functions that get to your desired end result more quickly. For instance, if you're trying to find a plot relative to the one in question, there's a whole slew of functions in the Map: structure, like Map:GetPlotXY() that do all of this without the need for actual index numbers.
 
Well, after 5000 lines of coding its the first time I had this need. I usually cycle through things based on index and pass them around that way. No reason for that except consistent programming style. I already have multiple functions that take iPlot, and I didn't want to rewrite all of them just because I didn't have iPlot in this one case.
 
Back
Top Bottom