Jump to content
Rosso777

getPos player + 200 meters?

Recommended Posts

I am trying to modify a script that spawn an AI assistant. The original code spawns the AI directly on your position, but I want the AI to spawn about 200 meters from the current player position.

 

 

Here is the original line:     _unit = group player createUnit [_unitList select (round(random ((count _unitList) - 1))), getPos player, [], 0, "FORM"];

 

Here was my version that did not work:    _unit = group player createUnit [_unitList select (round(random ((count _unitList) - 1))), [getPos player + 200], [], 0, "FORM"];

 

I've tried digging around the BIKI but there wasn't much available on the getPos page. I also found this, but not sure if it's a completely different aspect: ((getPos player) vectorAdd [((random 400)-200),((random 400)-200),0])

 

Can anyone offer some insight?

 

Share this post


Link to post
Share on other sites

forget [getpos player + 200]    for:    player getPos [200,getDir player]

or even :   player getPos [100 + random 100, random 360]

 

by the way:   _unitList select (round(random ((count _unitList) - 1)))

selectRandom _unitList

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, pierremgi said:

player getPos [100 + random 100, random 360]

 

Thanks for your help, Pierre, I tested it and it works like a charm.

 

 

2 hours ago, pierremgi said:

by the way:   selectRandom _unitList

 

Is this for the script to randomize the AI that it spawns?

  • Like 1

Share this post


Link to post
Share on other sites

selectRandom  is able to select an element of an array at random. _unitList must be an array of existing classes (strings) of units.

So same thing as your code, but clearer.

 

See also selectRandomWeighted is you want to spawn more units of some types than others.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

selectRandom  is able to select an element of an array at random. _unitList must be an array of existing classes (strings) of units.

So same thing as your code, but clearer.

 

See also selectRandomWeighted is you want to spawn more units of some types than others.

 

Understood. I will give this a go and post my results as to help future similar issues. Thanks!

  • Like 1

Share this post


Link to post
Share on other sites
12 hours ago, pierremgi said:

See also selectRandomWeighted is you want to spawn more units of some types than others.

 

I needed this command for something else. Thanks!

Over a decade in SQF and still learning commands....

  • Like 2

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

×