OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: headshot_snipe on 01 Jun 2004, 13:44:48
-
hi all
is it possible to use the random command between a certain number, like only produce numbers between 1 and 5?
cuz i am making a script where shells are fired onto some infantry and i don't want all the infantry to die at the same time so i thought of making a delay for the infantry to go away but i also wanted some of them to die...
here is my script
~2
_boom = "HEAT120" camCreate [getpos _this select 0, getpos _this select 1, 1000]
~2
_boom setvelocity [0,0,-1000]
exit
at the second delay i would like it to be random between 1 and 10 seconds but i don't know how to do that. Any ideas?
I would also like to know how to make my script target a random unit, is that possible?
thx in advance
-
Greets,
Yes, entirely possible:
_delay = random 10
will generate a random number up to 10, and store it in the variable _delay.
so you could use the command
~ _delay
in conjunction with the above
Targetting a random unit: Yes, that is also possible. You could store units in an array, generate a random number based on the number of elements in the array, and select the unit from the array based on a random number...
Sorry if that doesn't make much sense ::)
OK: So, if you wanted to randomly target any EAST unit on the map, you would create a trigger over the whole map, set it to east present, and in the activation field, put
eastUnitsArray = thislist
in the script:
_elements = count eastUnitsArray
_random = random _elements
_target = eastUnitsArray select _random
That should give you a random target, from any east unit from the map.
Good luck... ;D
-Supr. Cmdr. PsyWarrior
-Psychic Productions
-
Greets,
Yes, entirely possible:
_delay = random 10
will generate a random number up to 10, and store it in the variable _delay.
so you could use the command
~ _delay
in conjunction with the above
Targetting a random unit: Yes, that is also possible. You could store units in an array, generate a random number based on the number of elements in the array, and select the unit from the array based on a random number...
Sorry if that doesn't make much sense ::)
OK: So, if you wanted to randomly target any EAST unit on the map, you would create a trigger over the whole map, set it to east present, and in the activation field, put
eastUnitsArray = thislist
in the script:
_elements = count eastUnitsArray
_random = random _elements
_target = eastUnitsArray select _random
That should give you a random target, from any east unit from the map.
Good luck... ;D
-Supr. Cmdr. PsyWarrior
-Psychic Productions
that won't cut it cause that would give a number that could be like 4.562562 or anything like it, so a revised version would be like this
_elements = count eastUnitsArray - 1
_random = random _elements
_random = _random - (_random mod 1)
_target = eastUnitsArray select _random
that will give "select" a number it can accept
if you wonder why i do "- 1" it's cause select does'nt go from 1 and up, but 0 and up
happy Scripting :D
-
thx for the reply guys, but another question ::)
when i fire my shells, i want it to be random as well, so in the x and y values i want something different, i tried randoming the values but it only goes from 0 to whateva number i put in
is it possible to generate a random number from -20 to +20?
thx
-
You can generate any random number you like. The command random generates a number: you then have to do the appropriate arithmetic on it to get it within the paramaters you want.
For example, to create a random number between -10 and +10 you would just have
_rand1 = random 20
_rand2 = _rand1-10
Use the command mod if you want to generate a whole number. Example in the online comref.
-
Oh, yeah... forgot about converting to whole numbers...
Silly me... ::)
-PsyWarrior
-
Here's the code I use to get a number in a certain range:
_MinNum = 5
_MaxNum = 20
_NumRange = _MaxNum - _MinNum
_Rand = (_NumRange * (random 1)) + _MinNum
Just put your Minimum value in _MinNum and your Maximum value in _MaxNum. The example above would give you something between 5 and 20.
-
General Barron made a very usefull Function:RandomInt.sqf (Its in the Function library)
The result is a random integer (whole number) between 2 settings.(Min-Max)
I used it in our Skirmish template to select Random Lightsettings and Random music.
In your example:
randomInt = preprocessFile "randomint.sqf" ---> in the init.sqs
Randomnumber = [-20,20]call RandomInt (Gives an integer between -20 and 20)
~Randomnumber or selection= array select randomnumber
PS:in MP you need to run a script on the server only and PublicVariable the outcome,or everybody would have a different random number.
-
One of the great attributes of OFP: One problem, many solutions. :o
I had been using Fragorl's method that he posted awhile back to get a random bomb placement:
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.
Seeing some other (cleaner,shorter) solutions, I may have to start using some of these examples! ;D
Wadmann
-
Another quick and easy trick I use for spreading shells about a target is:
_base = getpos target
_bx = (_base select 0) + (random 100) - (random 100)
_by = (_base select 1) + (random 100) - (random 100)
_bz = (_base select 2) + (random 20)
_ammo CamCreate [_bx,_by,_bz]
By adding and subtracting random numbers your shell could be 100 m away, but is likely to be much closer - the spread is heavier nearer the target point.
The random height is handy because it makes the shells drop for a moment - so the explosions don't come on a regular rhythm.