Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
OB1

addaction & sound public variable

Recommended Posts

would appreciate some help with my following predicament...

aim = a vehicle to have an action menu to be able to turn on a siren then turn it off again..

the script works perfectly but only in single player. In multilayer each client has their own menu and the siren only plays client side.. my scripting skills are rudimentary at best so after long hours bleeding my eyes out im hoping someone can help me here.. this is the script

sirenon.sqf

_car = _this select 0;

_car removeaction SirenON;
SirenOFF = _car addaction ["SirenOFF", "common\sirenOff.sqf"];
DCV_siren = true;
While {DCV_siren} do
{
0 fadesound 1; _car say "CopSiren";
sleep 1.35;
};

sirenoff.sqf

_car = _this select 0;

_car removeaction SirenOFF;

DCV_siren = false;
0 fadesound 1; _car say "EndFade";

SirenON = _car addaction ["SirenON", "common\sirenOn.sqf"];

any ideas ?

Share this post


Link to post
Share on other sites

One way of doing it, but look alittle into MP framework as im not totally sure on how to use that correctly.

place in init.sqf:

DCV_siren = false;

save this as script and run this on the car, or change it to work in init. line of the car (change _this to this):

_actOn = _this addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"];
_actOf = _this addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];

the actions will both be on the car at the same time but will only be visible for the driver, and oon will only be visible when its off and vice versa.

now here is the changed siren.sqf wich is used for both on and off, remember to place function module on map:

_car = _this select 0;
if (DCV_siren) then {
DCV_siren = false;
publicVariable "DCV_siren";
0 fadesound 1;
[b]_sound = [_car,nil,rSAY,"EndFade"] call RE;[/b]
_car say "EndFade";
} else {
DCV_siren = true;
publicVariable "DCV_siren";
While {DCV_siren} do {
	0 fadesound 1;
	[b]_sound = [_car,nil,rSAY,"CopSiren"] call RE;[/b]
	_car say "CopSiren";
	sleep 1.35;
};
};

You see the higlighted MPFramework playing sound on all clients.

http://community.bistudio.com/wiki/Multiplayer_framework

i am not totally up to speed on the multi player framework, here is link to it, and someone might come help here correct it if its wrong.

Share this post


Link to post
Share on other sites

Demonized thanks for you support,

with your

_actOn = _this addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"];
_actOf = _this addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];

I cannot seem to get it working in any situation either via veh init or sqf

am I doing somthing wrong ?

Share this post


Link to post
Share on other sites

Attach a trigger to the car that plays the siren sound while a publicVariable is true. Have the addactions change and publicize that variable.

Actually, you'd need to delete and recreate the triggers to stop the sounds so that might not be the best. Sounds in MP are stupid, don't use them. :)

Edited by kylania

Share this post


Link to post
Share on other sites

For doing this globally, I'd also reccomend some of the CBA functions like GlobalExecute and GlobalSay3D.

Share this post


Link to post
Share on other sites

I cannot seem to get it working in any situation either via veh init or sqf

am I doing somthing wrong ?

to use in init line, remove underscore in first _this, you probably did it in the last one also wich should be left as is in any case:

_actOn = [b]this [/b]addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"];
_actOf = [b]this [/b]addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];

to run from a script: dont change anything, use previous post code, but execute script with this in initline of vehicle:

_null = this execVM "nameOfScript.sqf";

remember to place the variable as mentioned in init.sqf, its in my previous post.

i did first test on triggers as kylania said, but then it would be a mess with several vehicles and or respawns, reason why triggers is good, is because they are "local", not meaning to confuse you but every trigger is local, but copied to all clients.

so the trigger would play the sound on each client when the publicVariable was detected.

Share this post


Link to post
Share on other sites
to use in init line, remove underscore in first _this, you probably did it in the last one also wich should be left as is in any case:

_actOn = [b]this [/b]addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"];
_actOf = [b]this [/b]addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];

to run from a script: dont change anything, use previous post code, but execute script with this in initline of vehicle:

_null = this execVM "nameOfScript.sqf";

remember to place the variable as mentioned in init.sqf, its in my previous post.

i did first test on triggers as kylania said, but then it would be a mess with several vehicles and or respawns, reason why triggers is good, is because they are "local", not meaning to confuse you but every trigger is local, but copied to all clients.

so the trigger would play the sound on each client when the publicVariable was detected.

lol yes that was exactly what I did wrong and now it works perfectly..

However I have another associated problem.

Because the vehicle that this script is being applied to is to be spawned I can't seem to initiate the action or script.

this is only a section of the script for example:

setVehicleInit ""_actOn = this addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"]; _actOf = this addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];""

;processInitCommands;};

and with that it completely poops itself and crashes to desktop. It also does to same thing when I do this:

setVehicleInit "_null = this execVM "nameOfScript.sqf";";

processInitCommands;

I'm most likely going about it totally wrong, what you think ?

Share this post


Link to post
Share on other sites

when working with strings: (string is a text inside qoutes)

you cannot have a quote inside a string, you can however use double qoutes or ' instead:

example correct usage of string inside string:

_vehicle setVehicleInit "_null = this execVM ""nameOfScript.sqf"";";
processInitCommands;

// OR this way:

_vehicle setVehicleInit "_null = this execVM 'nameOfScript.sqf';";
processInitCommands;

btw, you didnt have a vehicle to setVehicleInit on in your post, i asume it was just in the post and not in the script?

http://community.bistudio.com/wiki/setVehicleInit

Share this post


Link to post
Share on other sites

Ok thanks, getting closer. I have got the vehicle to call the script and that works fine..

the action script works perfect by its self in the actual vehicle init line and the siren works..

I just cant get the vehicleinit to process once the vehicle has called the script..

Im sure its got to be something like this...

_car = _this select 0;
_vehicle setVehicleInit "_actOn = _this addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"];
_actOf = _this addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];";
processInitCommands;

but that just doesn't work for me..

Share this post


Link to post
Share on other sites

you use _car and assign the init to _vehicle:

it should be:

_car setVehicleInit.........................................

Share this post


Link to post
Share on other sites
you use _car and assign the init to _vehicle:

it should be:

_car setVehicleInit.........................................

ah yes sorry, fixed but still no joy.. this is exactly what I have got setup for testing;

Vehicle init

_null = this execVM "sireninit.sqf";

sireninit.sqf

_car = _this select 0;
_car setVehicleInit "_actOn = _this addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"]; _actOf = _this addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];";
processInitCommands;

and tried this

_car = _this select 0;
_car setVehicleInit "_actOn = this addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"]; _actOf = this addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];";
processInitCommands;

Share this post


Link to post
Share on other sites

this is the correct way:

[b]_car = _this;[/b]
_car setVehicleInit "_actOn = this addAction ["SirenON", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND !DCV_siren"]; _actOf = this addAction ["SirenOFF", "common\siren.sqf", [], 0, false, true, "", "driver _target == _this AND DCV_siren"];";
processInitCommands;

edit: brief explanation of _this used in scripts:

_null = [1,2,3,4,5] execVM "anyscriptname.sqf";

in anyscriptname.sqf, _this refers to [1,2,3,4,5]

_this select 1 will refer to the number 2.

_null = unitName execVM "anyscriptname.sqf";

in anyscriptname.sqf, _this refers to unitName

_this select 0, will error out, sicne there is not array to select from, its only 1 object.

_null = this execVM "anyscriptname.sqf";

in anyscriptname.sqf, _this refers to this(wich would be the whatever object it was placed in initline of)(basically the objects name)

same as above.

Edited by Demonized

Share this post


Link to post
Share on other sites
Sign in to follow this  

×