Author Topic: Vehicle sound stuff. (Detecting if player is driver when getting in/out)  (Read 2021 times)

So I've been trying to manipulate my old vehicle sound mod so it only activated when the driver entered the vehicle, and stopped when the driver got out.
Here's what I'm using. No errors, it just does nothing.

Code: [Select]
package RodeoMountSound
{
function Armor::onMount(%this,%obj,%col,%slot,%player)
{
if(%col.dataBlock !$= "RodeoVehicle")
{
parent::onMount(%this,%obj,%col,%slot);
%obj.canDismount = true;
}
if(%col.dataBlock $= "RodeoVehicle")
{
parent::onMount(%this,%obj,%col,%slot);

serverplay3d("RodeoMount" @ getRandom(1, 3), %obj.getHackPosition());


%vehicle = %player.getMountObject();
if(%vehicle.getMountedObject(0) == %player)
{
   if(%vehicle.started=false)
   {
  schedule(1000,0,"RodeoSpeedCheck",%this,%obj);
   serverplay3d("RodeoStart",%vehicle.getPosition());
   %vehicle.started=true;
}
 
}
}

}

function Armor::onUnMount(%this,%obj,%player)
{
parent::onunMount(%this,%obj);

%vehicle = %player.getMountObject();
if(%vehicle.getMountedObject(0) == %player)
{
serverplay3d("RodeoStop",%obj.getHackPosition());
cancel(%this,RodeoSpeedCheck);
%vehicle.started=false;
}
}
};


PROBLEMS:
- Doesn't play when entering the vehicle. It has a problem with getting the object.
- Keeps starting the vehicle's sounds up even when just sitting there; so essentially it's calling the onMount function when you're sitting there in the car.
- Plays in all seats.
- Canceling doesn't work.
« Last Edit: October 11, 2014, 01:53:07 PM by Arekan »

Instead of doing the vehicle ::onMount have you instead tried using armor::onMount so you can have something like
Code: [Select]
package HydricMountSound
{
function armor::onMount(%this,%obj,%col,%slot)
{
if(%col.dataBlock !$= "HydricVehicle")
{
parent::onMount(%this,%obj,%col,%slot);
%obj.canDismount = true;
}
if(%col.dataBlock $= "HydricVehicle")
{
parent::onMount(%this,%obj,%col,%slot);

serverplay3d("HydricMount" @ getRandom(1, 3), %obj.getHackPosition());
}
}
};

activatePackage(HydricMountSound);
Filipe1020's Hyrdic

That works, however, there's a few problems. Updating OP.

- Plays sounds on the player. Needs to be on the vehicle.
serverplay3d("RodeoStart",%vehicle.getPosition()); maybe?

- Keeps starting the vehicle's sounds up even when just sitting there; so essentially it's calling the onMount function when you're sitting there in the car.
Add a custom variable to the vehicle that sets to true upon mounting, then false upon unmounting, and add in an if statement so it'll play once, be set to true, then stop.

serverplay3d("RodeoStart",%vehicle.getPosition()); maybe?
I mean, the actual vehicle sounds. It uses the same code as the Hydric, where you probably got your copypaste from (unless u typed it u GENIUS), so I think it has something to do with scheduling it via armor::onMount.

Add a custom variable to the vehicle that sets to true upon mounting, then false upon unmounting, and add in an if statement so it'll play once, be set to true, then stop.

m stoopid
How do?

It uses the same code as the Hydric, where you probably got your copypaste from
Filipe1020's Hyrdic

Are you actually naming the AudioProfile for the sound RodeoMount1 RodeoMount2 RodeoMount3 etc?

m stoopid
How do?

Something along the lines of:
Code: [Select]
if(%vehicle.getMountedObject(0) == %player)
{
    if(%vehicle.started=false)
    {
        schedule(1000,0,"RodeoSpeedCheck",%this,%obj);
        serverplay3d("RodeoStart",%vehicle.getPosition());
        %vehicle.started=true;
    }
}
And then one on the unmount to set it back to false.

A couple of errors i noticed:
Code: [Select]
function Armor::unUnMount(%this,%obj,%player)

unUnMount, should be onUnMount (assuming that is actually a function)


Code: [Select]
%vehicle = %player.getMountObject();

Im pretty sure at this point (definitely after the parent, maybe before even) the player doesn't have a mount object, so this would return 0 every time. You need to get the vehicle another way, it might be in %player or %obj, you should echo their class names to see what they are (then rename the variables if they're wrong).


Oh, and youre not sending %player to the parent, that could break a lot of other add-ons.

A couple of errors i noticed:
unUnMount, should be onUnMount (assuming that is actually a function)
thanks, fixed

I think it should be fine. I don't mind if it plays on the player as long as it stops when the player gets out of the vehicle. Updated OP with new code.

