Home   Help Search Login Register  

Author Topic: Condition of presence issue: spawn either a unit, or another  (Read 1893 times)

0 Members and 1 Guest are viewing this topic.

Offline Vic

  • Members
  • *
Simple mission, simple issue: I want to spawn randomly either a tank or a BMP.
Went for the obvious solution first, set the tank probability of presence to 50%, set the BMP's condition of presence to !alive tank. No workie, since the tank doesn't exist, alive tank returns 'bool'. Let's check it in this case, with a new condition: format["%1", alive tank] != "true". While hint-ing this one returns the proper result (true/false), the BMP is spawned even if the tank exists. Am I missing something perhaps?

Offline zwobot

  • Members
  • *
Re: Condition of presence issue: spawn either a unit, or another
« Reply #1 on: 25 Feb 2009, 11:18:03 »
The "condition of presence" is a bit of a dissapointment: it only works with very special commands/conditions.
In my experience the condition of presence works only if you use something like !cadetMode or inside a single group: alive <name of the group leader>.

It's a pity because the condition of presence could otherwise be used to easily randomize a mission and to adjust difficulty but that's how it is unfortunately  :(
"Executing tactics in real combat is the hardest thing one can ever do...well I've never given birth but..well whatever."

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Condition of presence issue: spawn either a unit, or another
« Reply #2 on: 25 Feb 2009, 14:11:16 »
There is usually more than one way to skin a cat.

Why not set the condition for the tank to 50% and the condition for the BMP to 100% but in the init field of the tank have an instruction to deleteVehicle the BMP.  Or in the int field of the BMP have something that checks to see if the tank is alive and if it is it then deletes itself.  To be  on the safe side you might want to use a script with a slight delay built in to ensure it always works whatever order the vehicles are created in.
 
« Last Edit: 25 Feb 2009, 14:14:02 by THobson »

Offline Ext3rmin4tor

  • Members
  • *
Re: Condition of presence issue: spawn either a unit, or another
« Reply #3 on: 25 Feb 2009, 17:47:48 »
You can do that this way. Place both the tank and the BMP in the mission editor, give them a name, like randomBMP and randomTank Create the init.sqs script for your mission and write the following code:

Code: [Select]
_rSeed = _random (1)
? (_rSeed <= 0.5): goto "deleteBMP"
goto "deleteTank"

#deleteBMP
deleteVehicle randomBMP
goto "end"

#deleteTank
deleteVehicle randomTank

#end
exit

This will delete either the BMP or the tank with a probability of 50% so that the result is you have just one of them at the mission start (Damn I had forgotten how bad  SQS syntax is, it took me 2 mins to write a if-else block!).
« Last Edit: 25 Feb 2009, 17:50:57 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Condition of presence issue: spawn either a unit, or another
« Reply #4 on: 25 Feb 2009, 18:14:58 »
You could replace all of that with:

Code: [Select]
if (5 < random 10) then {deleteVehicle BMPName} else {deleteVehicle TankName} :)

Offline Vic

  • Members
  • *
Re: Condition of presence issue: spawn either a unit, or another
« Reply #5 on: 26 Feb 2009, 10:46:46 »
Thanks all, I went for the init line solution:
Code: [Select]
if (alive tank) then {{deleteVehicle _x} forEach crew this; deleteVehicle this}

Offline Ext3rmin4tor

  • Members
  • *
Re: Condition of presence issue: spawn either a unit, or another
« Reply #6 on: 26 Feb 2009, 12:06:26 »
You could replace all of that with:

Code: [Select]
if (5 < random 10) then {deleteVehicle BMPName} else {deleteVehicle TankName} :)

Ah Right, but this is just a special case because the blocks contain few statements.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Condition of presence issue: spawn either a unit, or another
« Reply #7 on: 26 Feb 2009, 12:38:07 »
Quote
Ah Right, but this is just a special case because the blocks contain few statements.
Not really

Here is one I have used in a mission.

Code: [Select]
{if ((PrimaryWeapon _x in ["M16","AK74"]) and (5 > random 100)) then {_x removeMagazines "HandGrenade";_x removeMagazines (primaryWeapon _x);_x removeWeapon (primaryWeapon _x);_x addMagazine "KozliceBall";_x addMagazine "KozliceBall";_x addMagazine "KozliceBall";_x addMagazine "KozliceBall";_x addMagazine "KozliceBall";_x addMagazine "KozliceShell";_x addMagazine "KozliceShell";_x addMagazine "KozliceShell";_x addMagazine "KozliceShell";_x addMagazine "KozliceShell";_x addWeapon "Kozlice";_x selectWeapon (primaryWeapon _x)}} forEach (_tempLoons - units w_infantry_1Grp - units w_convoy_guardGrp - units w_guard_2Grp - units group w_baseguard_1)
I am not sure if there is a limit to how much can be included in each block.  If there is a limit I have certainly not found it.  Admittedly they can become difficult to read but you can space them out to help with that and it is still easier to read than the ? : Goto stuff  Given that this is just one of many similar instructions in quite a large script I would hate to have had to write it that way.

@Vic
Glad you found a solution.  As I said there are often many ways to do what you want - you just need to find something that works for you.
« Last Edit: 26 Feb 2009, 13:55:28 by THobson »

Offline Ext3rmin4tor

  • Members
  • *
Re: Condition of presence issue: spawn either a unit, or another
« Reply #8 on: 27 Feb 2009, 22:27:13 »
There is no limit on block instructions but you can place at most 4096 charcaters per line. This means that goto is the only option for long scripts.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Condition of presence issue: spawn either a unit, or another
« Reply #9 on: 28 Feb 2009, 09:55:53 »
I certainly have no problem with using a goto in OFP scripting.  I used it a lot, but I see so much ugly code using ? : goto that would be so much easier to write and understand using:

Code: [Select]
if (condition) then {instruction block} else {instruction block}
(Quite often one of those instruction blocks is a goto)

Likely to be way off topic now so probably best to end here. ;)