Jump to content
Sign in to follow this  
ShinShin

Generate Units Within Area, With Marker as Center.

Recommended Posts

Okay...

I'm trying to Make a Script which I Can Call from my "Init.sqf" & it'll Generate Hostile AI Units around the Desired Marker Area.

But Now...

Before you help me. (If you Do!)

Please Do Not Create it for Me... Nor point me toward something Similar that's already Made & Done.

With THAT Being Said... Can Someone, ANYONE, Help me Continue it.

I don't have much (or if Anything at all). But I Don't even Know where to Start/Begin from after What i've already Started :( :icon_neutral:

___________________________________________________________________________________________________________________________

Here's the Beginning of the Script...

Script...

GenerateUnits.sqf

// CALL via "Init.sqf": _null = ["MARKERNAME",400,100,50] execVM "Kays_Scripts\GenerateUnits.sqf";

_Marker = _this Select 0; [b][size=1]//[/size][/b][color="#696969"]Center Marker which Units Will Spawn Around[/color]
_SpawnSize = _this Select 1; [b][size=1]//[/size][/b][color="#696969"]Range Which Units Can Be Created Within[/color]
_DistanceToPlayer = _this Select 2; [b][size=1]//[/size][/b][color="#696969"]Distance from Player When Unit is Created[/color]
_AmountOfUnits = _this Select 3; [b][size=1]//[/size][/b][color="#696969"]How many Units You'd Like to be Made[/color]

Thanks In Return!

Share this post


Link to post
Share on other sites

Before you create a unit you'll need to create a group. However, before you can create a group you need to have created a center. The simplest method of doing so is just to put down a unit of the side you'll be making units for in some obscure part of the map. You can even set it's "Probability of Presence" to 0%, it just needs to be on the map. Once you have that you can createGroup and createUnit to your hearts content (well, as long as your heart is content with 144 groups per side that is!) You can also use the createCenter command, but plopping a bad guy on the map first is a good habit to get into.

So what you can do is have pre-placed markers around and spawn units at them when your player gets within range or whatever method you desire. For the amount of units you can create one per AmountOfUnits by using the forEach command to "loop" the createUnit to make multiples of them, like this:

// Create 3x USMC Crewmen using a pre-created group called "myGroup" within 10m of a marker called "mySpawnMarker"
{_guy = myGroup createUnit ["USMC_Soldier_Crew", getMarkerPos "mySpawnMarker", [], 10, "FORM"]} forEach [1,2,3];

Now, that's how to make a group one unit at a time, which can be annoying. A more powerful method of making groups is using the Functions module (Modules F7 in the editor) and making use of the BIS_fnc_spawnGroup function. This allows you to create a whole preset group at once, like the Groups F2 feature of the editor can put down.

So first decided where you want the enemy to spawn at (at preplaced markers or in towns or x distance and y direction from the player), then decide how you want them to spawn (when a player hits a trigger or gets within x meters of an object), then decide what you want to spawn (custom/individual units at a time or a whole group). Once you know that, then start making the code using the tools you learned here.


Another thing to consider is the intent of what you're trying to do. If you're trying to learn scripting, that's just great. However if you're trying to do something like make a randomized mission you might do it differently or without this much complicated scripting. Since it's running from init.sqf it'll only kick off when you start the game (assuming single player) which means you could just use units on the map rather than spawning them in. You can play around with things like Probability of Presence or even the Condition field to customize which units are actually going to spawn. You can use tricks like grouping leaders with Markers to determine where they spawn. You can use triggers to move units around the map depending on what the player does. The mission editor itself is quite powerful and can do a lot without a lot of scripting (or even with a little bit of scripting!)

So I'd definitely sit down and plan your mission out first. List what you want to happen and what resources are needed to make that goal happen, then you can get into the mechanics of how to make it happen.

Edited by kylania

Share this post


Link to post
Share on other sites

EDIT:

Thanks for the Reply & Suggestions.

I'd Very Much Rather the Enemy Spawn

"X distance and Y direction from the player"
&& How I Want them to Spawn... is By trigger, That Would be Nice.
"When a player hits a trigger"

and The Types to be Grouped or Individual Units.

"Individual Units at a time or a Whole Group"

-Thank you!

Edited by ShinShin

Share this post


Link to post
Share on other sites

I can help you with the first part if you want to find a point at a random distance and direction from an object.

I used _obj here...just replace with player. If you want to use a marker then change getpos to getMarkerPos.

//get the objects x coordinate
_objx = [b]getpos[/b] [color="#FF0000"]_obj[/color] select 0;

//get the objects y coordinate
_objy = [b]getpos[/b] [color="#FF0000"]_obj[/color] select 1;

//minimum distance from object to spawn
_mindis = 200;

//minimum distance + some other random distance from 0 to 200m
_randis = _mindis + random 200;

//get a random direction from 0 to 360
_randir = random 360;

//find the x coordinate for the spawn point
_newx = _objx + (sin (_randir) * _randis);

//find the y coordinate for the spawn point
_newy = _objy + (cos (_randir) * _randis);

//make your new position array.... can also be [_newx, _newy, 0]
[b]_pos[/b] = [_newx,_newy];

//spawn whatever here using [b]_pos[/b] for your position......
....
....
....

Not tested. Might have silly errors but you will get the idea.

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Errmm... I'm Gonna put this Kind of Scripting on Hold. I'm Not Having any Luck. lOL

Thanks for the Help though.

I Attempted multiple times. lool :o

Share this post


Link to post
Share on other sites

Post what you have done so far and we'll point out what you were missing or maybe ways to improve your ideas. :)

Share this post


Link to post
Share on other sites

I Would Have to Make another Attempt then, and Not Trash it this time :/

EDIT: I Might Just find something already made as a Temporary and also Read it to get a better more in depth idea.

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  

×