Jump to content
jmejay

Reference object variable between scripts - initServer and init

Recommended Posts

Hi all,


I want initServer.sqf to spawn a box for me with createVehicle.


I then want init.sqf to give this box addActions for each client.


Basically I don't know how to addAction to an object already spawned from a different script. 


Or even if the box exists in the world, var named box, how do I find this item in an execVM?


For example, if I do in initServer:



box = createVehicle ["B_supplyCrate_F", _pos, [], 0, "CAN_COLLIDE"];

How do I reference "box" in loadout.sqf which is called from init.sqf.


Or should I be looking at functions for this.


Basically, I want an MP enabled Ammobox which can give preset loadouts via addaction.


I've been looking into get/setVariable but maybe I'm on the wrong page to reference the object between scripts. 


Cheers guys!


Share this post


Link to post
Share on other sites

Problem here is the initServer.sqf gets executed after the init.sqf, so basically there is not way to access the box because it does not exist. Initialisation order .

 

Easiest way would be to put the spawn of the box into

if(isServer) then
{
// spawn box
};

box addAction ["Example","exec "example.sqf"];

both in the init.sqf

 

init.sqf is executed after initServer.sqf in multiplayer environment.

Share this post


Link to post
Share on other sites

 

Or should I be looking at functions for this.

 

 

Yes. Use BIS_FNC_MP or remoteExec for this. You can enable JIP execution. That will run the command/function for addon the Actions to the box on all already connected and future connecting clients.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Revo, I'll try that; btw - Init.sqf is run after initServer on MP.

 

I don't believe that code would work - maybe it would create a new box every time someone's init.sqf fires. 

 

I think I have the answer in publicVariable - i'll update later.

Share this post


Link to post
Share on other sites

initServer.sqf or other file/trigger on the server:

if(isServer) then {
 _box = "someType" createvehicle getpos someObj;
  [_box] remoteExec ["TAG_FNC_AddActions",0,true];
};

description.ext:

class CfgFunctions
{
	class TAG
	{
              class myCategory
              {
                  class AddActions {file = "AddActions.sqf";};
              };
	};
};

And finnaly the AddActions.sqf in your mission folder next to mission.sqm and description.ext:

_box = param[0,objNull];

if(!isNull _box) then {
    _box addAction ["Blah",{hint "Name hat kein BAS!";}];
};
  • Like 1

Share this post


Link to post
Share on other sites

If you're creating something on the server and want it accessible to clients, have to put the object into a namespace the clients can access, such as missionNamespace

 

basically:

// On the server
missionNamespace setVariable ['JMEJAY_box',(createVehicle ['B_supplyCrate_F',_pos,[],0,'CAN_COLLIDE']),TRUE];

then on the client in 'initPlayerLocal.sqf'

// on the client
waitUntil {(!isNil {missionNamespace getVariable 'JMEJAY_box'})};
_action = (missionNamespace getVariable 'JMEJAY_box') addAction ['My Action',{},[],50,true,true,'',''];

at least thats how I would go about it.

 

 

 

Initialization Order:

 

Functions Library


Initialization Order

When mission is starting, its components are initialized in the following order:

  1. Functions with recompile param set to 1 are recompiled
  2. Functions with preInit param set to 1 are called (client + server)
  3. Object Init Event Handlers are called
  4. Object initialization fields are called
  5. init.sqs is executed in singleplayer
  6. init.sqf is executed in singleplayer
  7. Persistent multiplayer functions are called (client only)
  8. Modules are initialized
  9. initServer.sqf is executed (server only)
  10. initPlayerLocal.sqf is executed
  11. initPlayerServer.sqf is executed (server only)
  12. Functions with postInit param set to 1 are called (client + server)
  13. "BIS_fnc_init" variable is set to true
  14. init.sqs is executed in multiplayer
  15. init.sqf is executed in multiplayer

 

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

×