Home   Help Search Login Register  

Author Topic: random  (Read 1664 times)

0 Members and 1 Guest are viewing this topic.

headshot_snipe

  • Guest
random
« 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

Code: [Select]
~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
« Last Edit: 01 Jun 2004, 13:46:30 by headshot_snipe »

PsyWarrior

  • Guest
Re:random
« Reply #1 on: 01 Jun 2004, 14:24:32 »
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

Offline revellion

  • Contributing Member
  • **
    • My Website
Re:random
« Reply #2 on: 01 Jun 2004, 14:32:30 »
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
Code: [Select]
_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
Best Logistic Addons and Missions: www.TheChainOfCommand.com

headshot_snipe

  • Guest
Re:random
« Reply #3 on: 01 Jun 2004, 14:42:57 »
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



Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:random
« Reply #4 on: 01 Jun 2004, 14:59:08 »
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.
Plenty of reviewed ArmA missions for you to play

PsyWarrior

  • Guest
Re:random
« Reply #5 on: 01 Jun 2004, 18:40:46 »

Oh, yeah... forgot about converting to whole numbers...

Silly me... ::)

-PsyWarrior

Strango

  • Guest
Re:random
« Reply #6 on: 30 Mar 2005, 04:39:02 »
Here's the code I use to get a number in a certain range:

Code: [Select]
_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.
« Last Edit: 30 Mar 2005, 04:39:38 by Strango »

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:random
« Reply #7 on: 30 Mar 2005, 17:59:35 »
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.
http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:random
« Reply #8 on: 30 Mar 2005, 21:11:55 »
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:

Quote
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
Check out my Camouflage Collection! New items added 31 July 2005.

bluehand

  • Guest
Re:random
« Reply #9 on: 31 Mar 2005, 10:55:41 »
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.