Page 1 of 1

Examples for area checks during unit spawn?

Posted: 03 Dec 2010, 03:27
by bobthedinosaur
Say I want to spawn a unit near another unit (as if it were built from it) and I want to check the positions in the potential spawning area, to prevent placing on top of feature/ units, or off the map's edge. Are there any good examples of a gadgets using checks like this?

Re: Examples for area checks during unit spawn?

Posted: 03 Dec 2010, 05:45
by Google_Frog
wiki wrote:Spring.TestBuildOrder
( number unitDefID, number x, number y, number z, number facing)
-> number blocking [,number featureID]

blocking can be:
0 - blocked
1 - mobile unit in the way
2 - free (or if featureID is != 0 then with a blocking feature that can be reclaimed)
facing can be:
0, "s", "south"
1, "e", "east"
2, "n", "north"
3, "w", "west"
For the other checks just check your position against the map sizes and 0.

Re: Examples for area checks during unit spawn?

Posted: 03 Dec 2010, 13:01
by zwzsg
I used

Code: Select all

				local bt1,bt2=Spring.TestBuildOrder(UnitDefNames.yourunit.id,x,0,z,0)
				if bt1==2 and not bt2 then
					-- okay area is free
				end

Re: Examples for area checks during unit spawn?

Posted: 05 Dec 2010, 16:42
by bobthedinosaur
I am confused. what is the 2nd local for?

Re: Examples for area checks during unit spawn?

Posted: 05 Dec 2010, 19:03
by zwzsg

Re: Examples for area checks during unit spawn?

Posted: 05 Dec 2010, 23:37
by bobthedinosaur
Okay. New kind of related question:

If I wanted a certain air pad like unit to spawn another unit on top (attached to air pad), how would I go about this?

edit: Not possible? okay. nvm