mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
196 lines
4.8 KiB
Plaintext
196 lines
4.8 KiB
Plaintext
/**
|
|
|
|
*
|
|
* Title: trigger_breach_sound.script
|
|
* Description: creates a trigger volume that when breached will play a sound
|
|
|
|
*/
|
|
|
|
//------------------------------------------------
|
|
// Includes
|
|
//------------------------------------------------
|
|
|
|
include library.utils;
|
|
include library.space_utils;
|
|
//------------------------------------------------
|
|
// Constants
|
|
//------------------------------------------------
|
|
|
|
const string_id SID_TURN_ON = new string_id("spam", "turn_on_sound_object");
|
|
const string_id SID_TURN_OFF = new string_id("spam", "turn_off_sound_object");
|
|
|
|
const string OBJVAR_SOUND_FILE = "soundFile";
|
|
const string OBJVAR_IS_TURNED_ON = "itemIsOn";
|
|
|
|
//------------------------------------------------
|
|
// OnInitialize
|
|
//------------------------------------------------
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
if ( !utils.isInHouseCellSpace(self) )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if ( !hasTriggerVolume(self, "itemBreach") )
|
|
createTriggerVolume("itemBreach", 5.f, true);
|
|
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
// OnTriggerVolumeEntered
|
|
//------------------------------------------------
|
|
|
|
trigger OnTriggerVolumeEntered( string volumeName, obj_id whoTriggeredMe )
|
|
{
|
|
if ( !hasObjVar(self, OBJVAR_IS_TURNED_ON) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if ( getIntObjVar(self, OBJVAR_IS_TURNED_ON) == 0 )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if ( volumeName == "itemBreach" )
|
|
{
|
|
// Only players.
|
|
if ( !isPlayer(whoTriggeredMe) )
|
|
return SCRIPT_CONTINUE;
|
|
if ( !hasObjVar(self, OBJVAR_SOUND_FILE) )
|
|
return SCRIPT_CONTINUE;
|
|
string soundFile = getStringObjVar(self, OBJVAR_SOUND_FILE);
|
|
|
|
// Play the effect.
|
|
playMusic(whoTriggeredMe, soundFile);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
// OnTriggerVolumeExited
|
|
//------------------------------------------------
|
|
|
|
trigger OnTriggerVolumeExited( string volumeName, obj_id whoTriggeredMe )
|
|
{
|
|
if ( !hasObjVar(self, OBJVAR_IS_TURNED_ON) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if ( getIntObjVar(self, OBJVAR_IS_TURNED_ON) == 0 )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if ( volumeName == "itemBreach" )
|
|
{
|
|
// Only players.
|
|
if ( !isPlayer(whoTriggeredMe) )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
// Play the effect.
|
|
playMusic(whoTriggeredMe, "sound/music_silence.snd");
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
// OnObjectMenuRequest
|
|
//------------------------------------------------
|
|
|
|
trigger OnObjectMenuRequest( obj_id player, menu_info mi )
|
|
{
|
|
if (!utils.isInHouseCellSpace(self) && !space_utils.isNestedWithinPobShip(self))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
//if the object is off, or missing the objvar we change the menu option to 'On'
|
|
if ( !hasObjVar(self, OBJVAR_IS_TURNED_ON) || getIntObjVar(self, OBJVAR_IS_TURNED_ON) == 0 )
|
|
mi.addRootMenu(menu_info_types.SERVER_MENU1, SID_TURN_ON);
|
|
else
|
|
mi.addRootMenu(menu_info_types.SERVER_MENU1, SID_TURN_OFF);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
// OnObjectMenuSelect
|
|
//------------------------------------------------
|
|
|
|
trigger OnObjectMenuSelect( obj_id player, int item )
|
|
{
|
|
sendDirtyObjectMenuNotification(self);
|
|
|
|
if (!utils.isInHouseCellSpace(self) && !space_utils.isNestedWithinPobShip(self))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if ( item == menu_info_types.SERVER_MENU1 )
|
|
{
|
|
//if the object is off, or missing the objvar we turn the item 'On'
|
|
if(!hasObjVar(self, OBJVAR_IS_TURNED_ON) || getIntObjVar(self, OBJVAR_IS_TURNED_ON) == 0)
|
|
toggleSound(self, true);
|
|
else
|
|
toggleSound(self, false);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
//------------------------------------------------
|
|
|
|
trigger OnTransferred(obj_id sourceContainer, obj_id destContainer, obj_id transferer)
|
|
{
|
|
messageTo(self, "handleTriggerBreachMusicItemTransferred", null, 1, false);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleTriggerBreachMusicItemTransferred()
|
|
{
|
|
if ( !utils.isInHouseCellSpace(self) )
|
|
{
|
|
toggleSound(self, false);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//------------------------------------------------
|
|
// functions
|
|
//------------------------------------------------
|
|
|
|
//turns the item on and off
|
|
boolean toggleSound(obj_id item, boolean turnOn)
|
|
{
|
|
if ( turnOn )
|
|
{
|
|
//store the fact that it is on
|
|
setObjVar(item, OBJVAR_IS_TURNED_ON, true);
|
|
//create the trigger volume if it is missing
|
|
if(!hasTriggerVolume(item, "itemBreach"))
|
|
createTriggerVolume("itemBreach", 5.f, true);
|
|
}
|
|
else
|
|
{
|
|
//store the fact that it is on
|
|
setObjVar(item, OBJVAR_IS_TURNED_ON, false);
|
|
//destroy the trigger volume if it exists
|
|
if(hasTriggerVolume(item, "itemBreach"))
|
|
removeTriggerVolume("itemBreach");
|
|
}
|
|
|
|
obj_id[] players = getPlayerCreaturesInRange(getLocation(item), 25.0f);
|
|
for ( int i = 0; i < players.length; i++ )
|
|
{
|
|
obj_id temp = players[i];
|
|
if ( isIdValid(temp) )
|
|
{
|
|
playMusic(temp, "sound/music_silence.snd");
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|