Jump to content
DanBonehill

Random spawning with Script

Recommended Posts

Hi all,

I'm not sure if this is the right place to put this question but it seemed to fit the best.

I'm creating a mission in which I am spawning the AI in using script. This is script I've made myself. The mission is to destroy a series of Devices that will be spawned in, I want them to spawn in a random location within a given area so as to make it re-playable.

The mission is in Molos in the North East of Altis. I have my script working and the devices spawn in as I want. I came across a post someone where someone advised to use something like the below to randomize the spawning. The code is

Dev1 = createVehicle ["Land_Device_assembled_F", [[[_Pos, random 100 + 50]],["water","out"]] call BIS_fnc_randomPos, [], 0, "NONE"];

_Pos is defined above and is a marker which is at the centre of the town.

As I said this all works and they Devices do spawn in and at a random place however I'm not sure what the "random 100 + 50" actually means. Changing these values does change where they spawn but not by much it appears. Does anyone know how the above works? and what changing the numbers actually represents? Or is there a better way to do what I'm trying to do?

Thanks.

Share this post


Link to post
Share on other sites

It means that it will pick a random number from 0-100 then add 50 to it, so basically this means BIS_fnc_randomPos will search an area of 50 meters plus whatever (random 100) returns, so your radius will range from 50-150 meters.

Share this post


Link to post
Share on other sites

Hey guys,

With relation to "BIS_fnc_randomPos", how do I randomize the function ONCE in a whole script? (I am aware "BIS_fnc_SelectRandon" can be done once, but not "BIS_fnc_randomPos")

If I am correct, I could use a custom condition (within the function's params) to check if a variable is null, which will store the pos. (If it is not null, it will not run, therefore it will randomize once)

Share this post


Link to post
Share on other sites

Full code:

_getPos = [] call BIS_fnc_randomPos; //Randomizes position on map
_array = _getPos call BIS_fnc_PosToGrid; //Converts _getPos into Grid
_getGrid = [_array, ""] call CBA_fnc_join; //Joins _array together into proper Grid Reference

_crate = "B_CargoNet_01_ammo_F" createVehicle [0,0,0]; //Creates crate
_crate setPos _getPos; //Sets the crate's position

/*

RESULT: "DIFFERENT POSITIONS"

*/

If you test it within a .sqf file, you will notice that with the given Grid Reference will end up fake for the player, as the crate will not be there. (Another words, I need _getPos to generate one position for the whole script, so it works correctly)

Share this post


Link to post
Share on other sites

I'm still not too sure what your're actually after, but you have to provide at least the first 2 arguments for BIS_fnc_randomPos to get a position to return. I think you may not understand what the randomPos function does, but again, not too sure at this point.

Share this post


Link to post
Share on other sites

I do know how it works, I just want it to generate ONE (1) position for the whole script. I don't want it to generate another pos if, say I mention it again e.g.:

test = test + _getPos; //This calls the function again to generate another pos, which I do not want it to do

I am trying my best to explain this so much simpler. I want the function (BIS_fnc_randomPos) to generate a pos, then store the pos so I can use that same pos later on in the script.

Share this post


Link to post
Share on other sites

If you don't want another random position, just execute the randomPos once?

Or: once you run it, store the result in a global variable and add a check to only run it when the variable doesn't exist.

:huh:

Share this post


Link to post
Share on other sites

Thank you so much Greenfist! :D (and to you, Jshock :) )

I seem to have found an alternative by destroying the function with nil, after it has stored a pos in another variable. (It may possibly report an undefined variable since the function will not exist, but I'll come up with a solution once I test Greenfist's alternative)

Share this post


Link to post
Share on other sites

Thank you so much Greenfist! :D (and to you, Jshock :) )

I seem to have found an alternative by destroying the function with nil, after it has stored a pos in another variable. (It may possibly report an undefined variable since the function will not exist, but I'll come up with a solution once I test Greenfist's alternative)

 

Sorry, but my curiosity has got the best of me, what is the full context of what your're trying to do, because both myself and Greenfist seem to be missing something here, as the randomPos function only runs once, and from the given information there is no loop or similar structure involved that would cause the function to run more than once?

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

×