Comrades in Arms Discussion Board

Full Version: Scripts do not work for Dedicated Server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I'm trying myself on a mission which works ok for SP and MP on non-dedicated servers. When playing on dedicated server some scripts don't work as intended though.

1) The players start inside an aircraft. I add the following script with addAction to allow a HALO jump
Code:
_requestingUnit = _this select 1;

_requestingUnit action [ "eject", vehicle _requestingUnit];
sleep 0.1;
_requestingUnit spawn bis_fnc_halo;
sleep 0.1;
_requestingUnit setvelocity [0,120*0.8,0];
_requestingUnit setdir 0;

This works ONLY with those sleeps. Whereas in SP/MP-non-dedicated it also works without the sleeps. Now I'm confused on the one hand because I do not know why I need those and worried on the other hand because I don't know if other (slower) dedicated server might need longer sleeps.
I would be grateful for any insight in that.

2) It is also possible that there are some AIs in the slots. Since they are stupid and would never reach their destination if I would let them HALO I place them near the landing area

Code:
if(isServer) then
{
    {
        if(!(isPlayer _x)) then
        {
            // stupid AI drifts off several kms if not done
            _x addEventHandler ["HandleDamage", {false}];
            unassignVehicle _x;
            _xChute = createVehicle ["Parachute_US_EP1", [(getMarkerPos "mrkrInsertion" select 0), (getMarkerPos "mrkrInsertion" select 1) , 50], [], 0, "FLY"];
            _xChute setPos [(getPos _xChute select 0), (getPos _xChute select 1),  50];
            _x setPos [(getPos _xChute select 0), (getPos _xChute select 1),  50];
            _x moveInDriver _xChute;
        }
    } forEach units playerGroup;
}


This does work for SP/MP-non-dedicated but not for dedicated server. The parachutes are created, but the AIs just drop out of the aircraft and fall to death.

Thanks for any help on that
Behemeth
OK for the second problem:

1) for whatever reason I need to execute setPos twice
2) moveInDriver has to be executed local to unit

this results in the following working but ugly code:
Code:
// remove AIs from the plane when reaching the jump zone
// since they drift away severel kms if I let them jump themselves
// store them temporary on 0,0,0
// for whatever reason I need to execute setPos twice to work
if(isServer) then
{
    {
        if(!(isPlayer _x)) then
        {
            _x addEventHandler ["HandleDamage", {false}];
            sleep 0.5;
            unassignVehicle _x;
            sleep 0.5;
            _x setPos [0,0,0];
            sleep 0.5;
            _x setPos [0,0,0];
            sleep 0.5;
        }
    } forEach units playerGroup;
    sleep 10;
    deleteVehicle carrier;
};

// wait if any member of the group who is a player is near ground
waitUntil
{
    sleep 0.1;
    (    ((isPlayer player1) && ((getPosATL player1 select 2) < 25))
    ||    ((isPlayer player2) && ((getPosATL player2 select 2) < 25))
    ||    ((isPlayer player3) && ((getPosATL player3 select 2) < 25))
    ||    ((isPlayer player4) && ((getPosATL player4 select 2) < 25)))
};


_scatterHeight = -20;
_randomSpread = 100;
{
    if(!(isPlayer _x)) then
    {
        if(local _x) then
        {
            _xChute = createVehicle ["Parachute_US_EP1", [(getMarkerPos "mrkrInsertion" select 0) + (random _randomSpread) - _randomSpread/2, (getMarkerPos "mrkrInsertion" select 1) + (random _randomSpread) - _randomSpread/2, 50 - _scatterHeight], [], 0, "FLY"];
            _xChute setPos [(getPos _xChute select 0), (getPos _xChute select 1),  50 - _scatterHeight];
            _xChute setDir (random 360);
            _x setPos [(getPos _xChute select 0), (getPos _xChute select 1),  (getPos _xChute select 2)];
            sleep 0.5;
            _x moveInDriver _xChute;
            _scatterHeight = _scatterHeight + 10;
        }
        else
        {
            sleep 0.5;
        };
    };
} forEach units playerGroup;

Any suggestion on how to make the code nicer would be greatly appreciated
As well as an answer regarding the sleep issue

Quote: 2) It is also possible that there are some AIs in the slots. Since they are stupid and would never reach their destination if I would let them HALO I place them near the landing area


Are the AI on their own or in the same group as the player?


Edit: Nevermind, you found a solution.


As for
Quote:[size=78%]Any suggestion on how to make the code nicer would be greatly appreciated[/size]


Welcome to Arma scripting. There's no such thing as nice code here.
Whenever you work with player objects, as you do with your addAction and such, you need to make sure the variable is assigned the proper value when in a dedicated environment. Also some commands in ArmA can only be used when the game is running (time > 0).


So to fix future problem 1's, add this to the top of the script:
waitUntil { !(isNull player) };
waitUntil { time > 0 };


You really should read up on MP scripting and JIP on the biki if you want scripts to work in a dedi env.




For problem 2, like wolf said, welcome to ArmA scripting. When I create stuff I usually run stuff line by line in my debugger to see what works and what doesn't in that situation, and all the stuff that works gets pasted in a file. It's not very common that you can just script an entire file without doublechecking the effects of every line of code in a debugger.