Jump to content
Sign in to follow this  
Rexxenexx

Someone explain why this script does what it does Hosted vs. Dedicated served

Recommended Posts

I understand Client vs. Server but why does this spawn two? I keep reading it over and over and I don't see why it does what it does if the "local server" GL check is there or not. But it does poop out two. I have to test the mission commenting out that GL check then when I want to make it for a dedicated server I have to un-comment out that line, it's frustrating! Then the mission is messed for local Hosting!!

// *****************************************************
//** Operation Flashpoint Script File
//*****************************************************

//Original script by KaRRiLLioN modified by norrin then modified yet again by Rexxenexx 21st April 2008
//NOTE:*empty timer has been removed* so if the vehicle is empty for a long time it won't respawn.
//IMPORTANT: ADD A GAMELOGIC NAMED server
//to the mission to prevent multispawn

if (local server) exitWith {}; //otherwise two will respawn !local server respawned the vehicle without ammo

_vcl = _this;

_vclname = vehicleVarName _vcl;

//specify the respawn wait times destroyed vehicles in the following 2 lines
_respawndelay = 5;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_type = typeOf _vcl;
_unit = driver _vcl;

sleep 1;

_run = true;

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


while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do  
{
sleep 1;
};
while {canMove _vcl && count crew _vcl < 1} do
{
sleep 1;
};
while {canMove _vcl && {damage _x} forEach crew _vcl >= 1} do
{
sleep 1;
};
_delay = Time + _respawndelay;
while {!canMove _vcl && Time < _delay} do
{
sleep 1;
};


if ((count crew _vcl) < 1) then
{
    deleteVehicle _vcl;
   _vcl = _type createVehicle _pos;
   _vcl SetVehicleVarName _vclname;
   _vcl Call Compile Format ["%1=_this; PublicVariable ""%1""",_vclname];
   _vcl setvelocity [0,0,0];
   _vcl setdir _dir;
   _vcl setpos _pos;

   hint "Our MHQ has been damaged too much. A new one respawned.";

 };

sleep 2;

};

if (true) exitWith {};

If I put something in the init.sqf that checks if the server GL is local and that changes a variable that turns on and off that line you think that would work??

EDIT: That didn't work and is pointless anyway. Looking for something magical in the comref.... :D

EDIT2: isServer???? If that works I gotta stop drinking...

Edited by Rexxenexx

Share this post


Link to post
Share on other sites

You can use isServer instead of placing a game logic called server.

Also exitWith is only supposed to be used for exiting loops inside scripts not scripts themselves. It's quoted here that the behavior is undefined if you use it that way. Instead try doing this

if(isServer) then
{
   // PLACE CODE YOU WANT SERVER TO RUN
};

Regards,

Share this post


Link to post
Share on other sites
OMFG I just found isDedicated

... which nobody needs to respawn a vehicle :)

Use isServer to check locality and do only respawn vehicles where isServer is true. It's simple as that.

Xeno

Share this post


Link to post
Share on other sites

In the case of respawning vehicles, does anyone know how to retain the name of a vehicle when it respawns?

eg a heli called chopper dies, the respawn script is fired and a shiny new helicopter appears back at base - but how to you ensure that the new one retains the name of the original?

does the x_vehirespawn.sqf script from domination already feature name retention?

Share this post


Link to post
Share on other sites

TurokGMT, search a bit (try searching for vehicleVarName). This has been answered a few times already. One of the devs (I believe it was Gaia) posted a solution that BI uses in their official missions.

Share this post


Link to post
Share on other sites

Thanks guys for all the info. I'll try that isServer conditional encasing the code. I actually solved this a while back a diff way, then I messed it up two nights ago and I couldn't find my way back it was so bad. Hopefully this works in both ded/nonded servers. I'll report back this afternoon when I can work on it. The isDedicated is for something else I just didn't know it existed. :D

---------- Post added at 08:31 AM ---------- Previous post was at 07:18 AM ----------

For the script in the first post: I have a hint and an equip.sqf that loads the vehicle with weapons. Both don't work on a dedicated server.

Here's the code:

