OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Vic on 25 Feb 2009, 10:39:40
-
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?
-
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 :(
-
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.
-
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:
_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!).
-
You could replace all of that with:
if (5 < random 10) then {deleteVehicle BMPName} else {deleteVehicle TankName} :)
-
Thanks all, I went for the init line solution:
if (alive tank) then {{deleteVehicle _x} forEach crew this; deleteVehicle this}
-
You could replace all of that with:
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.
-
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.
{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.
-
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.
-
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:
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. ;)