All Unit Position

All Unit Position

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

All Unit Position

Post by Von66341 »

Hey!

Is there a way I can get the position of all units?
Say for example, 5 mins into the game, i want to collect all unit position and log it in a txt file.

Thanks.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: All Unit Position

Post by knorke »

Spring.GetAllUnits
Spring.GetUnitPosition
collect all unit position and log it in a txt file
maybe it looking at the widget of this is helpfull:
http://springrts.com/phpbb/viewtopic.ph ... 1&start=62
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: All Unit Position

Post by Von66341 »

The link says: File does not exist on our server
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: All Unit Position

Post by knorke »

down file is down.
try something like that:

Code: Select all

function widget:GameFrame(frame)
 if (frame==5*60*30) then--5 minutes
  myfile = io.open ("bla.txt", "w")
  if (myfile== nil) then 
    Spring.Echo ("could not open file for writing!") 
    return  
  end
  for _,unitID in ipairs(Spring.GetAllUnits ()) do
   x,y,z=Spring.GetUnitPosition (unitID)
   text = "unit " .. unitID .. " is at " .. ":"..x ..":".. y.. ":".. z
   myfile:write (text .. "\n")
  end
  myfile:flush()
  myfile:close()
end 
end
Post Reply

Return to “Game Development”