Jump to content
Sign in to follow this  

Help with evacuation loudspeaker script using TFAR

Recommended Posts

Hiya, I'm having some trouble with a script for a mission that is supposed to have a vehicle with something like a loudspeaker on it. The plan was to use TFAR for this for the cool effect of being able to actually speak through it and your voice then blaring from the car over radio and this making a bunch of civilians react in different ways. (I'm not having problems with the actual sounds and mod the problem is checking for certain conditions being met)

I've found the event that I need to call to check for whenever someone transmits over a radio and set it up so that it only activates using the right frequency. However I also want it to only work when you SPEAK through the radio. There's a boolean that you can check for to see if someone is speaking but obviously if I use this in the event code it is only called once when the button is pressed. So I'm having some problems with how to implement this.

Also excuse the shittily written and formatted code this has been cut and pasted through a few times so whenever I get something functional I'm gonna rewrite it a bit nicer. Here's what I got so far:

radioBroadcastScript.sqf (executed in init with the argument of "230" just for testing purposes)

//These first lines check for the arguments of the script. If none are added it will use the defaults.
//First argument is the braodcast frequency. Note this has to be between 30 and 512. DEFAULT is 79.3
if (isNil {_this select 0}) then 
	_this set [0, "79.3"];

//Set the frequency at which the broadcast is detected on.
broadcastFrequency = (_this select 0) ;

//For each player in a group run the code below

	//Register event to unit. This event is from TFAR and is for when someone presses or releases the radio transmit button.
	["BroadcastingThroughSpeaker", "OnTangent", {
	//The event information. Unit object, radio object, radio type, whether it's an additional channel, whether it's a release or press.
        params ["_player", "_radio", "_radioType", "_additional", "_buttonDown"];
		//Checks whether the button is pressed
		if (_buttonDown) then {
			//Assigns the currently used radio frequency by the unit to a variable
			_currentFrequency = _player call TFAR_fnc_currentSWFrequency;
			//Checks whether the frequency used matches the broadcast frequency
			if (_currentFrequency isEqualTo broadcastFrequency) then {
				systemChat format ["%1 is transmitting on frequency %2", name playerObject, _currentFrequency];

    }, player] call TFAR_fnc_addEventHandler;

} forEach units group player;

And the check for whether someone is speaking is this little line here

if (_player call TFAR_fnc_isSpeaking) then

I've been kinda trying out a few different options but nothing really works. Also something worth noting is that this should ideally work in multiplayer. Any help would be greatly appreciated! 😄

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