Home   Help Search Login Register  

Author Topic: Fired and random in a script  (Read 3036 times)

0 Members and 1 Guest are viewing this topic.

Offline Clayborne

  • Members
  • *
Re: Fired and random in a script
« Reply #15 on: 27 Dec 2009, 10:43:04 »
Thanks alot, guys.

Not to be a pest but I've found a need to use that script not only with groups but with group arrays. I amended the script yesterday for this and it worked to a point (until it stopped because of the 0 thing). Does this look ok? The array Group_array1 is defined in the init.sqs. (obviously I will change the random thing as per your suggestions)



Code: [Select]
#assign

?(contact==1) : goto "end"

; wait between 7 - 15 seconds
~(7 + random 15)

; choose a loon at random - make sure he's alive
_r = random ({alive _x} count group_array1)
_r = _r - _r % 1
_speaker = (group_array1) select _r

; choose a random goto marker
_saywhat = random 5
_saywhat = _saywhat - _saywhat % 1
goto format ["radio%1", _saywhat]


#radio1
_speaker say "recon1"
goto "assign"


#radio2
_speaker say "sweepsector"
goto "assign"


#radio3
_speaker say "checkzone"
goto "assign"


#radio4
_speaker say "hear"
goto "assign"


#radio5
_speaker say "radiocheck"
goto "assign"

#end

exit

EDIT

Also I guess I should ask if this would work ok in Multiplayer. I know in its current form it's likely that each player will hear a different sound, but that isn't really important.

EDIT AGAIN!

I realised I shouldn't just take people's help without fully understanding what is going on, so could someone explain what exactly is happening in this section;

_saywhat = random 5
_saywhat = _saywhat - _saywhat % 1
goto format ["radio%1", _saywhat]


Okay so _saywhat is the random number. Does the goto format ["radio%1", _saywhat] part mean that as long as the #radio sections listed below are numbered between 0 and 5, that the script will automatically select the one that corresponds to whatever _saywhat is? If it goes to #radio1, is it because _saywhat is between (or equal to) 0 and 1?

Again, thanks for the help!

« Last Edit: 27 Dec 2009, 14:02:12 by Planck »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Fired and random in a script
« Reply #16 on: 27 Dec 2009, 14:07:15 »
First of all use the code format function when posting code, makes it easier to read.

It depends on what you mean by 'group arrays'. At first glance your script won't quite work because since you're now using an array of groupnames - if that's what the group arrays are - the script is selecting a group at random to utter the radio chatter rather than an individual loon. Once you've randomly determined the group you need to repeat the random selection to determine which loon of that group will do the chattering.

Code: [Select]
#assign

; loop again?
? (enemy_contact) : exit

; wait between 7 - 15 seconds
~(7 + random 8)

; choose a group at random
_r = random (count group_array1)
_r = _r - _r % 1
_speakers_group = (group_array1) select _r

; choose a loon at random - make sure he's alive
_r = random ({alive _x} count units _speakers_group)
_r = _r - _r % 1
_speaker = (_speakers_group) select _r

; choose a random goto marker
_saywhat = random 5
_saywhat = _saywhat - _saywhat % 1
goto format ["radio%1", _saywhat]


#radio0
_speaker say "recon1"
goto "assign"


#radio1
_speaker say "sweepsector"
goto "assign"


#radio2
_speaker say "checkzone"
goto "assign"


#radio3
_speaker say "hear"
goto "assign"


#radio4
_speaker say "radiocheck"
goto "assign"

Take a look at the format command in the COMREF - one of the best resources you'll find for editing. It can be used for a great many handy things. And yes, you've grasped exactly what it does in the above context, i.e. appends whatever the value of _saywhat is to the string #radio.

If the enemy_contact variable is just going to be true or false make it a boolean; and if all you're going to do is exit the script when enemy_contact becomes true, just put the exit command there with the conditional rather than jumping to another script marker. Of course it could be you intend enemy_contact to have more than 2 states, and you might want to do something before the script exits, in which case your approach is exactly right.

Looks like you're getting the hang of it. :good:
« Last Edit: 27 Dec 2009, 14:09:08 by bedges »

Offline Clayborne

  • Members
  • *
Re: Fired and random in a script
« Reply #17 on: 27 Dec 2009, 15:19:28 »
Sorry, I should have been clearer; The 'group array' is simply an array of units who are not grouped together in the editor, but on whom I still want to run the script. It should run the same as the original script except the guys are not in the same group.

I just tested it using the script I posted above, having fixed the random 0 issue, and it seems to work fine. So do both of them look like they should run no problem in MP?
« Last Edit: 27 Dec 2009, 15:26:34 by Clayborne »