Author Topic: Starting and stopping an audio Loop for a vehicle  (Read 548 times)

Not sure if that title is the best but what ever.

Code: [Select]
package f18
{
function armor::onMount(%this,%obj,%col,%slot)
{
Parent::onMount(%this,%obj,%col,%slot);
if(%col.getDataBlock() == F18Vehicle.getId())
{
%Client = %Obj.Client;
%Client.Play2d(F18roosterpit);
%col.unmountimage(0);
%col.mountimage(F18EngineImage, 0);
}

}
function armor::onUnMount(%this, %obj, %slot, %col)
{
Parent::onUnMount(%this,%obj,%slot,%col);
if(%col.getDataBlock() == F18Vehicle.getId())
   {
%Client = %Obj.Client;
%Client.stopAudio(1);
}
}
function servercmdLight(%client)
{


%p = %client.player;
if(!isobject(%p.getobjectmount()))
return Parent::servercmdLight(%client);



if(%p.getobjectmount().getdatablock() == F18vehicle.getid())
{
if($Sim::Time<%client.delay)
{
return;
}
%obj = %p.getobjectmount();
%client=%client;

switch (%obj.f18gear)
{

case 1:
for(%i = 0; %i < 3; %i++)
{
%obj.schedule(1400,setWheelTire,%i, F18tire);
%obj.schedule(1400,setWheelspring,%i, F18spring);
}
%obj.playThread(0,"geardown");

%obj.f18gear = 2;
case 2:
for(%i = 0; %i < 3; %i++)
{
%obj.setWheelTire(%i, F18faketire);
%obj.setWheelSpring(%i, F18fakespring);
}
%obj.playThread(0,"gearup");

%obj.f18gear = 1;
default:
for(%i = 0; %i < 3; %i++)
{
%obj.setWheelTire(%i, F18faketire);
%obj.setWheelSpring(%i, F18fakespring);
}
%obj.playThread(0,"gearup");

%obj.f18gear = 1;
}
%client.delay=$Sim::Time+2000/1000;
}
else
Parent::servercmdLight(%client);


}
};
activatePackage(f18);

Ignore the rest (Unless it does pertain to what im asking) But focus on OnMount and OnUnMount. What i want to do is when a player enters this vehicle, a Looped sound is played to their client. I have the audio datablock set up to where it loops, there is no problem with the loop. But what im having issues with is the loop stopping when you exit the vehicle.

As of right now, when you exit the vehicle the loop plays endlessly. If you need any more information let me know, other then that thanks for the help.

If I remember you can't stop client audios, only play them because they don't have slots or a stopping function as far as I know, so you have to use the object (player/aiplayer/vehicle) for playing the audio.

%obj.playAudio(slot, sound); - I would choose 1 or 2

Code: [Select]
package f18
{
function armor::onMount(%this,%obj,%col,%slot)
{
Parent::onMount(%this,%obj,%col,%slot);
if(%col.getDataBlock() == F18Vehicle.getId())
{
%obj.playAudio(1, F18roosterpit);
%col.unmountimage(0);
%col.mountimage(F18EngineImage, 0);
}

}
function armor::onUnMount(%this,%obj,%slot,%col)
{
Parent::onUnMount(%this,%obj,%slot,%col);
if(%col.getDataBlock() == F18Vehicle.getId())
    {
%obj.stopAudio(1);
}
}

Its still not stopping Im also getting this error:
http://prntscr.com/biwvrj    <---- Error pic

you have the wrong order of arguments on armor::onUnMount
here is the proper order of arguments:
Armor::onUnMount(%this,%obj,%vehicle,%node)

to avoid issues like this in the future use echos to find the value of variables
in this case using echo on %col would have returned the seat the player was in and you would have realized that it was not the vehicle object

also ensure that you name your variable more reliable words like %veh or %vehicle instead of %col as it can mix you up easier when you aren't paying attention