Examples for area checks during unit spawn?

Examples for area checks during unit spawn?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Examples for area checks during unit spawn?

Post 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?
Last edited by bobthedinosaur on 05 Dec 2010, 16:42, edited 1 time in total.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Examples for area checks during unit spawn?

Post 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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Examples for area checks during unit spawn?

Post 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
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Examples for area checks during unit spawn?

Post by bobthedinosaur »

I am confused. what is the 2nd local for?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Examples for area checks during unit spawn?

Post by zwzsg »

User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Examples for area checks during unit spawn?

Post 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
Post Reply

Return to “Lua Scripts”