Jump to content
M1ke_SK

condition initPlayerLocal.sqf and initServer.sqf in init.sqf file

Recommended Posts

In my missions I dont like many files, so I am looking for alternative. Is this code in init.sqf alternative to initPlayerLocal.sqf and initServer.sqf correct? 

 

init.sqf

// initServer.sqf
if ((isServer) or (isDedicated)) then {

};

// initPlayerLocal.sqf
if(hasInterface) then {
    waitUntil {sleep 0.1; !isNull player};

};

 

Share this post


Link to post
Share on other sites


// initServer.sqf

if (isServer) then {

//run on dedicated server or player host

};

// initPlayerLocal.sqf

if(hasInterface) then {

    //run on all player clients incl. player host

    [] spawn {

        waitUntil {sleep 0.1; !isNull player};

    

    };

};

Share this post


Link to post
Share on other sites
// initServer.sqf

if (isServer) then {

//run on dedicated server or player host

};


// initPlayerLocal.sqf

if(hasInterface) then {

    //run on all player clients incl. player host

    [] spawn {
        waitUntil {sleep 0.1; !isNull player};
    
    };
};

or what Killzone Kid posted. link in name

 

Im always editing inits looking for better performance .

my understanding is if you use initserver.sqf then you don't need if isserver in a script and same with initPlayerLocal.sqf.

Share this post


Link to post
Share on other sites

or what Killzone Kid posted. link in name

Im always editing inits looking for better performance .

my understanding is if you use initserver.sqf then you don't need if isserver in a script and same with initPlayerLocal.sqf.

Your understanding is correct (those commands are essentially built into the backend of those files), from a performance standpoint, there may be slight differences, the true upside being you know the absolute locality of the code executing.

To tac onto what has already been presented by davidoss, the way he is checking the server ensures compatibility between SP and MP, as in SP the player is both a client and the server at the same time (at least in basic terms). Your original code would do the same, between SP and MP, but the isDedicated check is really just an unecessary conditional (again barely any difference in performance, just extra stuff to look at).

Where an isDedicated check would come in handy is when you want code in the init.sqf to only run on the HC (headless client), in which case you'll want:

if (!hasInterface && !isDedicated) then { call TAG_fnc_myHCFunction; };
Lots of the locality condtional commands are more for certainty of where and when code/functions are executing over general purpose usage. They are also good for function security, in the sense that I can make a function only executable on the server or only a client or only the HC, no matter who/what calls it. And with the CfgRemoteExec now in play, it makes that even more secure.

Anyways probably way more info than you probably wanted, since davidoss gave you a good short answer, but I can't go to sleep and saw the thread :). Also just noticed KKs note on that link covers most of what I just said, but it's typed anyhow lol.

Share this post


Link to post
Share on other sites

thanks, David and jshock .

sometimes I can read something over and over and not get a full understanding,

but reading it again when someone else writes it from a different perspective makes it 100%

easier to get a grip on it.

 

also, I like the pic jshock. I work in the hazmat field. 

Share this post


Link to post
Share on other sites
if(hasInterface) then {

    //run on all player clients incl. player host

    [] spawn {
        waitUntil {sleep 0.1; !isNull player};

        if(local player) then {
            // here is initPlayerLocal.sqf alternative ???
        };

    };
};

so I add condition "local" to get "initPlayerLocal.sqf" inside init.sqf ?

Share this post


Link to post
Share on other sites

for what? you want to check if local player is local to it self?

 

I call function in initPlayerLocal.sqf

[player] call MY_fnc_myStuff;

but I want to call it for player locally in init.sqf

Share this post


Link to post
Share on other sites

(hasInterface) check is enough for that. Only player has interface and variable  "player" are local to each player

Share this post


Link to post
Share on other sites

(hasInterface) check is enough for that. Only player has interface and variable  "player" are local to each player

if(hasInterface) then {

    //run on all player clients incl. player host

    [] spawn {
        waitUntil {sleep 0.1; !isNull player};
        //this code will executed locally when player joins mission ?
    };
};

Share this post


Link to post
Share on other sites
if(hasInterface) then {

    //run on all player clients incl. player host

    [] spawn {
        waitUntil {sleep 0.1; !isNull player};
        //this code will executed locally when player joins mission ?
    };
};

To the comment after waitUntil, yes.

Share this post


Link to post
Share on other sites

It should do.

 

You're asking if you want to use init.sqf to do "alternative to initPlayerLocal.sqf and initServer.sqf", and that page tells you it's not the same because it's executed in a different order.

 

If it works, then fair enough, but it's not like for like.

Share this post


Link to post
Share on other sites

what they are saying is : and yeah credits to (fn_Q Das,Jay,David ).

 

if you use initserver.sqf you don't need if (isServer) then {

 

if you use initPlayerlocal.sqf you don't need  waitUntil { !isNil {player} };

 

 BUT if you DO use just init.sqf then you need to use things like

 

waitUntil { !isNil {player} };

waitUntil { player == player };

if(isServer) then {

if (hasInterface) then {

if (isDedicated) then {

 

so in the long run you can do either both will work the same

but my opinion is initserver.sqf and initPlayerlocal.sqf it simplfys things.

 

not to complicate anything but you can load a script local 

and within the script itself can be changed to server/dedicated and what ever else.

 

ie: in my init.sqf 

 

if (!isDedicated) then
 {
 waitUntil {
 !isNull player && isPlayer player
 };
 sidePlayer = side player;
 };




some execvm.sqf
some execvm.sqf
some execvm.sqf


[] call compile preprocessfile "Functions\fn_Init_Brit.sqf"; //<------  inside the script will add if (isServer) then {
 
JNA_Fnc_Init_Brit =


 {
_Unit = param [0, objNull, [objNull]];


 [_Unit,true] call JNA_Fnc_RedressBrit;


_Unit addEventHandler ['Respawn', {[_this select 0] call JNA_Fnc_RedressBrit}];


  0 = _Unit execVM 'SA\functions\main\fn_remNvAddLight.sqf';


 _Unit addEventHandler ['Respawn',{_this select 0 execVM 'SA\functions\main\fn_remNvAddLight.sqf'}];


 _Unit addEventHandler ['Killed',{_this spawn fnc_pwrotate;}];//spawn


 _Unit addEventHandler ["Hit",{_this spawn fnc_bloodbath;}];//spawn


 };
 // Enable Loadouts


//    {if (_x IsKindof 'Man' && faction _x isEqualTo 'BLU_CTRG_F') //Tanoa


    {if (_x IsKindof 'Man' && faction _x isEqualTo 'BLU_G_F') //Altis/Chernaraus/Stratis


        then{
              if (isServer) then {
                [_x] spawn JNA_Fnc_Init_Brit;


            };


//    } foreach _myGroup;// All Units in your group.
       };
    } foreach allunits;// All Blufor Units

I hope this helps ...

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

×