Jump to content
Sign in to follow this  
zooloo75

vehicle player say3d "sound" not global?

Recommended Posts

case 79: 

{
	if((patrolcar) && (vehicle player != player)) then {(vehicle player) say3d "stepoutofthevehicle"}; 
};

Ok, this code works great for me; the vehicle emits the sound effect, but there's one issue. In multiplayer, only the player who presses the key to play the sound can hear it - no one else can hear it. It's as if the sound is only played locally.

How would I make this code work globally? I can't do setvehicleinit because it will make everyone play this sound, which is not what I want.

Share this post


Link to post
Share on other sites
There's a little bit of info in this thread that may help, I noticed it the other day. post 3

http://forums.bistudio.com/showthread.php?136377-Play-Sound

So instead of

case 79: 

{
	if((patrolcar) && (vehicle player != player)) then {(vehicle player) say3d "stepoutofthevehicle"}; 
};

It would be

case 79:
{
[nil,nil,rEXECVM,"sound1.sqf",[player,allunits]] call RE;
}

and sound1.sqf would be

if((patrolcar) && (vehicle player != player)) then {(vehicle player) say3d "stepoutofthevehicle"}; 

?

Share this post


Link to post
Share on other sites

That's about how I read it but I haven't done any MP work. I've added sound to a couple of things so would like to know the result myself.

I'm not sure about allunits in the rEXECVM line, you may get away with changing it to [vehicle player,player] it may works as you only need real players to hear anything.

Share this post


Link to post
Share on other sites

For people that like to roll their own... here's a way using PVEH's and a purpose built function.

You don't have to stop with say3D. Playsound... text messages.... pass parameters and script names and have scripts execute. Just create your own function for whatever you need.

Create a function in your mission folder or wherever called "fn_netSay3D.sqf";

fn_netSay3D.sqf:-

private ["_obj","_snd"];

_obj = _this select 0;	//object
_snd = _this select 1;	//sound

// broadcast PV
PVEH_netSay3D = [_obj,_snd];
publicVariable "PVEH_netSay3D";

// run on current machine also if not dedi server
if (not isDedicated) then {_obj say3D _snd};

true

Add this to the init.sqf...must run on all machines.

fn_netSay3D = compile preprocessFileLineNumbers "fn_netSay3D.sqf";

if (isNil "PVEH_netSay3D") then {
PVEH_NetSay3D = [objNull,0];
};

"PVEH_netSay3D" addPublicVariableEventHandler {
     private["_array"];
     _array = _this select 1;
    (_array select 0) say3D (_array select 1);
};

To call the function:-

//killer will say "goodbye" on all machines except dedi
nul = [_killer,"goodbye"] call fn_netSay3D;

Edited by twirly

Share this post


Link to post
Share on other sites

As i understand this you just want the vehicle to play the sound to all clients correct?

I had a similar issue with a radio object at base not playing to all clients, this was fixed by using the rSay function from the MP Framework.

Try using the following:

[nil, vehiclename, rSAY, soundname] call RE;

Share this post


Link to post
Share on other sites

just an update - using all three methods do work.

Twirlys way is less expensive i think on the olde cpu, rather than the Call RE methods, and it can be modded to play any sound using the same PEH.

If you use the say3d - make sure you place the name of the object to play, and the name of anything that will hear it.

Although you dont actually need the object that will hear the noise - as in the sound playing script you dont use anything other that the object playing the noise. - so really it doesnt matter what you use (Last part untested)

hope this helps

Share this post


Link to post
Share on other sites

@Twirly - I never knew how those worked until you posted that nice bunch of info! I do know some Actionscripting, and I'm trying to adapt to ArmA's language because I love this game and would like to expand upon it with my own missions. I know in AS you can write functions which can handle things automatically (depending on how you wrote it). I never thought about/ knew about creating my own functions for ArmA. You just opened up a new door to ArmA scripting to me. Thank you!

As your script hasn't been tested by me, I will try Shadow.D ^BOB's method first as it seems to be simple; but I will also test yours out for some other things. Thank you all for your help :)

I will get back to y'all later once I test these out.

---------- Post added at 11:45 PM ---------- Previous post was at 11:17 PM ----------

As i understand this you just want the vehicle to play the sound to all clients correct?

I had a similar issue with a radio object at base not playing to all clients, this was fixed by using the rSay function from the MP Framework.

Try using the following:

[nil, vehiclename, rSAY, soundname] call RE;

if((patrolcar) && (vehicle player != player)) then {[nil, (vehicle player), rSAY, "stepoutofthevehicle"] call RE;};

I used this code, and it didn't work. I pasted it into squint and there were no errors. No sound was emited.

Share this post


Link to post
Share on other sites

When you say doesn't work, is that SP or MP or both?

How are you using the code, if you start in the vehicle it should be fine but if your getting in later you will need to run it continuously or use a getin eventhandler or addaction, even a radio trigger.

