Jump to content
Sign in to follow this  
bobby budnick

Modifying respawn script

Recommended Posts

Hey guys, I am trying to modify Norrin's respawn script to add an action to the respawned vehicle when it is respawned. The addaction line I added is near the end.  This works perfectly testing it on a listen server but on the dedicated server the action is never added, no errors.  Is this because addaction has to be run on all the clients? If so, how would I do that in this case?

Thanks.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

/*

 VEHICLE RESPAWN SCRIPT SQF

 Respawns vehicles when they are destroyed or cannot move

 © May 2007 - norrin (norrins_nook@iprimus.com.au), based upon KaRRiLLioN's original vrs.sqf script.

 Version:  1.0                      

******************************************************************************************

*********************************

IMPORTANT: ADD A GAMELOGIC NAMED Server to the mission to prevent multispawn

To run this script place the following code in the init line of the vehicle:

v = [this, "vehicle name", x] execVM "vrs_AI_general.sqf"

where x is the time you wish to set for the vehicle destroyed respawn delay

Note: the vehicle name must be in quotation marks eg. if vehicle name's Hmm1 it must appear in the init line as "Hmm1"

******************************************************************************************

**********************************

Start VRS_Move.sqf

*/

private ["_vcl","_respawndelay","_dir","_pos","_type","_run","_delay"];

if (!local Server) exitWith {};

_vcl = _this select 0;

_name_vcl = _this select 1;

_respawndelay = _this select 2;

_dir = Getdir _vcl;

_pos = Getpos _vcl;

_type = typeOf _vcl;

_run = TRUE;

sleep 5;

for [{}, {_run}, {_run}] do

{

while {canMove _vcl} do  

 {

     sleep 1;

_delay = Time + _respawndelay;

 };

_delay = Time + _respawndelay;

   while {!canMove _vcl && Time < _delay} do

 {

     sleep 1;

 };

 if (!canMove _vcl && Time >= _delay) then

 {

       deleteVehicle _vcl;

         _vcl = _type createVehicle _pos;

       _vcl setVehicleVarName _name_vcl;

         _vcl setdir _dir;

         sleep 1;

         _vcl setvelocity [0,0,0];

         _vcl setpos _pos;

_vcl addAction ["Defcon 1", "detonate_vehicle.sqs", _vcl, 0, false, false, ""];

         sleep 1;

         _vcl setvelocity [0,0,0];

       sleep 2;

   };

};

Share this post


Link to post
Share on other sites

I think it may be a problem with the locality of the script and the vehicle.  When the script first respawns the vehicle it resides on the dedicated server, so the addaction command only exists on the server, however if some one gets in and drives it its my understanding that the vehicle transfers its locality to the client's PC where the addaction command does not exist.  

You can get around this problem by creating an init variable that contains the addaction command, then using SetVehicleInit and processInitCommands commands as described in this thread here: http://www.flashpoint1985.com/cgi-bin....=synide

This will hopefully ensure that the addaction command for the vehicle exists on all clients as well as the server when it respawns.

PS: I've got an updated version of this script that does not begin the respawn timer until the crew disemabrks from the vehicle (just in case its still being used as gun platform) let me know if you want it and I'll post it here.

Share this post


Link to post
Share on other sites

Thanks.  Now, on the listen server no action is added at all, no errors.  On the dedicated I get a 'error local variable in global space' referencing the line that I added.  I briefly tried to change _vcl to vcl69 to eliminate it being a local variable but I still get the error, except the error doesn't show the lines that contain the error.  It just shows a larger black box with the error and then 'line 27' at the end.  This is what the script looks like now.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

private ["_vcl","_respawndelay","_dir","_pos","_type","_run","_delay"];

if (!local Server) exitWith {};

_vcl = _this select 0;

_name_vcl = _this select 1;

_respawndelay = _this select 2;

_dir = Getdir _vcl;

_pos = Getpos _vcl;

_type = typeOf _vcl;

_run = TRUE;

sleep 5;

for [{}, {_run}, {_run}] do

