Define Properties() -- Private Properties active = 0 sound_handle = 0 -- Script Parameteres sound_id = 0 ExposeProperty('sound_id', 'Sound id?') PersistProperty('sound_id') sound_url = "" ExposeProperty('sound_url', 'Sound URL (overrides id)?') PersistProperty('sound_url') volume = 100 ExposeProperty('volume', 'Volume (0-255)?') SetPropRange('volume', 0, 255) PersistProperty('volume') looping = 1 ExposeProperty('looping', 'Repeat Play', 'checkbox') SetPropRange('looping', 0, 1) PersistProperty('looping') sound_range = 5 ExposeProperty('sound_range', 'Range of sound in tiles?') PersistProperty('sound_range') sound_place = 1 ExposeProperty('sound_place', 'Play sound to place', 'checkbox') PersistProperty('sound_place') script_description = 'Play Sound' script_long_description = 'Allows this object to play a sound when used' script_icon = '12071:438' end Trigger use(user_object) -- /use objectId Debug("in use for %s from %s", self.name, user_object.name) toggle_sounds(self,user_object) -- Block other use events from triggering. return 1 end Trigger destroyed() stop_playing(self) end function stop_playing(self) Debug("self.sound_handle = %s",self.sound_handle or 0) if self.sound_handle ~= 0 and self.sound_handle ~= nil then StopSoundPlace(self.sound_handle) self.sound_handle = 0 end end function toggle_sound(self,user_object) Debug ("Toggling sound.") if self.active == 0 then self.active = 1 SendTo (self, 'play_sound', 0) else self.active = 0 stop_playing(self) end end Trigger play_sound() --if self.sound_handle > 0 then -- return --end Debug ("place = %d", self.sound_place) if self.active == 1 then if self.sound_place == 1 then -- Play to place if self.sound_url == "" then self.sound_handle = PlaySoundPlace(self.sound_id, self.volume, self.looping) else self.sound_handle = PlaySoundRefPlace(self.sound_url, self.volume, self.looping) end else -- Play to range Debug ("Attempting to play to range.") if sound_url == "" then self.sound_handle = PlaySoundRadius(self, self.sound_range, self.sound_id, self.volume, self.looping) else self.sound_handle = PlaySoundRefRadius(self, self.sound_range, self.sound_url, self.volume, self.looping) end end end end --[[ -- List of available sound commands PlaySoundPlace soundId, volume, loop PlaySoundRefPlace url, volume, loop PlaySoundRadius target object, radius, soundId, volume, loop PlaySoundRefRadius target object, radius, url, volume, loop PlaySoundTo target object, soundId, volume, loop PlaySoundRefTo target object, url, volume, loop --]]