I want to create a radio station mod. I have worked out some generic code as I just starting to learn and was wondering if someone could help me out?
so basically for the first part it would work in vehicles with the left and right arrow keys but would shut off upon exiting an resume upon entering and when the radio is playing all ambient and combat music while in the vehicle would be off. there would be a slider added into the audio settings to control how loud you want it to play aswell.
this is what I've got and i'm stuck...I can make the audio files and do the calls to those but my problem lies with tying it into the base game vehicles and fading the audio when you get out to the ambient or combat music whatever the situation you are in.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<!-- Adding custom sounds -->
<append xpath="/Sounds">
<SoundData name="vehicle_radio_station_rock">
<AudioSource>CustomRadio</AudioSource>
<Playlist>
<Clip>Sounds/CustomMusic/rock_song1.ogg</Clip>
<Interval>2</Interval>
<Clip>Sounds/CustomMusic/rock_dj_speech1.ogg</Clip>
<Interval>2</Interval>
<Clip>Sounds/CustomMusic/rock_song2.ogg</Clip>
</Playlist>
<Volume>1</Volume>
<Loop>true</Loop>
</SoundData>
<SoundData name="vehicle_radio_station_pop">
<AudioSource>CustomRadio</AudioSource>
<Playlist>
<Clip>Sounds/CustomMusic/pop_song1.ogg</Clip>
<Interval>2</Interval>
<Clip>Sounds/CustomMusic/pop_dj_speech1.ogg</Clip>
<Interval>2</Interval>
<Clip>Sounds/CustomMusic/pop_song2.ogg</Clip>
</Playlist>
<Volume>1</Volume>
<Loop>true</Loop>
</SoundData>
</append>
<!-- Modifying vehicle UI to add radio controls with image-based arrows and station name -->
<append xpath="/XUi/xui/Windows">
<window name="vehicle_radio_controls">
<rect pos="20,20" size="200,40" />
<image name="previous_station" source="UI/Images/arrow_left.png" onclick="previous_radio_station" />
<image name="current_station" source="UI/Images/station_rock.png" />
<image name="next_station" source="UI/Images/arrow_right.png" onclick="next_radio_station" />
</window>
</append>
<!-- Adding event to handle switching vehicle radio stations -->
<append xpath="/XUi/xui/Controllers">
<controller name="previous_radio_station">
<action type="PlaySound" sound="vehicle_radio_station_pop" />
<action type="SetImage" target="current_station" value="UI/Images/station_pop.png" />
</controller>
<controller name="next_radio_station">
<action type="PlaySound" sound="vehicle_radio_station_rock" />
<action type="SetImage" target="current_station" value="UI/Images/station_rock.png" />
</controller>
</append>
<!-- Adding hotkeys for station switching and turning off music (vehicle radios only) -->
<append xpath="/XUi/xui/Hotkeys">
<hotkey name="SwitchRadioStation" key="arrow_right" action="next_radio_station" />
<hotkey name="ToggleRadio" key="arrow_left" action="stop_vehicle_radio" />
</append>
<!-- Adding event to stop vehicle radio -->
<append xpath="/XUi/xui/Controllers">
<controller name="stop_vehicle_radio">
<action type="StopSound" sound="vehicle_radio_station_rock" />
<action type="StopSound" sound="vehicle_radio_station_pop" />
</controller>
</append>
<!-- Stopping ambient and combat music when radio is on -->
<append xpath="/XUi/xui/Controllers">
<controller name="radio_music_override">
<action type="StopSound" sound="ambient_music" />
<action type="StopSound" sound="combat_music" />
<action type="PlaySound" sound="vehicle_radio_station_rock" condition="radio_nearby_or_vehicle" />
<action type="PlaySound" sound="vehicle_radio_station_pop" condition="radio_nearby_or_vehicle" />
</controller>
<!-- Check for leaving the vehicle or physical radio, then resume ambient and combat music -->
<controller name="vehicle_left">
<action type="StopSound" sound="vehicle_radio_station_rock" />
<action type="StopSound" sound="vehicle_radio_station_pop" />
<action type="PlaySound" sound="ambient_music" />
<action type="PlaySound" sound="combat_music" />
</controller>
<!-- Fading radio volume as the player walks away from a physical radio -->
<controller name="fade_radio_volume">
<action type="AdjustVolume" sound="vehicle_radio_station_rock" value="1 - (distance_to_radio / max_distance)" />
<action type="AdjustVolume" sound="vehicle_radio_station_pop" value="1 - (distance_to_radio / max_distance)" />
</controller>
</append>
<!-- Adding custom volume slider to in-game audio settings menu -->
<append xpath="/XUi/xui/Windows[@name='audio_settings']">
<window name="radio_volume_settings">
<rect pos="50,200" size="300,50" />
<label text="Radio Volume" />
<slider name="radio_volume_slider" min="0" max="1" step="0.1" value="1" onchange="set_radio_volume" />
</window>
</append>
<!-- Adding event to adjust radio volume -->
<append xpath="/XUi/xui/Controllers">
<controller name="set_radio_volume">
<action type="SetVolume" source="vehicle_radio_station_rock" value="@radio_volume_slider" />
<action type="SetVolume" source="vehicle_radio_station_pop" value="@radio_volume_slider" />
</controller>
</append>
</config>