Home   Help Search Login Register  

Author Topic: setVehicleInit  (Read 2849 times)

0 Members and 1 Guest are viewing this topic.

Offline LurchiDerLurch

  • Members
  • *
setVehicleInit
« on: 22 Apr 2010, 18:46:41 »
Hello!

I don't know what I'm doing wrong =(

Code: [Select]
_shell = "B_30x113mm_M789_HEDP" createvehicle _pos;
_shell setVehicleInit "tracer = [This] execVM ""tracer.sqf""";
processInitCommands;

tracer.sqf:
Code: [Select]
titleText ["Show this text", "PLAIN"];
But nothing happens...  :confused:

Any idea?

Lurchi

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: setVehicleInit
« Reply #1 on: 22 Apr 2010, 19:06:24 »
just two remarks

1) "bla ""bla2"" bla" => "bla 'bla2' bla"

2) setVehicleInit is for events you want JIP players to experience on connect
for only live execution PV/PVEH is the way to go

and many setVehicleInit are bad as you cannot clear them.
so you can cause a lot of network traffic for JIP if used unwisely.


Offline LurchiDerLurch

  • Members
  • *
Re: setVehicleInit
« Reply #2 on: 22 Apr 2010, 20:11:05 »
Many thanks... I'm not very experienced with MP  :no:

So it's the same way like the sounds... http://www.ofpec.com/forum/index.php?topic=34845.0

A question:

Code: [Select]
_soundsource = "HeliHEmpty" createVehicle (position player);
_sound = "MySoundFile";
AAS_PublicSound = [_soundsource,_sound];
publicVariable "AAS_PublicSound";
_soundsource say _sound;

Am I right that without the last line "_soundsource say _sound;" the server (or me in singleplayer) can't hear the sound?

edit: has been settled... ^^
Quote
Biki States:
Multiplayer: Note that the EH is only fired on clients where the publicVariable command has not been executed, as publicVariable does not change the variable where it has been executed. 
« Last Edit: 22 Apr 2010, 20:12:36 by LurchiDerLurch »

Offline Loyalguard

  • Former Staff
  • ****
Re: setVehicleInit
« Reply #3 on: 23 Apr 2010, 01:41:40 »
If you are looking for a way to "mimic" a PVEH on the same machine where the publicVariable command was executed, it is a little more work, but here is one way to do it.  The script and variable names are just for the example.  You can use anything.  Please excuse any typos.

First initialize your PV and add the PVEH.  The PVEH will send the name of the variable and its value to a script called event.sqf that will execute any code we want run when the PVEH fires:

Code: [Select]
// init.sqf

// Set the initial value of the PV only if it is nil in order to not override a JIP update or other updated value assignment.
if {!isNil "myPublicVariable"} then {myPublicVariable = false;};

// Create a PVEH that will send the name of the variable and its value to event.sqf whenever the value of the PV changes.
"myPublicVariable" addPublicVariableEventHandler {[(_this select 0), (_this select 1)] execVM "event.sqf"};

Next for example, create a script that uses the publicVariable command.  Here I am calling it monitor.sqf, it doesn't matter where/how you send the PV.  This script sets the PV to true (initial false) and then broadcasts the PV.  However, it also "mimics" a PVEH by also sending the name and value of the variable to event.sqf

Code: [Select]
// monitor.sqf

// Wait until something happens...
waitUntil{...};

// Set the PV to true and broadcast it to all other machines.
myPublicVariable = true;
publicVariable "myPublicVariable";

// Send the name of variable and its value to event.sqf  directly on this machine since the PVEH won't fire on the same machine that broadcasts it.
_nul  = ["myPublicVariable", true] execVM "event.sqf"


Finally here is event.sqf that runs some sample code (just a simple hint here but shows how the variable

Code: [Select]
// event.sqf

// Scope //
private ["_var", "_val"];

// Parameter(s) //
_var = (_this select 0); // Name of public variable that has changed value (string).
_val  = (_this select 1); // The current value of the public variable after being changed (any).

hint format [ "The PV %1 is %2!", _var, _val]; // Output: The PV "myPublicVariable" is true!.
« Last Edit: 23 Apr 2010, 16:27:24 by Loyalguard »

Offline LurchiDerLurch

  • Members
  • *
Re: setVehicleInit
« Reply #4 on: 23 Apr 2010, 14:21:01 »
Thanks for your helpful work  :good:

I think I can now handle the MP  :D