Jump to content
Spinal Tap 84

Using setPos with preset building positions

Recommended Posts

Hey everyone,

I am a long time Operation Flashpoint player, but a very poor mission editor.  I am trying to make a mission with enemy units inside of buildings.  I have done some searching and found the following code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this setpos [(getpos this select 0), (getpos this select 1), 15]

You would place the unit where you want him and manipulate the value for the altitude, but I am curious to know if there is another way.  

My question is if I am using buildings that have predetermined positions, what line of code do I use?  I found the following code in the readme for philcommando's embassy addon:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this setpos (embassy2 buildingpos 1) or

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this move (embassy2 buildingpos 1)

I cannot, for the life of me, figure out how to do this with buildings that are part of the map and not addons.  Is it even possible? "Embassy2" is the name given to the object in it's name field.  I have heard that you need to use the object's id number, but I have unsuccessfuly tried to implement it.  For reference, I am currently using AfganEveron v2.0.  I think the problem may arise from the use of spaces. For example one building is called "caravenserail-sand 7," and I always get errors when I input this and the id number where "embassy2" is in the above code. 

I have searched the forums, google, and this forum's FAQ thread, but I have been unsuccessful to find a solution that works for me (it's entirely possible that I have missed it, which is kind of sad on my part because I have been searching for a couple of days now).  I know it's not the most complicated problem, but nonetheless it has been bugging me.  Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites

If the addons are on the island, not placed objects you placed yourself, then you would have to find out the object ID#. This is easy, just go to the right side of your editor and click "Show IDs" or something similar, then when you have zoomed in close to find out the building you want's ID #, remember the #, and put this in the unit's init field:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this setpos (object ### buildingpos 1)

hope this works!

Share this post


Link to post
Share on other sites

snuffles is right, here is a small tutorial to make finding building ID and position easy to understand if you are not experienced in this part of the mission editing.

In your OFP editor you can notice a Show ID button (according to the mod you are using, the location of this button in the editor GUI can change), remember where it is, it will be needed in the example.

showidic1.jpg

Now on the example, i want to find the ID of one the building in Montignac,as i will want an AI to move into it :

montiplanzr7.jpg

Once i have located it in the plan, i press the Show ID button in the editor interface , here is what happen :

montiidzg9.jpg

I notice the ID allocated by OFP to this building is 20749 , that's important, i note it for later, now i want the AI to move to this window here on this building

where1xs1.jpg

To know what is the position number of this location in the building, i make an AI to join me , with me as the leader, ingame i select this AI and point it to the window, notice the number that appear on the cursor : House Position #5

housposbz6.jpg

But to be sure that at this distance i point exactly where i want, i move to the position myself, and then point the AI to the floor/wall until the number appear :

confirmtx8.jpg

Good it seems confirmed House Position #5

But here is some problem, you must substract 1 to the House Position number you find, to see what is the true numer of the House Position, why ? just try the following code with 5 instead of 4 and you will understand.

So we know we must use the house position number 4 (the 5 we see ingame - 1 as i tell you)

So by using

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this setpos ((object 20749) buildingpos 4)

the AI will appear directly where i need (i can setdir it later to get an orientation)

or

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this move ((object 20749) buildingpos 4)

or if the AI is in formation

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this domove ((object 20749) buildingpos 4)

So the AI will move from where it is , and will enter the building and climb the stair, up to the window position.

Now you should be able to apply this to any enterable building built in any island in OFP.

Share this post


Link to post
Share on other sites

Thank you very much for the fast replies snuffles and Sanctuary!  This should be more than sufficient!

Sanctuary, thanks for the extremely detailed walk-through.  The extra effort you put in is a really big help.  I am a big fan of your animations work and the rest of DMA's projects as well.

Share this post


Link to post
Share on other sites

Shyt! You can learn something every day! biggrin_o.gif

I didn't know about those biulding positions ... cool, thx guys!

Share this post


Link to post
Share on other sites
Gnat @ Aug. 20 2006,03:45)]Shyt! You can learn something every day!  biggrin_o.gif

I didn't know about those biulding positions ... cool, thx guys!

wow, this is great. i never even knew that :P

thanks Sanctuary

Share this post


Link to post
Share on other sites

Hi

