Jump to content
Sign in to follow this  
JohnKalo

Scripts Can Only Be Called Once?

Recommended Posts

My problem started when I decided to place a working police siren in one of my missions

Scripting aint really my thing but I try :D

 

So, after failing some attempts I decided to put the following into practice:

 

1.]In description:

class cfgMusic
{
    tracks[]={song1, song2};
    
    class track1
    {
        name="song1";
        sound[] = {\music\song1.ogg, db+10, 1.0};
    };
class track2
    {
        name="song2";
        sound[] = {\music\song2.ogg, db+10, 1.0};
    };
     
     };

Where song1 is the police siren audio and song2 is an empty audio file

 

2.]I created folder music and I inserted the appropriate mono track ogg files

 

3.]I created 2 units called siren0 and siren1 and I equipped them with many first aid packs

 

4.] Init of Offroad Police Car:

this animate ["HidePolice", 0]; this animate ["BeaconsStart", 1]; this addAction ["Siren On","sirenon.sqf",

[1],0,false,true,""," driver  _target == _this"]; this addAction ["Siren off","sirenoff.sqf",[1],0,false,true,""," driver  

_target == _this"];

5.]Sirenon.sqf:

siren0 setDamage 0.5;

6.]Sirenoff.sqf

siren1 setDamage 0.5;

7.] I placed a trigger with the condition:

(damage siren0)>0.4

On activation I activated "repeatable" and I placed an effect that plays song0, the siren audio

 

8.] I place a trigger with the condition:

(damage siren1)>0.4

On activation I activated "repeatable" and I placed an effect that plays song1, the empty audio file

 

9.]The idea was that the script called from the "siren on" action would damage a unit and that damage would cause the siren to play. While the unit healed himself the "siren off" action would damage another unit and that damage would cause an empty sound file to play so as for the siren sound to stop

 

I played my mission and everything worked fine. I opened the siren and I managed to turn it off! After a while I tried to open the siren again. But the siren would just not open?!?!?

 

I have put this procedure into practice for 3 different vehicles but I cannot make it work.. The siren on and off only works once. So, in short ........... Heeeeeeeeeeeelp

Share this post


Link to post
Share on other sites

Scripts can be called as many times as youd lke.

Quick question, why not use playSound3D and attach it to the car? The current set up seems like an odd workaround.

Maybe try something like this (pseudo code):

Init

Addaction ["toggle siren", togglesiren.sqf, this]

This setVariable["siren", false]; // boolean to tell if on or off

togglesiren.sqf:

car = _this select 0;

If (car getVariable "siren") then {

// turn off sound

car set variable sound false

} else {

PlaySound3D myaudio, car;

Car set variable sound true;

};

Sorry, doing this on my phone so I got lazy towards the end with syntax

Share this post


Link to post
Share on other sites

Many thanks for the immediate reply!

^^ I could not use playSound3D because I could not understand how to show the game what audio to use. I want the audio to be into the .pbo file. When I play songs or any kind of audio I use the text I have included in the description file. I will try your suggestion and see if I can make it work

Share this post


Link to post
Share on other sites

Could not make your script work. Apart from ; missing errors for the addaction sector, I changed that with the one I used, there were more errors being reported.

So I should use Jacmac's text in the description file as I have understood. Lets see

 

EDIT: Nope, that will be needed in an sqf file. Oh, man. I am kinda dizzy

EDIT: Missing variable something error. You know maybe I should be doing some things when I am not since my scripting are way low. Ehm, can somebody give me the exact commands I need to use please

Share this post


Link to post
Share on other sites

Why are you against using an sqf file? Also what I gave you was pseudo code. It was more of an idea for implementation rather than the exact implementation itself. I can write the exact code if you're unfamiliar

Share this post


Link to post
Share on other sites

Not so much against as incapable in using them. I only use them for simple addaction cases. Pseudo code? I do not even know what that is. If you would I would greatly appreciate it

 

EDIT: Googled and found out what pseudo code is :whistle:

And if anyone could tell me what went wrong with my noobish approach pls

Share this post


Link to post
Share on other sites

Updated per grumpy's comment below:

 

Give this a try: 
 
init:

this addAction ["Toggle siren","togglesiren.sqf",[this],0,false,true,""," driver _target == _this"];
this setVariable["siren", false];

 
togglesiren.sqf:
 

_car = _this select 0;  //this will get the car object passed from addAction
 
//Thanks to KK:
ROOT = call {
    private "_arr";
    _arr = toArray __FILE__;
    _arr resize (count _arr - 15); //subtract length of "togglesiren.sqf" (15 characters) to get directory
    toString _arr
};
 
 
 
if(_car getVariable "siren") then { 
//siren is on, turn it off
say3D [ROOT + "music\song2.ogg", _car];
_car setVariable["siren", false];
} else { 
//siren is off, turn it on
say3D [ROOT + "music\song1.ogg", _car];
_car setVariable["siren", true];
};

Share this post


Link to post
Share on other sites

Ehm, nope. It does not work. It says:

say3D [ROOT + "music\song2.ogg", _car]; _car s...' missing ;

 

I tried placing a ; at

say3D [ROOT + "music\song2.ogg", _car];
_car setVariable["siren", false];
}!;!

 

but that did not work either

Share this post


Link to post
Share on other sites

Ok now it does not report any errors. The toggle siren action exists as intended but when I click on it it says "song1.ogg not found" ?!?!?

How can this be possible?

The audio file is there. I placed a trigger in the mission that played the audio file in a BLUEFOR present condition but the togglesiren.sqf script cannot find it..

I am perplexed

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×