Jump to content
Sign in to follow this  
jakkob4682

How to use call compile format?

Recommended Posts

I'm trying to wrap my head around creating dynamic objects using call compile format, more specifically I'm trying to create my ied setup in a small town.

in triggerStatements i have

for [{i=0},{i=i<3},{i=i+1}] do {iedPos = [getMarkerPos "TC1",random 250,random 360] call BIS_fnc_relPos;iedBPos = getPos(nearestBuilding iedPos);call compile format ["ied%1 = 'BAF_IED_V1' createVehicle iedBPos"];iedList = nearestObjects [getMarkerPos "TC1",["LAND_IED_V1_PMC"],1000];player sideChat format ["%1",count iedList]};

the debug returns 0, so how can I create three ied's w/o having to do ied1-ied3 in a trigger?

Share this post


Link to post
Share on other sites

The syntax for format seems messed up. Try and put that on separate lines to see it better. Any reason you don't use the same calssname for what you dreate and what youtry to find?

Share this post


Link to post
Share on other sites

Try not to use call compile format as there is almost always a better way to get things done. For example:

iedList = [];
for [{_i=0}, {_i < 3}, {_i = _i + 1}] do
{
_iedPos = [getMarkerPos "TC1",250 * (sqrt (random 1)),random 360];
// This will give area to have equal chance for IED.
// Your randomization makes it so areas around the center are much more likely to have an IED.

_iedBPos = getPos (nearestBuilding _iedPos);
_ied = createVehicle ["BAF_IED_V1", _iedBPos, [], 0, "NONE"];
iedList set [_i, _ied]; // Create array with IEDs we have created
};

// Now if you already placed some PMC IEDs and want to make a list of them as well...
iedListPMC = nearestObjects [getMarkerPos "TC1", ["LAND_IED_V1_PMC"],1000];

Share this post


Link to post
Share on other sites

Example syntax:

for "_i" from 1 to 3 do
 {
 call compile format ["ied%1 = 'BAF_IED_V1' createVehicle iedBPos", _i];
 };

Share this post


Link to post
Share on other sites

@BlackMamb - As far as I can tell the actual class name is "LAND_IED_V1_PMC" when I use the empty IED's in the editor and use typeOf it returns that.

@Galv - I like that snippet, but I'm trying not to have to create a seperate script for it, although I might have to anyways because I'm using the createTrigger from CBA to script the explosions

@Ceeeb - Thats exactly what I was looking for thank you.

Share this post


Link to post
Share on other sites

ok so another question.... how then would I create a trigger on each of those ied's in a script?

Share this post


Link to post
Share on other sites

https://community.bistudio.com/wiki/createTrigger

After creating, use the "See Also" section for how to set the trigger's parameters.

Keep in mind the trigger is only created on the machine that runs the command and its condition is only checked on said machine, unlike triggers placed in the editor. This can actually make certain things easier, though, as for example in the case of an IED only the server needs to decide if/when to detonate it.

Share this post


Link to post
Share on other sites

I know how to create a generic trigger in a script the question was more about how to I create a trigger for each of the ied's created in the original for-from loop? i.e. what variable name do I use to represent each ied?

---------- Post added at 13:50 ---------- Previous post was at 13:42 ----------

The concept of this script is multi-layered, and I'm playing around with different idea's, but at the moment I'm trying to figure out how to:

Create dynamic IED's(I've tried reezo's module and it doesn't function 100% of the time, sometimes it doesn't work it all)

Create a trigger on those IED's(west present only activation)

Spawn a group at the nearest building of the ied location and have them ambush.

More to come... as I add more idea's.

Only wish I was a well versed scripter :(

Share this post


Link to post
Share on other sites

I've never had to use call compile format to be honest. There are many other solutions.

for "_i" from 0 to 2 do 
{
_iedpos = [getMarkerPos "TC1",250 * (sqrt (random 1)),random 360] call BIS_fnc_relPos;
_ied = createVehicle ["LAND_IED_V1_PMC",_iedpos, [], 0, "NONE"] ;
_trig = ([getPosATL _ied, "AREA:", [5, 5, 0, false], "ACT:", ["WEST", "PRESENT", true],"STATE:",["this","deleteVehicle (thisTrigger getVariable ['ied',objNull]); createVehicle ['Sh_125_HE',getPosATL thisTrigger, [], 0, 'NONE']",""]] call CBA_fnc_createTrigger) select 0;
_trig setVariable ["ied",_ied];
_mrk = createMarker[format ["ied_%1",random 1000],_iedpos];
_mrk setMarkerShape "ICON";
_mrk setMarkerType "DOT";
};

You're going to have to work on the nearestBuilding since it requires an object but that's a start.

Edited by cuel

Share this post


Link to post
Share on other sites

Cuel I'm using you're little snippett and it works fine, but how would I go about spawning a group nearby the ied after its detonated? As for the nearestBuilding question couldn't I just use nearestBuilding _ied? And thank you for the help, I'm trying to learn by doing, but the extent of what I can learn is limited to my understanding lol.

Share this post


Link to post
Share on other sites

I'm sure you can find a lot of examples on how to spawn groups :). A lot of people prefer using BIS_fnc_spawnGroup. You need the functions module placed.

Indeed you could just use the nearestBuilding on the ied object. However you won't know if it's an enterable house and you can't place it 'inside' the house in a buildingPos without some more code. I also don't see the appeal of a house blowing up as soon as you get close to it ;)

Share this post


Link to post
Share on other sites

It's just to add suspense to a mission I'm working on lol, and possibly some frustration with rng. Thought I saw somewhere a function to find the nearest enterable building will have to do some more looking into it. Originally I was going to make a secondary explosion nearby the original, so that when the support group/unit gets within range it detonates(IRA style bombing), and then spawn the group nearby to do the ambush. Might have to give up on spawning the group using nearestBuilding.

I know how to spawn a group, but how would I reference the trigger that activated to spawn the group?

Share this post


Link to post
Share on other sites

You could just execute a script in the statement of the trigger and pass the trigger.

for "_i" from 0 to 2 do 
{
_iedpos = [getMarkerPos "TC1",250 * (sqrt (random 1)),random 360] call BIS_fnc_relPos;
_ied = createVehicle ["LAND_IED_V1_PMC",_iedpos, [], 0, "NONE"] ;
_trig = ([getPosATL _ied, "AREA:", [5, 5, 0, false], "ACT:", ["WEST", "PRESENT", true],"STATE:",["this","deleteVehicle (thisTrigger getVariable ['ied',objNull]); createVehicle ['Sh_125_HE',getPosATL thisTrigger, [], 0, 'NONE']; 0 = [thisTrigger] execVM 'spawnGroup.sqf';",""]] call CBA_fnc_createTrigger) select 0;
_trig setVariable ["ied",_ied];
_mrk = createMarker[format ["ied_%1",random 1000],_iedpos];
_mrk setMarkerShape "ICON";
_mrk setMarkerType "DOT";
};

//spawnGroup.sqf
_pos = getPosATL (_this select 0);
//spaw some groups

Share this post


Link to post
Share on other sites

So new problem, I can get the function to work properly with a loop(meaning that the positions update when used with a sleep command), however if the unit remain in the same area the function continues to fire. So could I just use a for "_i" from 0 to 1 command when the script executes to call the function? i.e. if (condition) then {for-from}

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
Sign in to follow this  

×