Home   Help Search Login Register  

Author Topic: Array of numbers..  (Read 1289 times)

0 Members and 1 Guest are viewing this topic.

Offline RT-SuperTron

  • Members
  • *
  • Prey...you will be
Array of numbers..
« on: 16 Jun 2003, 01:31:06 »
Toying around with the objectID numbers, we tried to figure out how make an array of exmpl. [10,20,30,40] and letting a script choose a random number of thoose in the array.
It might be because I allways work with OFP untill very late night, or maybe im just plain stupid, but i cant get the freakin thing to work.

Please help...

[RT]SuperTron
+- PAIN IS YOUR FRIEND, IT WILL REMIND YOU THAT YOU ARE ALIVE -+

deaddog

  • Guest
Re:Array of numbers..
« Reply #1 on: 16 Jun 2003, 02:48:20 »
Here is how to generate a random integer between 0 and 6:

_count=(random 1000)
_count=(_count-(_count mod 1)) mod 7

If you want an integer between 0 and 49, for example, change the mod 7 to mod 50.

If you have an array of strings like:

_strings=["hello","goodbye","huh?","blah"]

and you want to randomly pick one of those strings, then do this:

_count=(random 1000)
_count=(_count-(_count mod 1)) mod 4

player sidechat (_strings select _count)

Hope that helps.  :)


Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Array of numbers..
« Reply #2 on: 16 Jun 2003, 02:51:29 »
@ dead - isnt it just easier 2 do

_rnd = random (count arrayname)

da select command exepts real numbers (not ints ;D) i know cuz i use dat daily - never had a prob

player sidechat (_strings select _rnd)

;) ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

deaddog

  • Guest
Re:Array of numbers..
« Reply #3 on: 16 Jun 2003, 03:03:19 »
Quote
da select command exepts real numbers (not ints )

I didn't know that.  :)  I figured that you can't select the 2.145th element of an array.  ;D  The select command must ignore everything after the decimal point.

That will make some of my scripts a little smaller, which is always a good thing.  Thanks LCD  :thumbsup:

Hey [RT].  That's how you generate random integers, at least.  ;D

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Array of numbers..
« Reply #4 on: 16 Jun 2003, 03:08:23 »
its alwayz kool 2 learn new things ;) :booty:

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline RT-SuperTron

  • Members
  • *
  • Prey...you will be
Re:Array of numbers..
« Reply #5 on: 17 Jun 2003, 00:01:47 »
 :) It helpÂ's alot but I think we have a little misunderstanding. My problem is more in the direction of this..
How do I make a script, that will randomly choose between preselected Object ID numbers. Im trying to mimic the effect of having multiple Gamelogis or markers as random WPÂ's, but I prefere to work with Object IDÂ's instead of cluttering the map with multiple WPÂ's, triggers etc..

So instead of choosing between for example.:
[_trg1,_trg2,_trg3,_trg4]

I want to choose between preselected numbers like [165,12377,45308,1433]

and then make something like:
("_x domove getpos (object RandomlyChoosenVariableFromMyPreselectedList)") foreach units _this


The other half [RT]FatherBob and I, are trying to make a more "real and alive" environment, to get the presure on the player(s) shoulder, instead of the CPU. Currently we experiment with Patrol, Sniper and Stalker scripts, so right now the question is how to make this little thing "above" work.

I have more questions pending, of which I can find no answers to in the EdDepot or by browsing the Forum, but lets take them one by one.

Thanks for your quick replies..

[RT]SuperTron, Regards from [RT]FatherBob
+- PAIN IS YOUR FRIEND, IT WILL REMIND YOU THAT YOU ARE ALIVE -+

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Array of numbers..
« Reply #6 on: 17 Jun 2003, 00:43:08 »
Quote
("_x domove getpos (object RandomlyChoosenVariableFromMyPreselectedList)") foreach units _this

1st thing - use da move command not da domove - den u can issue it only 2 ur leader ;) not 2 da whole group

sec -"foreach units _this" wont work but - "foreach units group _this" will

3rd - da new line wil look like

Code: [Select]
"_x move getpos (object (arrayname select (random (count arrayname))))")foreach units group _this
LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Array of numbers..
« Reply #7 on: 17 Jun 2003, 00:46:57 »
You mean series of arrays, as in series of possible waypoints? That would mean you need an array for each possible series of arrays. Then you select one of those and make the units go through them, possibly with a loop or some @ contraption.

