Home   Help Search Login Register  

Author Topic: Radio/music script for all players  (Read 1563 times)

0 Members and 1 Guest are viewing this topic.

renzo

  • Guest
Radio/music script for all players
« on: 25 Nov 2005, 16:56:44 »
I'm trying to create a radio/music script that can be used to play songs of the game but the problem is I can't get it to work for everyone. The selected music plays only for the person who selects it. My script is as follows

On players initialization field: radio=true

trigger with condition: radio
trigger's on activation: m0=player addaction ["radio","radio.sqs"]

(adds "radio" command on use list)


radio.sqs file
Code: [Select]
m8=player addaction ["back","m8.sqs"]
m1=player addaction ["Orkideahauta","m1.sqs"]
m2=player addaction ["Armo","m2.sqs"]
m3=player addaction ["Lyijykyyneleet","m3.sqs"]
m4=player addaction ["Sadonkorjuu","m4.sqs"]
m5=player addaction ["Länsi","m5.sqs"]
m6=player addaction ["Tiennäyttäjä","m6.sqs"]
m7=player addaction ["no music","m7.sqs"]
player removeaction m0
exit
(removes "radio" command and adds those tunes to the use list)


m1.sqs - m8.sqs
Code: [Select]
0.5 fademusic 0.5
player removeaction m1
player removeaction m2
player removeaction m3
player removeaction m4
player removeaction m5
player removeaction m6
player removeaction m7
player removeaction m8
TitleText ["Airut - Orkideahauta","Plain"]
playmusic "FDFairut_orkideahauta"
m0 = player addaction ["radio","radio.sqs"]
exit
(removes tunes from the list, starts playing the selected music and enables "radio" command again)

m1-m6 are like above, m7 just goes back to use list and m8 stops the music.


The problem obviously lies in the selection "player". I've tried some group selections (mygroup=group this) and some "select action" scripts and even using trigger that normally works but no bonus. Perhaps I'm too stupid to understand what's wrong and therefore I'm asking help here :)
« Last Edit: 25 Nov 2005, 16:59:46 by renzo »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Radio/music script for all players
« Reply #1 on: 29 Nov 2005, 23:48:24 »
The reason the only player that hears the music is the player that activates the addaction is because ADDACTION is a local command, meaning anything the action runs will only be localised on the machine it was run on.

What you want to do is possible, however you will need to have your addaction create the following

1) Variable A
This will define which music track should be played
Lets call it tx_track
variable type would be a "Number"
eg tx_track = 3

2) Variable B
This will activate a trigger, which will run on everyones client
variable type would be a "Boolean"
lets call it tx_MusicOn

The trigger would be:
a) Repeating
b) Condition: tx_MusicOn
c) On Activation: [tx_track] exec Playmusic.sqs"

Playmusic.sqs
Quote
if(tx_Playing)then{hint "Music is already playing"; exit} else {tx_Playing = true}
;;;
;;;add code here to temporarily remove all the select music addactions
;;;


_label = _this select 0
goto "LABEL"

;;(this basically means goto tx_track)

#1
Playmusic "Music1"
~
(Number of seconds it takes to play the track)
;;;; wait length of time it takes music track to play

goto "END"

#2
Playmusic "Music2"
~
(Number of seconds it takes to play the track)
;;;; wait length of time it takes music track to play

goto "END"

#3
Playmusic "Music3"
~
(Number of seconds it takes to play the track)
;;;; wait length of time it takes music track to play
goto "END"

#END
;;;
;;;add code here to re-add all the select music addactions
;;;no point in allowing players to select another track while any music is currently playing
;;;

tx_Playing = false
tx_MusicOn = false

;; this allows the resetting of the trigger ready for the next music requestexit

;; tx_Playing is used to check if any music is already playing, if it is, then simply exit



--------------------------------------------------------------------------------------------------
I would use 2 levels of addactions
Level 1
This would simply be a "Select Music" action
Selecting this would then run a script that would remove this action and in its place add an action for each music track that you wanted to offer

so it would be something very basically like the following

tx_Selection = Player addaction ["Select Music", "select.sqs"]

The select.sqs would
a) Removeaction tx_selection
and add actions
Play track 1
play track 2
play track 3 etc
 it would then run a "timeout loop", lets say allowing the player 20 seconds to select a music track, if after 20 seconds, no track was chose (eg a boolean hadnt come true "tx_Playing", then the script would remove all the "Play Track" actions and reinstate the "Select Music" action


The play track actions would run a script, this script would define
tx_track and make tx_MusicOn = true




----------------------------------------------------------------------------------------------------
So basically, every player would start with an action in his menu
1) Select Music
Selecting this would then create a list of (addactions) music that could be chosen
If the player didnt select a choice of music within 20 seconds, the individual selections (action list) would revert back to Select music

If the player did select a choice within the time limit, then all the actions would be removed, the boolean tx_MusicOn would activate the trigger
the trigger would run the "Playmusic.sqs" jumping to the label which had the same number as the tx_track value


Hope that helps and gives you some iudea of the overall design you should be trying to create


NB>>>> You will have to publicvariable tx_Track so that all the other players clients have the same value for tx_track when they start the playmusic.sqs
It would also be a good idea to publicvariable  the tx_MusicOn at the same time, just to make sure all client triggers are activated

eg

{publicvariable _x} foreach ["tx_track",tx_MusicOn"]
« Last Edit: 29 Nov 2005, 23:53:46 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

renzo

  • Guest
Re:Radio/music script for all players
« Reply #2 on: 04 Dec 2005, 14:37:57 »
Thanks for the info.

However, I had hard time understanding the advice but then I bumbed into another problems with addaction/local/global execution and finally I got it.

So my script (m1.sqs for example) was:
Code: [Select]
0.5 fademusic 0.5
player removeaction m1
player removeaction m2
player removeaction m3
player removeaction m4
player removeaction m5
player removeaction m6
player removeaction m7
player removeaction m8
TitleText ["Airut - Orkideahauta","Plain"]
playmusic "FDFairut_orkideahauta"
m0 = player addaction ["radio","radio.sqs"]
exit
From where I removed titletext and playmusic commands replacing them with variables:
Code: [Select]
player removeaction m1
player removeaction m2
player removeaction m3
player removeaction m4
player removeaction m5
player removeaction m6
player removeaction m7
player removeaction m8
orkideahauta=true
publicvariable "orkideahauta"
m0 = player addaction ["radio","radio.sqs"]
~1
orkideahauta=false
exit
Go public! Obviously there has to be some wait time since triggers seem to lag. Then variable has to be set false to make it work repeatedly (trigger has already launched so we don't need it "true" anymore"). In editor I have triggers for each song (condition: orkideahauta for the one above).

So it wasn't so hard afterall when I get to know about addaction/publicvariable stuff.

Thanks for the help.