Check out move ai to 2nd floor positions in a bulding at OFPEC, there is some more info about using the indexed positions in buildings. Mainly the buildingPosCount function which can be used to find out the number of the indexed positions so you don't need to know that in advance in your scripts. Combining that with nearestBuilding, you can make a script which looks for suitable buildings and then orders AI soldiers into them.

Share this post


Link to post
Share on other sites
Quote[/b] ]Check out move ai to 2nd floor positions in a bulding at OFPEC, there is some more info about using the indexed positions in buildings. Mainly the buildingPosCount function which can be used to find out the number of the indexed positions so you don't need to know that in advance in your scripts. Combining that with nearestBuilding, you can make a script which looks for suitable buildings and then orders AI soldiers into them.

I didn't use buildingposcount (have to look into that function) but my AI script orders AI into buildings. Open the getcover.sqs file to see how its done, it's pretty easy really.

Link to relevant thread with download link

Share this post


Link to post
Share on other sites

Take great care using buildingPos. The function works fine until the mission is saved and then reloaded. After the reload then the results returned are very different - often in the next street!!

So using buildingPos at the start of a mission is fine, but if you have a script that uses buildingPos later on in the mission when the player may have saved the mission and then reloaded you will have problems. I find it best to save the positions at the start of the mission.

Share this post


Link to post
Share on other sites
Quote[/b] ]Take great care using buildingPos. The function works fine until the mission is saved and then reloaded. After the reload then the results returned are very different - often in the next street!!

So using buildingPos at the start of a mission is fine, but if you have a script that uses buildingPos later on in the mission when the player may have saved the mission and then reloaded you will have problems. I find it best to save the positions at the start of the mission.

OMG! I just tested it and was shocked. It appears that after reload all the buildingpositions are lost and set to position [0,0,0]. I'll have to adapt my scripts to cope with this problem. banghead.gif

Share this post


Link to post
Share on other sites

There is also another very easy way to do this for AI units:

Place AI unit on map give it a waypoint directly on top of a "house" or "church" etc.

(you will know it's on top when the name of the object appears). Once you do this you will have new options within the waypoint itself and you'll notice somehting like "pos #" or "building pos#" of which you can select and your units will walk to differant floors etc... Exactly like that of the the guy walking around on the resistance menu screen when you first got it.

--IceFLYER

Share this post


Link to post
Share on other sites
Quote[/b] ]Check out move ai to 2nd floor positions in a bulding at OFPEC, there is some more info about using the indexed positions in buildings. Mainly the buildingPosCount function which can be used to find out the number of the indexed positions so you don't need to know that in advance in your scripts. Combining that with nearestBuilding, you can make a script which looks for suitable buildings and then orders AI soldiers into them.

I didn't use buildingposcount (have to look into that function) but my AI script orders AI into buildings. Open the getcover.sqs file to see how its done, it's pretty easy really.

Link to relevant thread with download link

You can improve your script by using the buildingPosCount function.

Share this post


Link to post
Share on other sites
Quote[/b] ]OMG! I just tested it and was shocked. It appears that after reload   all the buildingpositions are lost and set to position [0,0,0]. I'll have to adapt my scripts to cope with this problem.
Indeed.  When I discovered this I created a little routine at the start of the mission that saved all the buildingPos locations that I needed in an array and then just used those values in all my scripts.

Share this post


Link to post
Share on other sites
Quote[/b] ]Indeed. When I discovered this I created a little routine at the start of the mission that saved all the buildingPos locations that I needed in an array and then just used those values in all my scripts.

Yeah, I'm trying to do that now for my script also. But the problem is that my script is intended to work anywhere, anytime, with minor effort from the mission designer. This requires that all buildings on the entire island are scanned at the start of the mission. I don't know how to do that without creating too much lag. Can you please tell me how your little routine works? Maybe it will be of some help to me.

Quote[/b] ]You can improve your script by using the buildingPosCount function.

Pretty nice function that is, I think I can use it once I have found a way to detect all buildings on the map.

Share this post


Link to post
Share on other sites

What I did will be on no help to you I'm afraid.  I identified all the buildings I wanted to use.  I made a list of their ID numbers.  At the start of the mission I run a script that cycled through all the buildings and saved the values of all the buildingPos that I wanted to use.

For what it is worth here is part of the script I used:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;Buildings - Saint Louis

_buildings = [17084,17087,17088]