{

while {canMove _vcl} do  

 {

     sleep 1;

_delay = Time + _respawndelay;

 };

_delay = Time + _respawndelay;

   while {!canMove _vcl && Time < _delay} do

 {

     sleep 1;

 };

 if (!canMove _vcl && Time >= _delay) then

 {

       deleteVehicle _vcl;

         _vcl = _type createVehicle _pos;

       _vcl setVehicleVarName _name_vcl;

         _vcl setdir _dir;

         sleep 1;

         _vcl setvelocity [0,0,0];

         _vcl setpos _pos;

_InitString = "_vcl addAction [""Defcon 1"", ""detonate_vehicle.sqs"", _vcl, 0, false, false, """"]";

_vcl SetVehicleInit _InitString;

processInitCommands;

         sleep 1;

         _vcl setvelocity [0,0,0];

       sleep 2;

   };

};

Share this post


Link to post
Share on other sites

Locality ain't it a bitch. smile_o.gif Didn't think of that m8 sorry, its a bit outside my level of expertise.  It seems that in the other thread they may have got around this problem by referencing the _vcl array.  So maybe try <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_InitString = "_vcl addAction [""Defcon 1"", ""detonate_vehicle.sqs"", _this select 0, 0, false, false, """"]"; instead of using _vcl or even <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_InitString = "this addAction [""Defcon 1"", ""detonate_vehicle.sqs"", _this select 0, 0, false, false, """"]";

Share this post


Link to post
Share on other sites

After some testing, the second suggestion seems to work fine Norrin.

Here is the final vrs_AI_general_defcon_1.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

/*

VEHICLE RESPAWN SCRIPT SQF

Respawns vehicles when they are destroyed or cannot move

© May 2007 - norrin (norrins_nook@iprimus.com.au), based upon KaRRiLLioN's original vrs.sqf script.

Version: 1.0

******************************************************************************************

*********************************

IMPORTANT: ADD A GAMELOGIC NAMED Server to the mission to prevent multispawn

To run this script place the following code in the init line of the vehicle:

v = [this, "vehicle name", x] execVM "vrs_AI_general.sqf"

where x is the time you wish to set for the vehicle destroyed respawn delay

Note: the vehicle name must be in quotation marks eg. if vehicle name's Hmm1 it must appear in the init line as "Hmm1"

******************************************************************************************

**********************************

Start VRS_Move.sqf

*/

private ["_vcl","_respawndelay","_dir","_pos","_type","_run","_delay"];

if (!local Server) exitWith {};

_vcl = _this select 0;

_name_vcl = _this select 1;

_respawndelay = _this select 2;

_dir = Getdir _vcl;

_pos = Getpos _vcl;

_type = typeOf _vcl;

_run = TRUE;

sleep 5;

for [{}, {_run}, {_run}] do

{

while {canMove _vcl} do

{

sleep 1;

_delay = Time + _respawndelay;

};

_delay = Time + _respawndelay;

while {!canMove _vcl && Time < _delay} do

{

sleep 1;

};

if (!canMove _vcl && Time >= _delay) then

{

deleteVehicle _vcl;

_vcl = _type createVehicle _pos;

_vcl setVehicleVarName _name_vcl;

_vcl setdir _dir;

sleep 1;

_vcl setvelocity [0,0,0];

_vcl setpos _pos;

_InitString = "this addAction [""Defcon 1"", ""detonate_vehicle.sqs"", this, 0, false, false, """"]";

_vcl SetVehicleInit _InitString;

processInitCommands;

sleep 1;

_vcl setvelocity [0,0,0];

sleep 2;

};

};

Also for anyone that wants it, here is my detonate_vehicle.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_vehicle = _this select 3;

{_x setDamage 1} forEach crew _vehicle;

_vehicle setDamage 1;

I use this mainly for AI tank convoys. Either with them following me or traveling alone. So when the retarded AI flips their tank or gets stuck on something I just push their number, then 6, then Defcon 1, and then byebye. I start out with 8 tanks or so and by the time I am at my objective I have 4 or so left. Not very realistic but I have wasted too many hours waiting on the AI in vehicles. Maybe this will help someone.