if (isServer) then {

  _vcl = _this;
  _vclname = vehicleVarName _vcl;
  _hasRespawned = 0;

  //specify the respawn wait times destroyed vehicles in the following 2 lines
  _respawndelay = 10;
  _dir = Getdir _vcl;
  _pos = Getpos _vcl;
  _type = typeOf _vcl;
  _unit = driver _vcl;

  while {!missionComplete} do {

     _vcl execVM "mhq_equip.sqf";
     if (_hasRespawned == 1) then { hint "Our MHQ has been damaged too much. A new one respawned."};

     _delay = Time + _respawndelay;

     while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do {sleep 5.0};
     while {canMove _vcl && count crew _vcl < 1} do {sleep 5.0};
     while {canMove _vcl && {damage _x} forEach crew _vcl >= 1} do {sleep 5.0};
     while {!canMove _vcl && Time < _delay} do {sleep 5.0};

     if ((count crew _vcl) < 1) then {

         deleteVehicle _vcl;
        _vcl = _type createVehicle _pos;
        _vcl SetVehicleVarName _vclname;
        _vcl Call Compile Format ["%1=_this; PublicVariable ""%1""",_vclname];
        _vcl setvelocity [0,0,0];
        _vcl setdir _dir;
        if (forwardFarpSpawn == 1) then {_pos=Getpos forwardFarpGL};
        _vcl setpos _pos;
        _hasRespawned = 1;

    };

  };

};

if (true) exitWith {};

So since it's not local the hint doesn't do anything on the ded server? How can I make that work? I think for the equip maybe I can just put the code back in-line...

Edited by Rexxenexx

Share this post


Link to post
Share on other sites

Fixed the hint problem with help from one of Tajins scripts. I added:

           _cone = createVehicle  ["RoadCone",[0,0,0], [], 0, "FLY"];
           _cone setVehicleInit "hint 'Our MHQ has been damaged too much. A new one respawned'";
           processInitCommands;
           deleteVehicle _cone;

Share this post


Link to post
Share on other sites

Anyone know why this spot doesn't add the ammo to the vehicle on a dedicated server?

if ((count crew _vcl) < 1) then
{
    deleteVehicle _vcl;
   _vcl = _type createVehicle _pos;
   _vcl SetVehicleVarName _vclname;
   _vcl Call Compile Format ["%1=_this; PublicVariable ""%1""",_vclname];
   _vcl setvelocity [0,0,0];
   _vcl setdir _dir;
   _vcl setpos _pos;

   _vcl addMagazineCargo ["10Rnd_127x99_M107",30];
   _vcl addMagazineCargo ["5Rnd_762x51_M24",30];
   _vcl addMagazineCargo ["15Rnd_9x19_M9",20];
   _vcl addWeaponCargo ["M107",2];
   _vcl addWeaponCargo ["M24",2];
   _vcl addMagazineCargo ["PipeBomb",8];

   player execVM "respawn_hint.sqf";

 };

Share this post


Link to post
Share on other sites

this is what I have now and it still doesn't spawn on a ded. server with ammo:

MHQ init:

_mhqHandler = this execVM "respawn_scripts\mhq_respawn.sqf";

mhq_respawn.sqf:

if (isServer) then {

  _vcl = _this;
  _vclname = vehicleVarName _vcl;

  call compile format["%1 execVM 'respawn_scripts\mhq_equip.sqf';",_vclname];

  //specify the respawn wait times destroyed vehicles in the following 2 lines
  _respawndelay = 10;
  _dir = Getdir _vcl;
  _pos = Getpos _vcl;
  _type = typeOf _vcl;
  _unit = driver _vcl;

  while {!missionComplete} do {

     _delay = Time + _respawndelay;

     while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do {sleep 5.0};
     while {canMove _vcl && count crew _vcl < 1} do {sleep 5.0};
     while {canMove _vcl && {damage _x} forEach crew _vcl >= 1} do {sleep 5.0};
     while {!canMove _vcl && Time < _delay} do {sleep 5.0};

     if ((count crew _vcl) < 1) then {

         deleteVehicle _vcl;
        _vcl = _type createVehicle _pos;
        _vcl SetVehicleVarName _vclname;

        Call Compile Format ["%1=_vcl; PublicVariable ""%1"";",_vclname];

        _vcl setvelocity [0,0,0];
        _vcl setdir _dir;
        if (forwardFarpSpawn == 1) then {_pos=Getpos forwardFarpGL};
        _vcl setpos _pos;

        //##########_mhqEquipHandle = _vcl execVM "respawn_scripts\mhq_equip.sqf";
        call compile format["%1 execVM 'respawn_scripts\mhq_equip.sqf';",_vclname];


        [] spawn {
           _cone = createVehicle  ["RoadCone",[0,0,0], [], 0, "FLY"];
           _cone setVehicleInit "hint 'Our MHQ has been damaged too much. A new one respawned'";
           processInitCommands;
           deleteVehicle _cone;
        };

     };

  };

};

