Jump to content
Sign in to follow this  
clydefrog

Spawning enemy by distance

Recommended Posts

What's the best way to go about having enemy only spawn at a certain area when you get close to them? Which are the best scripts for doing something like this?

example: a group of 10 enemy infantry spawn in a village when you get within 500 metres of them

Thanks.

Share this post


Link to post
Share on other sites

A trigger that runs a script that spawns units.

Trigger act: blufor present

on activation

0 = ["spawnmarker"] execVM "spawnUnits.sqf";

spawnUnits.sqf:

if (!isServer) exitWith {};
_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["RU_Soldier_SL", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit2 = _group1 createUnit ["RU_Soldier", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit3 = _group1 createUnit ["RU_Soldier_Medic", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit4 = _group1 createUnit ["RU_Soldier_AR", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
[_group1,_spawnPos,200] call bis_fnc_taskPatrol;

Edited by cuel

Share this post


Link to post
Share on other sites
A trigger that runs a script that spawns units.

Trigger act: blufor present

on activation

0 = ["spawnmarker"] execVM "spawnUnits.sqf";

spawnUnits.sqf:

if (!isServer) exitWith {};
_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["RU_Soldier_SL", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit2 = _group1 createUnit ["RU_Soldier", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit3 = _group1 createUnit ["RU_Soldier_Medic", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit4 = _group1 createUnit ["RU_Soldier_AR", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
[_group1,_spawnPos,200] call bis_fnc_taskPatrol;

Great thanks, what does the "NONE" and the [], 1, before it refer to?

Share this post


Link to post
Share on other sites

It's the attribute that you can enter in the editor IIRC. Like none, formation, flying.

Should be "NONE", "FORM", "FLY".

Share this post


Link to post
Share on other sites

Ahh, thank you. I guess those are useless in this case as they are not set to move in a formation anyways, just stand there.

Share this post


Link to post
Share on other sites

cuel, how could this script be modified so that the units spawned don't wonder off and instead stay in a given radius or something, it works but the problem is they just walk off wherever so you can't really use it to have units defend an area.

Share this post


Link to post
Share on other sites

I made them patrol, remove the line at the bottom :)

[_group1,_spawnPos,200] call bis_fnc_taskPatrol;

Alternatively lower the 200, that's the maximum distance between waypoints.

Share this post


Link to post
Share on other sites
I made them patrol, remove the line at the bottom :)

[_group1,_spawnPos,200] call bis_fnc_taskPatrol;

Alternatively lower the 200, that's the maximum distance between waypoints.

Ok, so then they'll just stand still? What I meant was patrol but only in a fixed area, as it is they seem to patrol anywhere and travel a long way from where they spawn.

Share this post


Link to post
Share on other sites

Yes if you remove it they'll stand still.

If you want more control over their patrols I'd recommend using UPSMON or a similar script. If you're using CBA there's this function.

Share this post


Link to post
Share on other sites
Yes if you remove it they'll stand still.

If you want more control over their patrols I'd recommend using UPSMON or a similar script. If you're using CBA there's this function.

Ok thanks, I looked at UPSMON but I'm using the Zeus AI mod and it sounded like it could clash with it. I'm using CBA so I'll check that out, thanks. But I guess with this CBA one you have to run it from a group leader or something and not from a trigger than spawns them like the one you gave me.

Edited by clydefrog

Share this post


Link to post
Share on other sites

Should be no problem, try this:

if (!isServer) exitWith {};
_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["RU_Soldier_SL", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit2 = _group1 createUnit ["RU_Soldier", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit3 = _group1 createUnit ["RU_Soldier_Medic", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit4 = _group1 createUnit ["RU_Soldier_AR", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
[_group1, _spawnPos, 150, 7, “MOVEâ€, “AWAREâ€, “YELLOWâ€, “FULLâ€, “STAG COLUMNâ€, “â€, [3,6,9]] call CBA_fnc_taskPatrol;

Share this post


Link to post
Share on other sites
Should be no problem, try this:

if (!isServer) exitWith {};
_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["RU_Soldier_SL", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit2 = _group1 createUnit ["RU_Soldier", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit3 = _group1 createUnit ["RU_Soldier_Medic", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
_unit4 = _group1 createUnit ["RU_Soldier_AR", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "NONE"]; sleep 0.2;
[_group1, _spawnPos, 150, 7, “MOVEâ€, “AWAREâ€, “YELLOWâ€, “FULLâ€, “STAG COLUMNâ€, “â€, [3,6,9]] call CBA_fnc_taskPatrol;

Thanks but it doesn't work, they don't spawn but when I enter the trigger my fps drops.

Actually it doesn't seem like the original one works either, nothing is spawning.

---------- Post added at 22:01 ---------- Previous post was at 21:32 ----------

Hmm ok I think it's working now, only after I put an opfor unit down on the map to test some other spawning script I got shown, weird.

Edit: Ok they spawn, but they just stand there and don't patrol.

Edited by clydefrog

Share this post


Link to post
Share on other sites

Yes you need something called centers if you want to spawn units this way. Those are created if there's a unit from that side in the mission from start. You can create a unit from each side and set their "probability of presence" down to 0% to circumvent this, or use this in your init.sqf.

Also seems like there was a problem copying the quotes directly from the CBA homepage so change the bottom-line to this :)

[_group1, _spawnPos, 150, 7, "MOVE", "AWARE", "YELLOW", "FULL", "STAG COLUMN", "", [3,6,9]] call CBA_fnc_taskPatrol;

Share this post


Link to post
Share on other sites

Yeah I read about that center stuff earlier today on the BIS fnc spawnGroup page, that's why I put it down as I was testing a script using BIS fnc spawnGroup.

Now it works :)

What was the problem with the code? It looked exactly the same as the original line when I looked at them both. Thanks a lot for this, just what I was looking for and this CBA one seems to have a good level of control.

Share this post


Link to post
Share on other sites

The quotes were not functional, I copied that directly from the CBA page.

“MOVEâ€

vs

"MOVE"

:)

Share this post


Link to post
Share on other sites
The quotes were not functional, I copied that directly from the CBA page.

“MOVEâ€

vs

"MOVE"

:)

Haha, I didn't notice that at all. Now if I want to call this script multiple times for different groups, do I need to make copies of it with different group names e.g. _group2, or can I always call the same script but just to different markers?

Share this post


Link to post
Share on other sites

You can use the same script with different markers.

_variable

are private to the script and gets destroyed when the script has finished running.

If they weren't private you would still just overwrite them and it would still work :)

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  

×