BTW for the clueless out there like me here is a breakdown of what that code does. The first line selects the third argument from where the script was called (I think). The second line makes sure to kill all the crew in the vehicle (though I don't understand the _x). The third line simply destroys the vehicle.

Share this post


Link to post
Share on other sites
BTW for the clueless out there like me here is a breakdown of what that code does. The first line selects the third argument from where the script was called (I think). The second line makes sure to kill all the crew in the vehicle (though I don't understand the _x). The third line simply destroys the vehicle.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x setDamage 1} forEach crew _vehicle;

The forEach command automatically cycles through the crew of the _vehicle and sets each of their damage to 1. As it cycles through the crew members the _x is replaced automatically in the code by the crew members name.

eg. There are two crew members "bob" and "tony" in a tank. To start off the forEach command selects the first crew member so _x = "bob" and then sets his damage to 1, the forEach command then selects the second element of the crew _vehicle array (ie. now _x = "tony") and then does the same thing to him.

Share this post


Link to post
Share on other sites

I've been trying to get cargo weapons/magazines to respawn via various vehicle respawn scripts on a dedicated server and have failed miserably thus far.  This modification I made to the above script seemed to almost do it, however it only seems to spawn the list of weapons from "weapon.sqs", and I cannot actually equip any of them.  I thought locality was the issue all along but I just don't know what else to do.  Is it possible to even do what I am attempting?  Below are examples of the mpmission that I am running on a dedicated linux server, and then testing it from a game client.  

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

[this] exec "first_weapons.sqs"; v = [this, "hum2", 10] execVM "vrs_AI_general.sqf"

Part of first_weapons.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_vehicle = _this select 0

; Add the items to the _vehicle

clearWeaponCargo _vehicle

clearMagazineCargo _vehicle

_vehicle addWeaponCargo ["M16A2", 24]

_vehicle addWeaponCargo ["M16A2GL", 24]

_vehicle addWeaponCargo ["M4", 24]

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">/*

VEHICLE RESPAWN SCRIPT SQF

Respawns vehicles when they are destroyed or cannot move

© May 2007 - norrin (norrins_nook@iprimus.com.au), based upon KaRRiLLioN's original vrs.sqf script.

Version:  1.0                      

******************************************************************************************

*********************************

IMPORTANT: ADD A GAMELOGIC NAMED Server to the mission to prevent multispawn

To run this script place the following code in the init line of the vehicle:

v = [this, "vehicle name", x] execVM "vrs_AI_general.sqf"

where x is the time you wish to set for the vehicle destroyed respawn delay

Note: the vehicle name must be in quotation marks eg. if vehicle name's Hmm1 it must appear in the init line as "Hmm1"

******************************************************************************************

**********************************

Start VRS_Move.sqf

*/

private ["_vcl","_respawndelay","_dir","_pos","_type","_run","_delay"];

if (!local Server) exitWith {};

_vcl = _this select 0;

_name_vcl = _this select 1;

_respawndelay = _this select 2;

_dir = Getdir _vcl;

_pos = Getpos _vcl;

_type = typeOf _vcl;

_run = TRUE;

sleep 5;

for [{}, {_run}, {_run}] do

{

while {canMove _vcl} do  

{

    sleep 1;

_delay = Time + _respawndelay;

};

_delay = Time + _respawndelay;

  while {!canMove _vcl && Time < _delay} do

{

    sleep 1;

};

if (!canMove _vcl && Time >= _delay) then

{

      deleteVehicle _vcl;

        _vcl = _type createVehicle _pos;

      _vcl setVehicleVarName _name_vcl;

        _vcl setdir _dir;

        sleep 1;

        _vcl setvelocity [0,0,0];

        _vcl setpos _pos;

  _InitString = "this addAction [""Load Weapons"", ""weapon.sqs"", this, 0, false, false, """"]";

  _vcl SetVehicleInit _InitString;

  processInitCommands;

        sleep 1;

        _vcl setvelocity [0,0,0];

      sleep 2;

  };

};

Part of weapon.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_vehicle = _this select 3

; Add the items to the _vehicle

clearWeaponCargo _vehicle

clearMagazineCargo _vehicle

_vehicle addWeaponCargo ["M16A2", 24]

_vehicle addWeaponCargo ["M16A2GL", 24]

_vehicle addWeaponCargo ["M4", 24]

Thanks in advance for any helpful input.

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  

×