Jump to content
Sign in to follow this  
tophe

Simple Vehicle Respawn Script [Arma3]

Recommended Posts

Yeh cheers mate it must have been the .sqf file that was wrong thanks for that..

No problem at all

Share this post


Link to post
Share on other sites

I test a little bit around with that script and it works fine but I have one problem if i put more in the init field like that:

 0 = [this,5]execVM "vehicle_respawn.sqf";this addEventHandler ["GetIn", {_this execVM ""scripttocall.sqf"}];

or

0 = [this,5,"this addEventHandler [""GetIn"", {_this execVM ""scripttocall.sqf""}];"] execVM "vehicle_respawn.sqf";

or

0 = [this,5,"this addEventHandler [""GetIn"", {_this execVM ""scripttocall.sqf""}];"] execVM "vehicle_respawn.sqf";this addEventHandler ["GetIn", {_this execVM "scripttocall.sqf"}];

the script that i call via init field doesn't work after respawn.

Share this post


Link to post
Share on other sites
Ok i return!!... i tried all i can do! And now i know exactly the problem with this script!

This script (naong's script with the 0.56 game version) is good to have a respawn vehicle, and has no bug!

But there's still a problem :

When you're not the leader (of your squad/group), you can't drive or get in assault boat/vehicle, if your vehicle isn't "unlocked"!

The problem is that, when the vehicle respawn, it's not "unlocked" anymore!!..

Then you cannot drive it if you're not leader!

What can i do for that?

Is there a problem with the respawn?

Thx !

and what new about this ?

Share this post


Link to post
Share on other sites
I test a little bit around with that script and it works fine but I have one problem if i put more in the init field like that:

 0 = [this,5]execVM "vehicle_respawn.sqf";this addEventHandler ["GetIn", {_this execVM ""scripttocall.sqf"}];

or

0 = [this,5,"this addEventHandler [""GetIn"", {_this execVM ""scripttocall.sqf""}];"] execVM "vehicle_respawn.sqf";

or

0 = [this,5,"this addEventHandler [""GetIn"", {_this execVM ""scripttocall.sqf""}];"] execVM "vehicle_respawn.sqf";this addEventHandler ["GetIn", {_this execVM "scripttocall.sqf"}];

the script that i call via init field doesn't work after respawn.

yeah, it wont with my script, it doesnt take init commands (although I could extend it to do so), it only does the respawn on the timer.

Share this post


Link to post
Share on other sites

I have modified naong's script with some code from Kronzky released many a years ago, from testing seems now to be working including vehicle init lines.

[color=#000000][color=#007700]if (![/color][color=#0000BB]isServer[/color][color=#007700]) [/color][color=#0000BB]exitWith [/color][color=#007700]{};

[/color][color=#FF8000]// Define variables
[/color][color=#0000BB]_unit [/color][color=#007700]= [/color][color=#0000BB]_this select 0[/color][color=#007700];
[/color][color=#0000BB]_delay [/color][color=#007700]= if ([/color][color=#0000BB]count _this [/color][color=#007700]> [/color][color=#0000BB]1[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_this select 1[/color][color=#007700]} else {[/color][color=#0000BB]30[/color][color=#007700]};
[/color][color=#0000BB]_deserted [/color][color=#007700]= if ([/color][color=#0000BB]count _this [/color][color=#007700]> [/color][color=#0000BB]2[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_this select 2[/color][color=#007700]} else {[/color][color=#0000BB]120[/color][color=#007700]};
[/color][color=#0000BB]_respawns [/color][color=#007700]= if ([/color][color=#0000BB]count _this [/color][color=#007700]> [/color][color=#0000BB]3[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_this select 3[/color][color=#007700]} else {[/color][color=#0000BB]0[/color][color=#007700]};
[/color][color=#0000BB]_explode [/color][color=#007700]= if ([/color][color=#0000BB]count _this [/color][color=#007700]> [/color][color=#0000BB]4[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_this select 4[/color][color=#007700]} else {[/color][color=#0000BB]false[/color][color=#007700]};
[/color][color=#0000BB]_dynamic [/color][color=#007700]= if ([/color][color=#0000BB]count _this [/color][color=#007700]> [/color][color=#0000BB]5[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_this select 5[/color][color=#007700]} else {[/color][color=#0000BB]false[/color][color=#007700]};
[/color][color=#0000BB]_unitinit [/color][color=#007700]= if ([/color][color=#0000BB]count _this [/color][color=#007700]> [/color][color=#0000BB]6[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_this select 6[/color][color=#007700]} else {};
[/color][color=#0000BB]_haveinit [/color][color=#007700]= if ([/color][color=#0000BB]count _this [/color][color=#007700]> [/color][color=#0000BB]6[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]true[/color][color=#007700]} else {[/color][color=#0000BB]false[/color][color=#007700]};

[/color][color=#0000BB]_hasname [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700];
[/color][color=#0000BB]_unitname [/color][color=#007700]= [/color][color=#0000BB]vehicleVarName _unit[/color][color=#007700];
if ([/color][color=#0000BB]isNil _unitname[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_hasname [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700];} else {[/color][color=#0000BB]_hasname [/color][color=#007700]= [/color][color=#0000BB]true[/color][color=#007700];};
[/color][color=#0000BB]_noend [/color][color=#007700]= [/color][color=#0000BB]true[/color][color=#007700];
[/color][color=#0000BB]_run [/color][color=#007700]= [/color][color=#0000BB]true[/color][color=#007700];
[/color][color=#0000BB]_rounds [/color][color=#007700]= [/color][color=#0000BB]0[/color][color=#007700];

if ([/color][color=#0000BB]_delay [/color][color=#007700]< [/color][color=#0000BB]0[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_delay [/color][color=#007700]= [/color][color=#0000BB]0[/color][color=#007700]};
if ([/color][color=#0000BB]_deserted [/color][color=#007700]< [/color][color=#0000BB]0[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_deserted [/color][color=#007700]= [/color][color=#0000BB]0[/color][color=#007700]};
if ([/color][color=#0000BB]_respawns [/color][color=#007700]<= [/color][color=#0000BB]0[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_respawns[/color][color=#007700]= [/color][color=#0000BB]0[/color][color=#007700]; [/color][color=#0000BB]_noend [/color][color=#007700]= [/color][color=#0000BB]true[/color][color=#007700];};
if ([/color][color=#0000BB]_respawns [/color][color=#007700]> [/color][color=#0000BB]0[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_noend [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700]};

[/color][color=#0000BB]_dir [/color][color=#007700]= [/color][color=#0000BB]getDir _unit[/color][color=#007700];
[/color][color=#0000BB]_position [/color][color=#007700]= [/color][color=#0000BB]getPosASL _unit[/color][color=#007700];
[/color][color=#0000BB]_type [/color][color=#007700]= [/color][color=#0000BB]typeOf _unit[/color][color=#007700];
[/color][color=#0000BB]_dead [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700];
[/color][color=#0000BB]_nodelay [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700];

[/color][color=#FF8000]// Kronzky's code
[/color][color=#0000BB]KRON_StrToArray [/color][color=#007700]= {
   private[[/color][color=#DD0000]"_in"[/color][color=#007700],[/color][color=#DD0000]"_i"[/color][color=#007700],[/color][color=#DD0000]"_arr"[/color][color=#007700],[/color][color=#DD0000]"_out"[/color][color=#007700]];
   [/color][color=#0000BB]_in[/color][color=#007700]=[/color][color=#0000BB]_this select 0[/color][color=#007700];
   [/color][color=#0000BB]_arr [/color][color=#007700]= [/color][color=#0000BB]toArray[/color][color=#007700]([/color][color=#0000BB]_in[/color][color=#007700]);
   [/color][color=#0000BB]_out[/color][color=#007700]=[];
   for [/color][color=#DD0000]"_i" [/color][color=#0000BB]from 0 to [/color][color=#007700]([/color][color=#0000BB]count _arr[/color][color=#007700])-[/color][color=#0000BB]1 [/color][color=#007700]do {
       [/color][color=#0000BB]_out[/color][color=#007700]=[/color][color=#0000BB]_out[/color][color=#007700]+[[/color][color=#0000BB]toString[/color][color=#007700]([[/color][color=#0000BB]_arr select _i[/color][color=#007700]])];
   };
   [/color][color=#0000BB]_out
[/color][color=#007700]};

[/color][color=#0000BB]KRON_StrLen [/color][color=#007700]= {
   private[[/color][color=#DD0000]"_in"[/color][color=#007700],[/color][color=#DD0000]"_arr"[/color][color=#007700],[/color][color=#DD0000]"_len"[/color][color=#007700]];
   [/color][color=#0000BB]_in[/color][color=#007700]=[/color][color=#0000BB]_this select 0[/color][color=#007700];
   [/color][color=#0000BB]_arr[/color][color=#007700]=[[/color][color=#0000BB]_in[/color][color=#007700]] [/color][color=#0000BB]call KRON_StrToArray[/color][color=#007700];
   [/color][color=#0000BB]_len[/color][color=#007700]=[/color][color=#0000BB]count [/color][color=#007700]([/color][color=#0000BB]_arr[/color][color=#007700]);
   [/color][color=#0000BB]_len
[/color][color=#007700]};

[/color][color=#0000BB]KRON_Replace [/color][color=#007700]= {
   private[[/color][color=#DD0000]"_str"[/color][color=#007700],[/color][color=#DD0000]"_old"[/color][color=#007700],[/color][color=#DD0000]"_new"[/color][color=#007700],[/color][color=#DD0000]"_out"[/color][color=#007700],[/color][color=#DD0000]"_tmp"[/color][color=#007700],[/color][color=#DD0000]"_jm"[/color][color=#007700],[/color][color=#DD0000]"_la"[/color][color=#007700],[/color][color=#DD0000]"_lo"[/color][color=#007700],[/color][color=#DD0000]"_ln"[/color][color=#007700],[/color][color=#DD0000]"_i"[/color][color=#007700]];
   [/color][color=#0000BB]_str[/color][color=#007700]=[/color][color=#0000BB]_this select 0[/color][color=#007700];
   [/color][color=#0000BB]_arr[/color][color=#007700]=[/color][color=#0000BB]toArray[/color][color=#007700]([/color][color=#0000BB]_str[/color][color=#007700]);
   [/color][color=#0000BB]_la[/color][color=#007700]=[/color][color=#0000BB]count _arr[/color][color=#007700];
   [/color][color=#0000BB]_old[/color][color=#007700]=[/color][color=#0000BB]_this select 1[/color][color=#007700];
   [/color][color=#0000BB]_new[/color][color=#007700]=[/color][color=#0000BB]_this select 2[/color][color=#007700];
   [/color][color=#0000BB]_na[/color][color=#007700]=[[/color][color=#0000BB]_new[/color][color=#007700]] [/color][color=#0000BB]call KRON_StrToArray[/color][color=#007700];
   [/color][color=#0000BB]_lo[/color][color=#007700]=[[/color][color=#0000BB]_old[/color][color=#007700]] [/color][color=#0000BB]call KRON_StrLen[/color][color=#007700];
   [/color][color=#0000BB]_ln[/color][color=#007700]=[[/color][color=#0000BB]_new[/color][color=#007700]] [/color][color=#0000BB]call KRON_StrLen[/color][color=#007700];
   [/color][color=#0000BB]_out[/color][color=#007700]=[/color][color=#DD0000]""[/color][color=#007700];
   for [/color][color=#DD0000]"_i" [/color][color=#0000BB]from 0 to [/color][color=#007700]([/color][color=#0000BB]count _arr[/color][color=#007700])-[/color][color=#0000BB]1 [/color][color=#007700]do {
       [/color][color=#0000BB]_tmp[/color][color=#007700]=[/color][color=#DD0000]""[/color][color=#007700];
       if ([/color][color=#0000BB]_i [/color][color=#007700]<= [/color][color=#0000BB]_la[/color][color=#007700]-[/color][color=#0000BB]_lo[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{
           for [/color][color=#DD0000]"_j" [/color][color=#0000BB]from _i to [/color][color=#007700]([/color][color=#0000BB]_i[/color][color=#007700]+[/color][color=#0000BB]_lo[/color][color=#007700]-[/color][color=#0000BB]1[/color][color=#007700]) do {
               [/color][color=#0000BB]_tmp[/color][color=#007700]=[/color][color=#0000BB]_tmp [/color][color=#007700]+ [/color][color=#0000BB]toString[/color][color=#007700]([[/color][color=#0000BB]_arr select _j[/color][color=#007700]]);
           };
       };
       if ([/color][color=#0000BB]_tmp[/color][color=#007700]==[/color][color=#0000BB]_old[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{
           [/color][color=#0000BB]_out[/color][color=#007700]=[/color][color=#0000BB]_out[/color][color=#007700]+[/color][color=#0000BB]_new[/color][color=#007700];
           [/color][color=#0000BB]_i[/color][color=#007700]=[/color][color=#0000BB]_i[/color][color=#007700]+[/color][color=#0000BB]_lo[/color][color=#007700]-[/color][color=#0000BB]1[/color][color=#007700];
       } else {
           [/color][color=#0000BB]_out[/color][color=#007700]=[/color][color=#0000BB]_out[/color][color=#007700]+[/color][color=#0000BB]toString[/color][color=#007700]([[/color][color=#0000BB]_arr select _i[/color][color=#007700]]);
       };
   };
   [/color][color=#0000BB]_out
[/color][color=#007700]};
[/color][color=#FF8000]// End of Kronzky's code

// Start monitoring the vehicle
[/color][color=#007700]while {[/color][color=#0000BB]_run[/color][color=#007700]} do 
{    
   [/color][color=#0000BB]sleep [/color][color=#007700]([/color][color=#0000BB]2 [/color][color=#007700]+ [/color][color=#0000BB]random 10[/color][color=#007700]);
     if (([/color][color=#0000BB]getDammage _unit [/color][color=#007700]> [/color][color=#0000BB]0.8[/color][color=#007700]) and ({[/color][color=#0000BB]alive _x[/color][color=#007700]} [/color][color=#0000BB]count crew _unit [/color][color=#007700]== [/color][color=#0000BB]0[/color][color=#007700])) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_dead [/color][color=#007700]= [/color][color=#0000BB]true[/color][color=#007700]};

   [/color][color=#FF8000]// Check if the vehicle is deserted.
   [/color][color=#007700]if ([/color][color=#0000BB]_deserted [/color][color=#007700]> [/color][color=#0000BB]0[/color][color=#007700]) [/color][color=#0000BB]then
   [/color][color=#007700]{
       if (([/color][color=#0000BB]getPosASL _unit distance _position [/color][color=#007700]> [/color][color=#0000BB]10[/color][color=#007700]) and ({[/color][color=#0000BB]alive _x[/color][color=#007700]} [/color][color=#0000BB]count crew _unit [/color][color=#007700]== [/color][color=#0000BB]0[/color][color=#007700]) and ([/color][color=#0000BB]getDammage _unit [/color][color=#007700]< [/color][color=#0000BB]0.8[/color][color=#007700])) [/color][color=#0000BB]then 
       [/color][color=#007700]{
           [/color][color=#0000BB]_timeout [/color][color=#007700]= [/color][color=#0000BB]time [/color][color=#007700]+ [/color][color=#0000BB]_deserted[/color][color=#007700];
           [/color][color=#0000BB]sleep 0.1[/color][color=#007700];
            [/color][color=#0000BB]waitUntil [/color][color=#007700]{[/color][color=#0000BB]_timeout [/color][color=#007700]< [/color][color=#0000BB]time [/color][color=#007700]or ![/color][color=#0000BB]alive _unit [/color][color=#007700]or {[/color][color=#0000BB]alive _x[/color][color=#007700]} [/color][color=#0000BB]count crew _unit [/color][color=#007700]> [/color][color=#0000BB]0[/color][color=#007700]};
           if ({[/color][color=#0000BB]alive _x[/color][color=#007700]} [/color][color=#0000BB]count crew _unit [/color][color=#007700]> [/color][color=#0000BB]0[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_dead [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700]}; 
           if ({[/color][color=#0000BB]alive _x[/color][color=#007700]} [/color][color=#0000BB]count crew _unit [/color][color=#007700]== [/color][color=#0000BB]0[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_dead [/color][color=#007700]= [/color][color=#0000BB]true[/color][color=#007700]; [/color][color=#0000BB]_nodelay [/color][color=#007700]=[/color][color=#0000BB]true[/color][color=#007700]}; 
           if !([/color][color=#0000BB]alive _unit[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_dead [/color][color=#007700]= [/color][color=#0000BB]true[/color][color=#007700]; [/color][color=#0000BB]_nodelay [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700]}; 
       };
   };

   [/color][color=#FF8000]// Respawn vehicle
     [/color][color=#007700]if ([/color][color=#0000BB]_dead[/color][color=#007700]) [/color][color=#0000BB]then 
   [/color][color=#007700]{    
       if ([/color][color=#0000BB]_nodelay[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]sleep 0.1[/color][color=#007700]; [/color][color=#0000BB]_nodelay [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700];} else {[/color][color=#0000BB]sleep _delay[/color][color=#007700];};
       if ([/color][color=#0000BB]_dynamic[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_position [/color][color=#007700]= [/color][color=#0000BB]getPosASL _unit[/color][color=#007700]; [/color][color=#0000BB]_dir [/color][color=#007700]= [/color][color=#0000BB]getDir _unit[/color][color=#007700];};
       if ([/color][color=#0000BB]_explode[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_effect [/color][color=#007700]= [/color][color=#DD0000]"M_AT" [/color][color=#0000BB]createVehicle getPosASL _unit[/color][color=#007700]; [/color][color=#0000BB]_effect setPosASL getPosASL _unit[/color][color=#007700];};
       [/color][color=#0000BB]sleep 0.1[/color][color=#007700];

       [/color][color=#0000BB]deleteVehicle _unit[/color][color=#007700];
       [/color][color=#0000BB]sleep 2[/color][color=#007700];
       [/color][color=#0000BB]_unit [/color][color=#007700]= [/color][color=#0000BB]_type createVehicle _position[/color][color=#007700];
       [/color][color=#0000BB]_unit setPosASL _position[/color][color=#007700];
       [/color][color=#0000BB]_unit setDir _dir[/color][color=#007700];
       if ([/color][color=#0000BB]_haveinit[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{
           [/color][color=#FF8000]//_unit setVehicleInit format ["%1;", _unitinit];
           //processInitCommands;
           // Modified by BearBison
           [/color][color=#007700]private [[/color][color=#DD0000]"_IDunit"[/color][color=#007700], [/color][color=#DD0000]"_sCommand"[/color][color=#007700]];
           [/color][color=#0000BB]_IDunit [/color][color=#007700]= [/color][color=#0000BB]format[/color][color=#007700][[/color][color=#DD0000]"(objectFromNetID '%1')"[/color][color=#007700], [/color][color=#0000BB]netID _unit[/color][color=#007700]];
           [/color][color=#0000BB]_sCommand[/color][color=#007700]=[[/color][color=#0000BB]format[/color][color=#007700][[/color][color=#DD0000]"%1"[/color][color=#007700],[/color][color=#0000BB]_unitinit[/color][color=#007700]],[/color][color=#DD0000]"this"[/color][color=#007700],[/color][color=#0000BB]format[/color][color=#007700][[/color][color=#DD0000]"%1"[/color][color=#007700],[/color][color=#0000BB]_IDunit[/color][color=#007700]]] [/color][color=#0000BB]call KRON_Replace[/color][color=#007700];
           [/color][color=#FF8000]// End of code modified by BearBison
           // Modified by naong
           [/color][color=#007700][[/color][color=#0000BB]call compile format[/color][color=#007700][[/color][color=#DD0000]"%1"[/color][color=#007700],[/color][color=#0000BB]_sCommand[/color][color=#007700]], [/color][color=#DD0000]"BIS_fnc_spawn"[/color][color=#007700], [/color][color=#0000BB]true[/color][color=#007700], [/color][color=#0000BB]true[/color][color=#007700]] [/color][color=#0000BB]spawn BIS_fnc_MP[/color][color=#007700];
       };
       if ([/color][color=#0000BB]_hasname[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{
           [/color][color=#FF8000]//_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
           //processInitCommands;
           [/color][color=#007700]private [/color][color=#DD0000]"_sCommand"[/color][color=#007700];
           [/color][color=#0000BB]_sCommand [/color][color=#007700]= [/color][color=#0000BB]format[/color][color=#007700][[/color][color=#DD0000]"[{(objectFromNetID '%1') setVehicleVarName '%2';}]"[/color][color=#007700], [/color][color=#0000BB]netID _unit[/color][color=#007700], [/color][color=#0000BB]_unitname[/color][color=#007700]];
           [[/color][color=#0000BB]call compile format[/color][color=#007700][[/color][color=#DD0000]"%1"[/color][color=#007700],[/color][color=#0000BB]_sCommand[/color][color=#007700]],[/color][color=#DD0000]"BIS_fnc_spawn"[/color][color=#007700], [/color][color=#0000BB]true[/color][color=#007700], [/color][color=#0000BB]true[/color][color=#007700]] [/color][color=#0000BB]spawn BIS_fnc_MP[/color][color=#007700];
           [/color][color=#0000BB]_unit call compile format [/color][color=#007700][[/color][color=#DD0000]"%1=_This; PublicVariable '%1'"[/color][color=#007700],[/color][color=#0000BB]_unitname[/color][color=#007700]];
       };
       [/color][color=#FF8000]// End of code modified by naong
       [/color][color=#0000BB]_dead [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700];

       [/color][color=#FF8000]// Check respawn amount
       [/color][color=#007700]if !([/color][color=#0000BB]_noend[/color][color=#007700]) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_rounds [/color][color=#007700]= [/color][color=#0000BB]_rounds [/color][color=#007700]+ [/color][color=#0000BB]1[/color][color=#007700]};
       if (([/color][color=#0000BB]_rounds [/color][color=#007700]== [/color][color=#0000BB]_respawns[/color][color=#007700]) and !([/color][color=#0000BB]_noend[/color][color=#007700])) [/color][color=#0000BB]then [/color][color=#007700]{[/color][color=#0000BB]_run [/color][color=#007700]= [/color][color=#0000BB]false[/color][color=#007700];};
   };
}; 

[/color][/color]

EDIT: Unfortunately only seems to work with basic commands, when trying to use execVM it errors or second respawn

Edited by BearBison
Additional partial failure info

Share this post


Link to post
Share on other sites

Ok tested it out with that init field:

veh = [this, 60, 300, 0, FALSE, FALSE, "
nul = [this,""H4"",0.5] execVM ""scripts\mark_unit.sqf"";
this addEventHandler [""GetIn"", {_this execVM ""scripts\vehiclelock.sqf""}];"]execVM "scripts\vehicle.sqf";
nul = [this,"H4",0.5] execVM "scripts\mark_unit.sqf";
this addEventHandler ["GetIn", {_this execVM "scripts\vehiclelock.sqf"}];

after the respawn I get an error ( missing ; )

I think it works, but there is a problem by placing the init field code back to the vehicle.

The error I get has something to do with my init field code I think.

the error:

'...omNetID '') addEventHandler ["GetIn", {_|#|(objectFormNetID '') execVM "scripts\veh...'

Error Missing ;

maybe I made something wrong.

anjan

Share this post


Link to post
Share on other sites

OK I can see why it is throwing the error with the init scripts you have, I only tested with ones that only had "this" and not "_this".

I can see a way around it using the method that I use for all vehicles/objects which is calling a script which then adds all the other inits to the vehicle.

I will try and put an example up ASAP for you.

Share this post


Link to post
Share on other sites

Unfortunately not been able to get it working fully as no matter what method I seem to put it throws an error when it tries to put the inits back for the second time I destroy the vehicle. Works perfect if I use some of the straight commands that I used in testing but not when I try to use execvm or commands with _this :(

Will keep looking at it to see if I can get it working any further, at least it seems to be a step in the correct direction.

Share this post


Link to post
Share on other sites
Unfortunately not been able to get it working fully as no matter what method I seem to put it throws an error when it tries to put the inits back for the second time I destroy the vehicle. Works perfect if I use some of the straight commands that I used in testing but not when I try to use execvm or commands with _this :(

Will keep looking at it to see if I can get it working any further, at least it seems to be a step in the correct direction.

At line 122:

[call compile format["%1",_sCommand], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;

Brackets and braces are missing for the code to be correctly executed by BIS_fnc_spawn:

[call compile format["[b][color="#FF0000"][{[/color][/b]%1[b][color="#FF0000"]}][/color][/b]",_sCommand], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;

Untested, but hopefully it may fix your problem.

Share this post


Link to post
Share on other sites

Thanks AgentRev,

Seems to have done the trick from a quick test, will do a better test tomorrow night when I am more awake unless someone else manages to have a look before then.

Share this post


Link to post
Share on other sites

nope doesn't work with my init and i changed this one in line 129 after the first test too.

Share this post


Link to post
Share on other sites
nope doesn't work with my init and i changed this one in line 129 after the first test too.

By looking at the init snippets you posted on page 8, I can see the problem comes from the string replace functions that BearBison added. Those functions convert every occurence of the word "this" in the init command to objectFromNetId's. The issue with your inits is that it even converts the nested "_this" inside of addEventHandler to something like "_(objectFromNetId '12345')", which of course is invalid.

Now, onto a practical solution: I looked at BIS_fnc_spawn in the Functions Viewer, and noticed it can also accepts 2 parameters. In that case, it defines the 1st param as the scope for executing the code (2nd param). So, in theory, this should do the trick:

if (_haveinit) then {
   [call compile format ["[objectFromNetId '%1', {%2}]", netId _unit, _unitinit], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
};

HOWEVER: Make sure to put underscores (_) behind all "this" statements in your inits, as "this" without underscores were specific to setVehicleInit.

Again, untested.

Share this post


Link to post
Share on other sites
By looking at the init snippets you posted on page 8, I can see the problem comes from the string replace functions that BearBison added. Those functions convert every occurence of the word "this" in the init command to objectFromNetId's. The issue with your inits is that it even converts the nested "_this" inside of addEventHandler to something like "_(objectFromNetId '12345')", which of course is invalid.

Now, onto a practical solution: I looked at BIS_fnc_spawn in the Functions Viewer, and noticed it can also accepts 2 parameters. In that case, it defines the 1st param as the scope for executing the code (2nd param). So, in theory, this should do the trick:

if (_haveinit) then {
   [call compile format ["[objectFromNetId '%1', {%2}]", netId _unit, _unitinit], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
};

HOWEVER: Make sure to put underscores (_) behind all "this" statements in your inits, as "this" without underscores were specific to setVehicleInit.

Again, untested.

Just a heads up (_) is a local variable (object,value or string) command and with out it is a Global variable command

Share this post


Link to post
Share on other sites
Just a heads up (_) is a local variable (object,value or string) command and with out it is a Global variable command

Of course, but in the very particular case of commands passed to "setVehicleInit", the "this" constant (which represented the vehicle) was local, and was required to not be prefixed by an underscore, for some reason.

Share this post


Link to post
Share on other sites

When I get back from work today, I will post the method that I mentioned and quickly tested last night to get it working with that additional code from the functions viewer that I missed.

I'll also test the last code to see if it works, I don't use this script in any of my missions, just came across the issue as one of the missions that our group wanted to play was broken after the update and managed to do a quick fix to get the mission playable.

Share this post


Link to post
Share on other sites

Err, is it me or:

1) netId doesn't return anything whatsoever? It's supposed to return a string but it just doesn't give anything.

2) Can't find ANY details on BIS_fnc_spawn anywhere. It's not even listed when you list all ARMA functions and there are no references to it anywhere on the internet (that's rare!). The hell did you find that function and how is it structured?

Share this post


Link to post
Share on other sites
if (_haveinit) then {
   [call compile format ["[objectFromNetId '%1', {%2}]", netId _unit, _unitinit], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
};

Unfortunately this one gives the same issue as the code from naong.

Here is a copy of the one I have which seems to be working using the inits from Anjan-Riot but I have created simple hints for the files that are used, one when the vehicle has spawned and another when the player gets in. Use the explosive charges to destroy the hunter that is not damaged and you will see it working, the other hunter that is damaged and has fuel at 50% is there just to show that if you don't use inits with _this in them it can be done directly.

Again this is probably not the best code but it appears to work :)

if (!isServer) exitWith {};

// Define variables
_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {30};
_deserted = if (count _this > 2) then {_this select 2} else {120};
_respawns = if (count _this > 3) then {_this select 3} else {0};
_explode = if (count _this > 4) then {_this select 4} else {false};
_dynamic = if (count _this > 5) then {_this select 5} else {false};
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;
_unitname = vehicleVarName _unit;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;

// Kronzky's code
KRON_StrToArray = {
   private["_in","_i","_arr","_out"];
   _in=_this select 0;
   _arr = toArray(_in);
   _out=[];
   for "_i" from 0 to (count _arr)-1 do {
       _out=_out+[toString([_arr select _i])];
   };
   _out
};

KRON_StrLen = {
   private["_in","_arr","_len"];
   _in=_this select 0;
   _arr=[_in] call KRON_StrToArray;
   _len=count (_arr);
   _len
};

KRON_Replace = {
   private["_str","_old","_new","_out","_tmp","_jm","_la","_lo","_ln","_i"];
   _str=_this select 0;
   _arr=toArray(_str);
   _la=count _arr;
   _old=_this select 1;
   _new=_this select 2;
   _na=[_new] call KRON_StrToArray;
   _lo=[_old] call KRON_StrLen;
   _ln=[_new] call KRON_StrLen;
   _out="";
   for "_i" from 0 to (count _arr)-1 do {
       _tmp="";
       if (_i <= _la-_lo) then {
           for "_j" from _i to (_i+_lo-1) do {
               _tmp=_tmp + toString([_arr select _j]);
           };
       };
       if (_tmp==_old) then {
           _out=_out+_new;
           _i=_i+_lo-1;
       } else {
           _out=_out+toString([_arr select _i]);
       };
   };
   _out
};
// End of Kronzky's code

// Start monitoring the vehicle
while {_run} do 
{    
   sleep (2 + random 10);
     if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

   // Check if the vehicle is deserted.
   if (_deserted > 0) then
   {
       if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then 
       {
           _timeout = time + _deserted;
           sleep 0.1;
            waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
           if ({alive _x} count crew _unit > 0) then {_dead = false}; 
           if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true}; 
           if !(alive _unit) then {_dead = true; _nodelay = false}; 
       };
   };

   // Respawn vehicle
     if (_dead) then 
   {    
       if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
       if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
       if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
       sleep 0.1;

       deleteVehicle _unit;
       sleep 2;
       _unit = _type createVehicle _position;
       _unit setPosASL _position;
       _unit setDir _dir;
       if (_haveinit) then {
           //_unit setVehicleInit format ["%1;", _unitinit];
           //processInitCommands;
           // Modified by BearBison
           private ["_IDunit", "_sCommand"];
           _IDunit = format["(objectFromNetID '%1')", netID _unit];
           _sCommand=[format["%1",_unitinit],"this",format["%1",_IDunit]] call KRON_Replace;
           // End of code modified by BearBison
           // Modified by naong and AgentRev
           [call compile format["[{%1}]",_sCommand], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
       };
       if (_hasname) then {
           //_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
           //processInitCommands;
           private "_sCommand";
           _sCommand = format["[{(objectFromNetID '%1') setVehicleVarName '%2';}]", netID _unit, _unitname];
           [call compile format["%1",_sCommand],"BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
           _unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
       };
       // End of code modified by naong
       _dead = false;

       // Check respawn amount
       if !(_noend) then {_rounds = _rounds + 1};
       if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
   };
};

A copy of the demo mission I used can be downloaded here

Share this post


Link to post
Share on other sites

Thank you i'll test it later

---------- Post added at 06:39 PM ---------- Previous post was at 05:21 PM ----------

Doesn't work I test it with different scripts, I don't get an error.

if you want here the scripts that I am using maybe the bug is there.

vehiclelock.sqf:

private ["_vehicle", "_pos", "_unit", "_namesArray"];
_vehicle = _this select 0;
_pos = _this select 1;
_unit = _this select 2;
_namesArray = ["2434115345154151451"];

if (driver _vehicle == player) then {
_vehicle setFuel 0;
_vehicle vehicleChat format["Welcome %1! Please wait for the membership check.", name _unit];
};
sleep 3;
if ((getPlayerUID _unit) in _namesArray) then {
_vehicle vehicleChat "Membership check successful: Welcome member!";
sleep 2;
_vehicle vehicleChat format ["Engines free %1!", name _unit];
sleep 1;
_vehicle setFuel 1;
} else {
_vehicle vehicleChat "You are not a member.";
sleep 1;
_vehicle vehicleChat "Only members can use this vehicle.";
_unit action ["Eject", vehicle _unit];
_vehicle setFuel 0;
};

place a marker on the map and name it H4

mark_unit.sqf:

private ["_unit","_marker","_delay"];
_unit = _this select 0;
_marker = _this select 1;
_delay = _this select 2;
while {true} do
{
_marker setMarkerAlpha 1;
while {alive _unit} do 
{
	_marker setMarkerPosLocal getPos _unit;
	sleep _delay;
};
_marker setMarkerAlpha 0;
waitUntil {alive _unit};
};

thank you BearBison for you help

if its not working then i have to deal with it.

Share this post


Link to post
Share on other sites

Both scripts are working for me, just pasted your code in to the scripts in my test mission.

If you want PM me with a copy of your mission and I will have a look to keep this thread on subject.

Share this post


Link to post
Share on other sites
if you want here the scripts that I am using maybe the bug is there.

Actually, providing the exact init calls you are using would be much more useful. I'm pretty sure the reason why BearBison's script is not working with your mission is, as I said in my 2nd post, because "KRON_Replace" doesn't make the difference between "this" and "_this", and corrupts those with the underscore. Have you tried to log the contents of _sCommand before passing it to BIS_fnc_MP to see if there's anything wrong?

Share this post


Link to post
Share on other sites

The scripts are working using the example in my demo mission, just means a slightly different way of configuring the inits but works.

Share this post


Link to post
Share on other sites

BearBison,

Sorry but I tried your demo in SP and Editor and it doesn't work at all.

- Despite the hintbox "unit marked", nothing is marked (at the start and after it's respawn there not hintbox).

- There's nothing locked after respawn.

- The damaged vehicle is not damaged after respawning.

I didn't change anything btw, just downloaded, put it in SP mission and tried it.

edit:

- Just tried it hosting it as a MPmission and it worked.

- Just integrated the changes in my MPmission (where I have tons of vehicles with various inits) and it works. Thanks Bear, nice work! :)

Edited by Twix

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  

×