OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Pilot on 15 Feb 2005, 02:09:07
-
I have a script that creates a munition, and I want that munition placed randomely within a certain area, I have tried this:
_cluster1 setpos [(getpos _bomb select 0) - random 20, (getpos _bomb select 1) - random 5, (getpos _bomb select 2)]but it doesn't work, any suggestions?
-
check out Johann's tute on scripting here, he has several one like that in it I believe.
http://www.ofpec.com/editors/browse.php?category=1_3 (http://www.ofpec.com/editors/browse.php?category=1_3)
-
Student pilot, this script will always place the munition to the left and below (looking at the map) the main munition, _bomb1.
Since random(x) always returns a positive value from 0 to x, try this line instead to get random placement in all directions:
_cluster1 setpos [(getpos _bomb select 0)+20*(random(2)-1), (getpos _bomb select 1)+5*(random(2)-1), (getpos _bomb select 2)]
Since 'random(2)' returns values between 0 and two, (random(2) - 1) returns values between -1 and 1. Therefore placement in the 'x' direction occurs between 20 metres infront and -20 metres behind _cluster1, likewise with the 'y' direction betw. -5 and 5.
-
Thanks for the replies, Tyger and Fragorl. It turns out I had another problem with my script, so the random was working the whole time. ::) Thanks especially for your suggestion Fragorl! I didn't know what you suggested could be done, it will make my job much easier!
Topic Solved