Quote
The select command must ignore everything after the decimal point.
to be precise it's the mod command that does that. It rounds up the decimals. So this would be what I gather you wan't:
Quote
_path1 = [12472,12123,12125]
_path2 = [12123,12472,12125]
_paths = [_path1,_path2]
_rndpath = random (count _paths]
_rndpath = _rndpath - (_rndpath mod 1)
_selpath = _paths select _rndpath

_wp = 0
#moveloop
_curwp = _selpath select _wp
~10
if ((leader groupname) distance (object _curwp) < 10) then {(leader groupname) move getPos (object _curwp); goto "moveloop";};
_wp = _wp + 1
? (! alive (leader groupname)) : exit
? (_wp < (count _selpath)) : goto "moveloop"
the main reason that is a loop that gives the move command all over again is that something might happen along the way why the AI shouldn't continue or them they just might die off. Well, thinking of it now, I don't know what you wan't.  ;D do you yourself?
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Array of numbers..
« Reply #8 on: 17 Jun 2003, 00:52:29 »
@ MI_Fred

didnt we pass da mod thingy b4 ?

Quote
_rnd = random (count arrayname)

da select command exepts real numbers (not ints)

no need 2 use mod command wen usin select ;)

LCD OUT

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Array of numbers..
« Reply #9 on: 17 Jun 2003, 01:00:53 »
Naw I wasn't using anything yet. I ment to provide a solution to the whole thing  ;) but no need to use mod when using select ?? umh, odd. I thought that there was. So it can round it up?
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Array of numbers..
« Reply #10 on: 17 Jun 2003, 01:30:08 »
yeah - u can try it if u want ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Bremmer

  • Guest
Re:Array of numbers..
« Reply #11 on: 17 Jun 2003, 10:33:08 »
Quote
@ dead - isnt it just easier 2 do

_rnd = random (count arrayname)

da select command exepts real numbers (not ints ) i know cuz i use dat daily - never had a prob

LCD - I remeber having a problem with this before. If I remember correctly it does not select from the elemnts with equal probability.

Take a sample array with 10 elements (they will be labelled 0 to 9). A random number based on your method will be between 0 and 10. If my memory hasn't failed numbers between -0.5 and +0.5 will select element 0, 0.5 and 1.5 will select 1, 1.5 and 2.5 will select 2 etc... The problem is that since the random number cannot be below 0 then the first element is half as likely to be picked as the others. What happens if the random number is above 9.5 I can't remember (it should select element 10 which does not exist).

Has anyone else come across this problem?

You could use _rnd = (random (count arrayname)) - 0.5 to get around this problem, but I usually use the mod method.

[edit] Just did a quick check and found that if the selection number is > 9.5 in the example above then the result is <null>. Definetely something to be careful of. [/edit]

« Last Edit: 17 Jun 2003, 21:24:51 by Bremmer »

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:Array of numbers..
« Reply #12 on: 17 Jun 2003, 14:35:47 »
Say you'd use toadlife's function, would that get what you want ?

toadlife also uses the mod method, so it seems that if you pass your array and then shuffle it using his function, you'd get something really randomly chosen.

There is also another way, if you use four empty markers, which you'll place on your objects, and  link them together with the F2 drag line : say if you call one "destination", it will occupy one of the four different positions every time you start the mission.
In that case, you'll have something like :

Code: [Select]
"_x move getmarkerpos ""destination""" foreach units group _this
Hope this helps.
« Last Edit: 17 Jun 2003, 14:38:37 by Igor Drukov »

Offline RT-SuperTron

  • Members
  • *
  • Prey...you will be
Re:Array of numbers..
« Reply #13 on: 17 Jun 2003, 18:23:11 »
 ;D Thanx MI_Fred, you where "spot on" dude. In your example you used a path of 3 WPÂ's (actually 2 paths). I was working around something similar, but i couldnt make it work. So if I got this right, I would have to make a variable for each WP I want (unless im using a path like yours) and then put them together in an array..Now that actualy makes a lot on sence, since I then would be able to add new WPÂ's when I need to, and remove them from the array when they are unwanted or unsafe..hmm cool. Thankx guys..


[RT]SuperTron
+- PAIN IS YOUR FRIEND, IT WILL REMIND YOU THAT YOU ARE ALIVE -+

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Array of numbers..
« Reply #14 on: 17 Jun 2003, 22:38:04 »
@ brem - tanks m8 - i ust never had da chance 2 have dis hapening  ;D

@ RT - problem solved ? solve boton is on dabotom ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta