jmejay 10 Posted September 10, 2015 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
R3vo 2535 Posted September 10, 2015 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
NeoArmageddon 926 Posted September 10, 2015 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. 1 Share this post Link to post Share on other sites
jmejay 10 Posted September 10, 2015 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
NeoArmageddon 926 Posted September 10, 2015 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!";}]; }; 1 Share this post Link to post Share on other sites
fn_Quiksilver 1523 Posted September 11, 2015 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 OrderWhen mission is starting, its components are initialized in the following order: Functions with recompile param set to 1 are recompiled Functions with preInit param set to 1 are called (client + server) Object Init Event Handlers are called Object initialization fields are called init.sqs is executed in singleplayer init.sqf is executed in singleplayer Persistent multiplayer functions are called (client only) Modules are initialized initServer.sqf is executed (server only) initPlayerLocal.sqf is executed initPlayerServer.sqf is executed (server only) Functions with postInit param set to 1 are called (client + server) "BIS_fnc_init" variable is set to true init.sqs is executed in multiplayer init.sqf is executed in multiplayer Share this post Link to post Share on other sites