I have all three working in SP, one thing you should know is that sound is very quiet when in a vehicle also if you edit your description file you will need to load the mission as restarting it won't see the modified decription file.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I am using multiplayer. You press a key on the numpad and it executes the code. It first checks if the patrolcar is true, and if the player is in a vehicle. If those are true, then it will run the code.

The player doesn't start in a vehicle though.

case 79:
{
if((patrolcar) && (vehicle player != player)) then {[nil, (vehicle player), rSAY, "stepoutofthevehicle"] call RE;};
};

Basically what I want is when the player is a patrol officer, and is in a vehicle, they will be able to press a key and emit a sound from their vehicle that all players will be able to hear.

---------- Post added at 12:42 AM ---------- Previous post was at 12:18 AM ----------

For people that like to roll their own... here's a way using PVEH's and a purpose built function.

You don't have to stop with say3D. Playsound... text messages.... pass parameters and script names and have scripts execute. Just create your own function for whatever you need.

Create a function in your mission folder or wherever called "fn_netSay3D.sqf";

fn_netSay3D.sqf:-

private ["_obj","_snd"];

_obj = _this select 0;	//object
_snd = _this select 1;	//sound

// broadcast PV
PVEH_netSay3D = [_obj,_snd];
publicVariable "PVEH_netSay3D";

// run on current machine also if not dedi server
if (not isDedicated) then {_obj say3D _snd};

true

Add this to the init.sqf...must run on all machines.

fn_netSay3D = compile preprocessFileLineNumbers "fn_netSay3D.sqf";

if (isNil "PVEH_netSay3D") then {
PVEH_NetSay3D = [objNull,0];
};

"PVEH_netSay3D" addPublicVariableEventHandler {
     private["_array"];
     _array = _this select 1;
    (_array select 0) say3D (_array select 1);
};

To call the function:-

//killer will say "goodbye" on all machines except dedi
nul = [_killer,"goodbye"] call fn_netSay3D;

Ok, I tested your method for my mission, it works great! I just have to see if others can hear it now! - will get back to you!

Edit - WOW, this is epic. It works perfectly in MP!

Edited by zooloo75

Share this post


Link to post
Share on other sites

I think it will work well for you mate.

As far as creating your own functions... once you've created them you have them to use whenever. You also have something that you built so you know how it works... there's a special kind of pleasure in that!

Also... as Mikie Boy said above... the added benefit is a lot less overhead than using the built in stuff.

Share this post


Link to post
Share on other sites

Twirly, I am trying to use your method to make "setobjecttexture" global.

It's not working :\

It will set my vehicle to a custom texture, but no one can see it.

fn_netSetObjectTexture.sqf

private ["_obj", "_texture"];

_obj = _this select 0;    //object
_texture = _this select 1; //texture


// broadcast PV
PVEH_netSetObjectTexture = [_obj,_texture];
publicVariable "PVEH_netSetObjectTexture";

// run on current machine also if not dedi server
if (not isDedicated) then {_obj setObjectTexture [0, (_texture)]};

true  

checkcar.sqf

while {true} do
{

if( ((vehicle player) distance paynspray < 10) && (typeof (vehicle player) == "VWGolf")) then 
{
execvm "carpaint.sqf";
};

sleep 5;
};

carpaint

nul = [(vehicle player), "golfblue.paa"] call fn_netSetObjectTexture;
hint "Vehicle Sprayed!";

piece of the init

fn_netSay3D = compile preprocessFileLineNumbers "fn_netSay3D.sqf";

if (isNil "PVEH_netSay3D") then {
   PVEH_NetSay3D = [objNull,0];
};

"PVEH_netSay3D" addPublicVariableEventHandler {
     private["_array"];
     _array = _this select 1;
    (_array select 0) say3D (_array select 1);
};  

//setobjecttexture

fn_netSetObjectTexture = compile preprocessFileLineNumbers "fn_netSetObjectTexture.sqf";

if (isNil "PVEH_netSetObjectTexture") then {
   PVEH_NetSetObjectTexture = [objNull,0];
};

"PVEH_netSetObjectTexture" addPublicVariableEventHandler {
     private["_array1"];
     _array1 = _this select 1;
    (_array1 select 0) setObjectTexture [0, (_array1 select 1)];
};  

Edited by zooloo75

Share this post


Link to post
Share on other sites

Hi mate... I'm not sure why it's not working. It looks like it should. I don't really have a way if testing this easily as I don't have textures... and in my searching I couldn't find anything to test with.

I did do a COOP test with a flagpole using setFlagTexture and it worked fine.

A big problem is that functions don't return error messages.... they just die with no reason given.

This has nothing to do with your problem...but you don't need to call your array _array1. Since the variable is declared as private to the routine no other routine can see it. You can simply use _array again.

I saw your PM.... but thought I'd better answer here.

EDIT: **Bright idea!!!** Instead of using (vehicle player) try this because I've had trouble recently with some commands using player as an object...

_veh = vehicle player;
nul = [_veh , "golfblue.paa"] call fn_netSetObjectTexture;

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×