;Buildings - Larche

_buildings = _buildings  + [17064,17065,17066,17067,17068,17079,17081,17080]

;Buildings - Goisse

_buildings = _buildings  + [17100,17101,17102]

_GL = "logic" createvehicle [0,0,0]

;Find all the positions possible

PeepingCiviPos = []

_i = 0

#loopPosition

_buildingID = _buildings select _i

if (getDammage (object _buildingID) > 0.7) then {goto"skipBuilding"}

_GL setPos getPos (object _buildingID)

_j = 0

while {((nearestbuilding _GL) buildingPos _j) select 0 > 1} do {PeepingCiviPos = PeepingCiviPos + [(nearestbuilding _GL) buildingPos _j];_j = _j + 1}

#skipBuilding

_i = _i + 1

if (_i < count _buildings) then {goto"loopPosition"}

deletevehicle _GL

The way I used the array later was simply to select locations at random.  It sounds like what you need to do will require much more structure than I needed

Share this post


Link to post
Share on other sites

hi,

that looks something similar as my "DAC_Scan_Building_In_ZoneXY" script wink_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_zone = _this select 0

_xVal = _this select 1

_yVal = _this select 2

_temp = [];_g = 1

_tPos = "logic" createvehicle [0,0,0]

_stime = time + 5

_tempB = []

{if(!((_x select 0) == _zone)) then {_tempB = _tempB + [_x]}}foreach DAC_Buildings

~0.1

DAC_Buildings = _tempB

#objagain

_checksb = 25

_mpos = getpos _zone

_pos = [(_mpos select 0) - _xVal,(_mpos select 1) - _yVal,0]

~0.2

_old1 = (_pos select 1)

_old2 = (_pos select 0)

#searchnext

_tPos setpos _pos

_obj = nearestbuilding _tPos

?(_obj in _temp):goto "afterLoop"

?((getpos _obj select 0) < ((getpos _zone select 0) - _xVal)) || ((getpos _obj select 0) > ((getpos _zone select 0) + _xVal)):goto "afterLoop"

?((getpos _obj select 1) < ((getpos _zone select 1) - _yVal)) || ((getpos _obj select 1) > ((getpos _zone select 1) + _yVal)):goto "afterLoop"

if(((_obj buildingpos 1) select 0) == 0) then {goto "afterLoop"} else {_g = 1}

_m = "NULL"

{if(getmarkerpos _x select 0 == 0) then {_m = _x}}foreach DAC_BLD_Marker

?(!(format["%1",_m] == "NULL")):_m setmarkerpos getpos _obj

#loopPos

if(((_obj buildingpos _g) select 0) == 0) then {DAC_Buildings = DAC_Buildings + [[_zone,_obj,_g - 1]];_temp = _temp + [_obj];goto "afterLoop"}

_g = _g + 1

goto "loopPos"

#afterLoop

_pos = [(_pos select 0),(_pos select 1) + _checksb]

?((_pos select 1) > (_old1 + (_yVal * 2))) && ((_pos select 0) > (_old2 + (_xVal * 2))):goto "result"

?((_pos select 1) > (_old1 + (_yVal * 2))):_pos = [(_pos select 0) + _checksb,(_pos select 1) - ((_yVal * 2) + _checksb),0.5]

?(time > _stime):_stime = time + 5;if((DAC_Com_Values select 0) && ((DAC_Com_Values select 3) == 1)) then {player groupChat format["DAC still searching for buildings in zone_%1",getpos _zone select 0]}

goto "searchnext"

#result

deletevehicle _tPos

if((DAC_Com_Values select 0) && ((DAC_Com_Values select 3) == 1)) then {player groupChat format["DAC found %1 Buildings in Zone_%2",count _temp,(_mpos select 0)]}

exit

bye

silola

Share this post


Link to post
Share on other sites

I'm making progress. I have developed a script that returns all the positions of enterable buildings on a malden sized island in under 3 minutes. Still under development though, I'll keep you guys posted.

Share this post


Link to post
Share on other sites
Huh, why dont I have a show ID button?huh.gif?huh.gif?  crazy_o.gif

try hitting the advanced button, or click on it if that don't work wink_o.gif

Share this post


Link to post
Share on other sites

Do you have Resistance? That feature was implemented with OFP version 1.75 as far as I know.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×