if (true) exitWith {};

mhq_equip.sqf:

sleep 1.0;

private ["_vcl"];

_vcl = _this;

clearMagazineCargo _vcl;
clearWeaponCargo _vcl;

_vcl = _this;
_vcl addMagazineCargo ["30Rnd_556x45_StanagSD",30];
_vcl addMagazineCargo ["30Rnd_556x45_G36",30];
_vcl addMagazineCargo ["15Rnd_9x19_M9",20];
_vcl addWeaponCargo ["M8_compact",2];
_vcl addWeaponCargo ["M8_sharpshooter",2];
_vcl addMagazineCargo ["PipeBomb",10];
_vcl addAction ["Viewdistance +", "setViewDist.sqf", [500], -1,false, true, ""];
_vcl addAction ["Viewdistance -", "setViewDist.sqf", [-500], -1,false, true, ""];

sleep 1.0;

if (true) exitWith {};

Share this post


Link to post
Share on other sites

for the respawns

createvehiclelocal

should do the trick.

does it ?

equipment adds often are very timing sensitive to my experince

try increasing the delay before firing the equip commands or soemthing like

waitUntil{not(isNull player)};

waitUntil{time > 3};

maybe that helps

-

now,

did you stop drinking ? ;)

Share this post


Link to post
Share on other sites

lol. I haven't stopped this or drinking yet. :D

Nobody noticed I put "_vcl = _this;" twice. That doesn't do anything but waste space but blah!..

I don't see where createVehicleLocal would do anything but make it not spawn on a dedicated server?Unless I'm wrong?

I tried that waitUntil... -Wiper- everywhere and still on the server it doesn't have ammo. I tried firing waitUntil{!(isNull _vcl)}; under a call compile format so _vcl is pooped out in text -and not- and still it doesn't have ammo. I'm still trying. This is like the last thing troubling for the mission. Everything works perfect when I preview it, like I said, even all these things I've just tried! lol! I actually beat the game in 1hr 22min yesterday on the dedicated server but throughout the game the MHQ had no equipment. Eh I dunno this is for sure beyond me. :P

EDIT: The thing that ultra-sucks is that it's not throwing any errors that I can see in the RPT.

tried

call compile format["%1=_vcl; PublicVariable '%1';waitUntil{!(isNull %1)};%1 execVM 'respawn_scripts\mhq_equip.sqf';",_vclname];

feces

Edited by Rexxenexx

Share this post


Link to post
Share on other sites
lol. I haven't stopped this or drinking yet. :D

lol.

burdening the lever twice ? :p

yea, as for the createvehiclelocal your right. Its even what you do NOT want: quoting the wiki it says "Vehicle is not transferred through network in MP games" for it.

I just guessed it might help as I had problems with GameLogics using ceatevehicle without "local".

Tested CreateVehicle and it seems to work well, but not for men types anymore as it looks (in OF and A1 it spawned literally "empty" soldier units, lol).

Dunno what type of vehicles you pass through in _vcl.

Maybe thats is the problem you face ?

Dont notice any noticable "anomaly" in the code too...

EDIT:

the waituntil's I posted mere should make sense at mission start, but thats probably not the case here, is it ?

one thing that comes to mind is that freshly spawned vehicles need about 20 seconds to initialize and cant be used/entered within that timespan, still in Arma2

adding equipment to the cargo might be affected too by that initialization phase ?!

Edited by Wiper

Share this post


Link to post
Share on other sites

So far it's like this now:

if (isServer) then {

  sleep 1.0;

  _type = "HMMWV_Ambulance";
  _pos = getMarkerPos "coastal_farp";
  _vcl = _type createVehicle _pos;
  _vclname="mhq";
  _vcl SetVehicleVarName _vclname;
  _vcl Call Compile Format ["%1=_this ; PublicVariable ""%1""",_vclname];

HQ=[West,"HQ"];
HQ SideChat format["OUT %1",_vclname];

  waitUntil{!(isNull _vcl)};
  _vcl execVM "respawn_scripts\mhq_equip.sqf";
  waitUntil{(time > 3)};

  //specify the respawn wait times destroyed vehicles in the following 2 lines
  _respawndelay = 10;
  _dir = Getdir _vcl;
  _pos = Getpos _vcl;
  _type = typeOf _vcl;
  _unit = driver _vcl;

  while {!missionComplete} do {

     _delay = Time + _respawndelay;

     while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do {sleep 5.0};
     while {canMove _vcl && count crew _vcl < 1} do {sleep 5.0};
     while {canMove _vcl && {damage _x} forEach crew _vcl >= 1} do {sleep 5.0};
     while {!canMove _vcl && Time < _delay} do {sleep 5.0};

     if ((count crew _vcl) < 1) then {

         deleteVehicle _vcl;
        _vcl = _type createVehicle _pos;
        _vcl Call Compile Format ["%1=_this ; PublicVariable '%1'",_vclname];

        _vcl SetVehicleVarName _vclname;
        _vcl setvelocity [0,0,0];
        _vcl setdir _dir;
        if (forwardFarpSpawn == 1) then {_pos=Getpos forwardFarpGL};
        _vcl setpos _pos;
HQ SideChat format["IN %1",_vclname];
        waitUntil{!(isNull _vcl)};
        _vcl execVM "respawn_scripts\mhq_equip.sqf";
        waitUntil{(time > 3)};

        [] spawn {
           _cone = createVehicle  ["RoadCone",[0,0,0], [], 0, "FLY"];
           _cone setVehicleInit "hint 'Our MHQ has been damaged too much. A new one respawned'";
           processInitCommands;
           deleteVehicle _cone;
        };

     };

  };

};

if (true) exitWith {};

mhq_equip:

private ["_vcl"];

_vcl = _this;

waitUntil{!(isNull _vcl)};

removeAllItems _vcl;
_vcl addMagazineCargo ["30Rnd_556x45_StanagSD",30];
_vcl addMagazineCargo ["30Rnd_556x45_G36",30];
_vcl addMagazineCargo ["15Rnd_9x19_M9",20];
_vcl addWeaponCargo ["M8_compact",2];
_vcl addWeaponCargo ["M8_sharpshooter",2];
_vcl addMagazineCargo ["PipeBomb",10];
_vcl addAction ["Viewdistance +", "setViewDist.sqf", [500], -1,false, true, ""];
_vcl addAction ["Viewdistance -", "setViewDist.sqf", [-500], -1,false, true, ""];

sleep 3.0;

if (true) exitWith {};

I deleted the MHQ in the editor to let it spawn one at start and still it works in local host play but no ammo equip on dedicated server. :yay: <-needs to be shot!

I've tried everything I can think of. I'm gonna try scripting it to poop out an ammocrate with the goods. It probably won't pass the addAction on a dedicated server. :eek: I rared a good copy of this mission yesterday so I'm not scared of totally raping this code to see if anything works. At the least I'll learn more of better scripting for ArmAII. I guess...:confused: Hey I just had an idea! What if I made a script that equips the MHQ like this:

while {!missionComplete} do {

  waitUntil{!(isNull mhq)};

  removeAllItems mhq;
  mhq addMagazineCargo ["30Rnd_556x45_StanagSD",30];
  mhq addMagazineCargo ["30Rnd_556x45_G36",30];
  mhq addMagazineCargo ["15Rnd_9x19_M9",20];
  mhq addWeaponCargo ["M8_compact",2];
  mhq addWeaponCargo ["M8_sharpshooter",2];
  mhq addMagazineCargo ["PipeBomb",10];
  mhq addAction ["Viewdistance +", "setViewDist.sqf", [500], -1,false, true, ""];
  mhq addAction ["Viewdistance -", "setViewDist.sqf", [-500], -1,false, true, ""];

  sleep 30.0;

};

if (true) exitWith {};

And just fire it at the start! Not in the mhq's code! I'll try that...

---------- Post added at 06:58 AM ---------- Previous post was at 06:36 AM ----------

Wow...This is just stupid:

while {!missionComplete} do {

  waitUntil{!(isNull mhq)};

  removeAllItems mhq;
  removeAllWeapons mhq;
  {mhq removeMagazines "30Rnd_556x45_StanagSD"}forEach magazines mhq;
  {mhq removeMagazines "30Rnd_556x45_G36"}forEach magazines mhq;
  {mhq removeMagazines "15Rnd_9x19_M9"}forEach magazines mhq;
  {mhq removeMagazines "PipeBomb"}forEach magazines mhq;

  sleep 1.0;

  mhq addMagazineCargo ["30Rnd_556x45_StanagSD",30];
  mhq addMagazineCargo ["30Rnd_556x45_G36",30];
  mhq addMagazineCargo ["15Rnd_9x19_M9",20];
  mhq addWeaponCargo ["M8_compact",2];
  mhq addWeaponCargo ["M8_sharpshooter",2];
  mhq addMagazineCargo ["PipeBomb",10];

  sleep 3.0;

};

if (true) exitWith {};

It keeps loading the MHQ with ammo. Totally bypassing the remove statements.

OK I'm done with this 1997 game until Sunday. Can't stand straightforward code not working at all.

Share this post


Link to post
Share on other sites

You need to use clearWeaponCargo and clearMagazineCargo :thumbsup:

Share this post


Link to post
Share on other sites

None of those worked but I had another idea I HAD to try and it f'in works! :yay: ring ring ring ring ring ring ring...banana phooone!

mhq_respawn.sqf:

if (isServer) then {

  sleep 1.0;

  _vclname="mhq";
  _type = "HMMWV_Ambulance";
  _pos = getMarkerPos "coastal_farp";
  _vcl = _type createVehicle _pos;
  _vcl SetVehicleVarName _vclname;
  _vcl Call Compile Format ["%1=_this;PublicVariable '%1'",_vclname];
  _vcl setVehicleInit "null = this execVM 'respawn_scripts\mhq_equip.sqf'";
  processInitCommands;
  clearVehicleInit _vcl;

  //specify the respawn wait times destroyed vehicles in the following 2 lines
  _respawndelay = 10;
  _dir = Getdir _vcl;
  _pos = Getpos _vcl;
  _type = typeOf _vcl;
  _unit = driver _vcl;

  while {!missionComplete} do {

     _delay = Time + _respawndelay;

     while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do {sleep 5.0};
     while {canMove _vcl && count crew _vcl < 1} do {sleep 5.0};
     while {canMove _vcl && {damage _x} forEach crew _vcl >= 1} do {sleep 5.0};
     while {!canMove _vcl && Time < _delay} do {sleep 5.0};

     if ((count crew _vcl) < 1) then {

         deleteVehicle _vcl;
        _vcl = _type createVehicle _pos;
        _vcl Call Compile Format ["%1=_this ; PublicVariable '%1'",_vclname];
        _vcl SetVehicleVarName _vclname;
        _vcl setvelocity [0,0,0];
        _vcl setdir _dir;
        _vcl setVehicleInit "null = this execVM 'respawn_scripts\mhq_equip.sqf'";
        processInitCommands;
        clearVehicleInit _vcl;

        if (forwardFarpSpawn == 1) then {_pos=Getpos forwardFarpGL};
        _vcl setpos _pos;

        [] spawn {
           _cone = createVehicle  ["RoadCone",[0,0,0], [], 0, "FLY"];
           _cone setVehicleInit "hint 'Our MHQ has been damaged too much. A new one respawned'";
           processInitCommands;
           deleteVehicle _cone;
        };

     };

  };

};

if (true) exitWith {};

mhq_equip.sqf:

clearWeaponCargo _this;
clearMagazineCargo _this;

_this addMagazineCargo ["30Rnd_556x45_StanagSD",30];
_this addMagazineCargo ["30Rnd_556x45_G36",30];
_this addMagazineCargo ["15Rnd_9x19_M9",20];
_this addWeaponCargo ["M8_compact",2];
_this addWeaponCargo ["M8_sharpshooter",2];
_this addMagazineCargo ["PipeBomb",10];
_this addAction ["Viewdistance +", "setViewDist.sqf", [500], -1,false, true, ""];
_this addAction ["Viewdistance -", "setViewDist.sqf", [-500], -1,false, true, ""];

sleep 30.0;

if (true) exitWith {};

I'm gonna just upload the mission. I've had enough of it. :D If theirs any bugs then GFY!:coop:

j/k :D

I'll have to get to it WAAAY later. I'm done for a while editing. This time I really mean it. I want to play more now that I know how messed up it is. All I gotta say is do as much as you can IN the editor. That tends to always work properly.

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  

×