Oh and I found the problem as to why the sounds looped. I accidentally grouped them with the vehicle sounds.

Code: [Select]
datablock AudioProfile(RodeoIdle)
{
   filename    = "./Sound/RodeoIdle.wav";
   description = AudioclosestLooping3d;
   preload = true;
};

datablock AudioProfile(RodeoStart : RodeoIdle) { filename = "./Sound/RodeoStart.wav"; };
datablock AudioProfile(RodeoStop : RodeoIdle) { filename = "./Sound/RodeoStop.wav"; };

Meaning, they're looping. Fixed aswell.
« Last Edit: October 11, 2014, 01:49:35 PM by Arekan »

K I forgeted something up, backtracking a bit. This is my code right now.
Code: [Select]
[size=8pt]package RodeoMountSound
{
function Armor::onMount(%this,%obj,%col,%slot,%player)
{
if(%col.dataBlock !$= "RodeoVehicle")
{
%vehicle = %player.getMountObject();
parent::onMount(%this,%obj,%col,%slot,%player);
%obj.canDismount = true;
}
if(%col.dataBlock $= "RodeoVehicle")
{
%vehicle = %player.getMountObject();
parent::onMount(%this,%obj,%col,%slot,%player);

serverplay3d("RodeoMount" @ getRandom(1, 3), %obj.getHackPosition());

if(isObject(%vehicle.getMountNodeObject(0).client))
{
activatePackage("RodeoEngineSound");
%driver = %vehicle.getMountNodeObject(0);

  schedule(1000,0,"RodeoSpeedCheck",%this,%obj);
  serverplay3d("RodeoStart",%obj.getHackPosition());
}
}

}

function Armor::onUnMount(%this,%obj,%player)
{
%vehicle = %player.getMountObject();
parent::onunMount(%this,%obj,%player);

if(isObject(%vehicle.getMountNodeObject(0).client))
{
deactivatePackage("RodeoEngineSound");
%driver = %vehicle.getMountNodeObject(0);

serverplay3d("RodeoStop",%obj.getHackPosition());
cancel(%player,RodeoSpeedCheck);
}
}
};
[/size]

It doesn't work anymore D:
Yeah I'm not doing this right, I'm not good at this stuff.

your onMount parameters are wrong
check Thorfin's for correct parameter list.

Anyway here's my code to make all vehicles play engine sounds
Code: [Select]
function WheeledVehicle::engineSoundCheck(%this)
{
for(%i=0;%i<%this.getMountedObjectCount();%i++)
{
if(%this.getMountedObjectNode(%i) == 0)
%this.playAudio(0,engineIdleSound);
}
}

package vehicleEngine
{
function armor::onMount(%this,%obj,%mount,%slot)
{
parent::onMount(%this,%obj,%mount,%slot);
if(%mount.getClassname() $= "WheeledVehicle" && !(%mount.getDatablock().shapeFile $= "Add-Ons/Item_Skis/deathVehicle.dts"))
{
if(%slot == 0)
{
%mount.playAudio(0,engineStartSound);
%mount.schedule(4000,engineSoundCheck);
}
}
}
function WheeledVehicleData::onDriverLeave(%this,%obj,%driver)
{
parent::onDriverLeave(%this,%obj,%driver);
%obj.playAudio(0,engineStopSound);
}

};
activatePackage(vehicleEngine);
I used the vehicle's onDriverLeave function to find when the driver left the vehicle instead of armor::onUnmount
You can also make the vehicle play the sound with .playAudio instead of where the vehicle WAS when the sound was played.

K. It works. Just incase someone out there wants to know, this is what I use.

Code: [Select]
package RodeoEngineStuffs
{
function armor::onMount(%this,%obj,%mount,%slot)
{
parent::onMount(%this,%obj,%mount,%slot);
if(%mount.getClassname() $= "WheeledVehicle" && !(%mount.getDatablock().shapeFile $= "Add-Ons/Item_Skis/deathVehicle.dts"))
{
if(%slot == 0)
{
%mount.playAudio(0,RodeoStart);
$RodeoSpeedCheckSchedule = schedule(1000,0,"RodeoSpeedCheck",%this,%obj);
serverplay3d("RodeoMount" @ getRandom(1, 3), %obj.getHackPosition());
}
}
}
function WheeledVehicleData::onDriverLeave(%this,%obj,%driver)
{
parent::onDriverLeave(%this,%obj,%driver);
}
function armor::onunMount(%this,%obj)
{
parent::onunMount(%this,%obj);

%vehicle = %obj; //i dont even know why i do this
%vehicle.StopAudio(0);
Cancel($RodeoSpeedCheckSchedule);
%vehicle.playAudio(0,RodeoStop);
}
};
activatePackage(RodeoEngineStuffs);

Then the Hydric's code for vehicle sounds.
« Last Edit: October 12, 2014, 12:10:46 AM by Arekan »