Page 1 of 2 12 LastLast
Results 1 to 10 of 17

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

  1. #1

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

    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!!

    Code:
    // *****************************************************
    //** 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....

    EDIT2: isServer???? If that works I gotta stop drinking...
    Last edited by Rexxenexx; Jul 18 2009 at 16:32.

  2. #2
    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

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

  3. #3
    Gunnery Sergeant
    Join Date
    Jun 1 2002
    Location
    SoCal
    Posts
    550
    Author of the Thread
    OMFG I just found isDedicated


  4. #4
    Quote Originally Posted by Rexxenexx View Post
    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

  5. #5
    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?
    Operation Magpie for ARMA2!
    Filefront Mirror
    Armaholic Mirror

    Domination! TurokGMT Edition for ARMA (Current and Final Version v0.6) :
    Filefront Mirror
    Armaholic Mirror

  6. #6
    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.
    VBS2 Designer

    Quote Originally Posted by Armored_Sheep View Post
    I like to call Arma a sandbox game that works pretty much like LEGO - you buy it not just because you want to have a nice car from the main picture on its box, do you?

  7. #7
    Gunnery Sergeant
    Join Date
    Jun 1 2002
    Location
    SoCal
    Posts
    550
    Author of the Thread
    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.

    ---------- 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:
    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...
    Last edited by Rexxenexx; Jul 20 2009 at 16:00.

  8. #8
    Gunnery Sergeant
    Join Date
    Jun 1 2002
    Location
    SoCal
    Posts
    550
    Author of the Thread
    Fixed the hint problem with help from one of Tajins scripts. I added:

    Code:
                _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;

  9. #9
    Gunnery Sergeant
    Join Date
    Jun 1 2002
    Location
    SoCal
    Posts
    550
    Author of the Thread
    Anyone know why this spot doesn't add the ammo to the vehicle on a dedicated server?

    Code:
    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";
    
      };

  10. #10
    Gunnery Sergeant
    Join Date
    Jun 1 2002
    Location
    SoCal
    Posts
    550
    Author of the Thread
    this is what I have now and it still doesn't spawn on a ded. server with ammo:

    MHQ init:
    Code:
    _mhqHandler = this execVM "respawn_scripts\mhq_respawn.sqf";
    mhq_respawn.sqf:
    Code:
    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:
    Code:
    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 {};

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •