Code: Select all
local longone = math.random(-95, -80)
local latone = math.random(44, 54)
DrawWhiteboardSquare(longone, latone, 5)
if (IsValidPlacementLocation (longone, latone, "Silo")) then
PlaceStructure (longone, latone, "Silo")
end
YieldLongTask()
units = GetAllUnits()
repeat
for i, unit in ipairs(units) do
if unit:GetTeamID() == GetOwnTeamID() then
if unit:GetUnitType() == "Silo" then
table.insert(siLos, unit)
end
end
YieldLongTask()
end
YieldLongTask()
S1 = siLos[1] -- S1 Goes after YieldLongTask() (after for end) and before block end
until # siLos == 1
SendChat("There have been " .. # siLos .. " silos placed")
-- Working code above
repeat
local e = # siLos
local x = siLos[e]:GetLongitude() + math.random(4, 5)
local y = siLos[e]:GetLatitude() - math.random(3, 4)
SendChat(siLos[e]:GetLongitude() .. " , " .. siLos[e]:GetLatitude())
SendChat(x .. " , " .. y)
if (IsValidPlacementLocation (x, y, "Silo")) then
PlaceStructure (x, y, "Silo")
else
SendChat("Not valid")
WhiteboardDraw (longone, latone, x, y)
end
YieldLongTask()
units = GetAllUnits()
local lastkey = # siLos
SendChat("There have been " .. # siLos .. " silos placed")
for i, unit in ipairs(units) do
if unit:GetTeamID() == GetOwnTeamID() then
if unit:GetUnitType() == "Silo" then
if unit:GetLongitude() ~= siLos[lastkey]:GetLongitude() then
table.insert(siLos, unit)
end
end
end
YieldLongTask()
end
YieldLongTask()
until GetRemainingUnits("Silo") == 3
YieldLongTask()
SendChat(# siLos)
SendChat("1 " .. siLos[1]:GetLongitude() .. " " .. siLos[1]:GetLatitude() .. " 2 " .. siLos[2]:GetLongitude() .. " " .. siLos[2]:GetLatitude() .. " 3 " .. siLos[3]:GetLongitude() .. " " .. siLos[3]:GetLatitude() .. " 4 " .. siLos[4]:GetLongitude() .. " " ..siLos[4]:GetLatitude())
SendChat(myCities[1]:GetLongitude())
SendChat(myCitiesLong[1])
SendChat(myCitiesLat[1])
SendChat(myCities[1]:GetLatitude())
SendChat(tostring(siLos[1]) .. " " .. tostring(siLos[2]) .. " " .. tostring(siLos[3]) .. " " .. tostring(siLos[4]))
-- Working code Below
Some of the code is simple there to help me asses what is actually happening (i.e., unnecessary). It looks to me like I can't make Silo#2 the starting point and it keeps going back to Silo#1 and trying to place Silo#3 on top of Silo#2, which is impossible.
Any suggestions?
Edit: I seem to have had it a bit backwards (table entry first, then placement, duh!), but now I can't seem to work out the table.insert function at the end. It'll place a bunch of silos now, but when it get's to the sea (Atlantic, from USA East Coast), it can't place any more but still loops through the code and tells me "there have been 16 silos placed", which is obviously incorrect.
New results: (corrected code above)
Edit: I've worked it all out except for the table.insert portion. It keeps entering the first silo twice. (new code above)