Jump to content
Sign in to follow this  
blasturbator

"function does not exist" issue with BIS_fnc_MP

Recommended Posts

I'm currently having trouble implementing an addAction using BIS_fnc_mp

Upon loading the game a function created in the init.sqf apparently "does not exist"

the line in init.sqf:

fnc_create_crateMHQ = compileFinal preProcessFileLineNumbers "Scripts\mhq\fnc_create_crateMHQ.sqf";

fnc_create_crateMHQ.sqf:

if isServer exitWith {}; 
if (!(isNull mhqcrate1)) then {
		mhqcrate1 addAction["<t color='#ff1111'>NATO Gear Crate</t>", VASopen];
		mhqcrate2 addAction["<t color='#ff1111'>NATO Gear Crate</t>", VASopen];
		mhqcrate3 addAction["<t color='#ff1111'>NATO Gear Crate</t>", VASopen];
		mhqcrate4 addAction["<t color='#ff1111'>NATO Gear Crate</t>", VASopen];
	};
}; 

line in the vehicle init:

nul = [[this], 'fnc_create_crateMHQ', true, true] call BIS_fnc_MP;

What i think is happening is the vehicle init is being called before init.sqf can create the function 'fnc_create_crateMHQ'. Can anyone help me with this?

Share this post


Link to post
Share on other sites

technically it is true, the init.sqf in a multiplayer is actually loaded a long way after unit initialization from editor objects.

from https://community.bistudio.com/wiki/Functions_Library_(Arma_3)

[b]Initialization Order[/b]

[color=#000000][font=sans-serif]When mission is starting, its components are initialized in the following order:[/font][/color]

[list=1]
[*]Functions with [i]recompile[/i] param set to 1 are recompiled
[*]Functions with [i]preInit[/i] param set to 1 are called
[*]Object [url="https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Init"][i]Init[/i] Event Handlers[/url] are called
[*]Object initialization fields are called
[*][url="https://community.bistudio.com/wiki/Event_Scripts"][i]init.sqs[/i][/url] is executed in singleplayer
[*][url="https://community.bistudio.com/wiki/Event_Scripts"][i]init.sqf[/i][/url] is executed in singleplayer
[*]Persistent [url="https://community.bistudio.com/wiki/Functions_Library_(Arma_3)#Multiplayer"]multiplayer functions[/url] are called (client only)
[*][url="https://community.bistudio.com/wiki/Arma_3_Modules"]Modules[/url] are initialized
[*][url="https://community.bistudio.com/wiki/Event_Scripts"][i]initServer.sqf[/i][/url] is executed (server only)
[*][url="https://community.bistudio.com/wiki/Event_Scripts"][i]initPlayerLocal.sqf[/i][/url] is executed
[*][url="https://community.bistudio.com/wiki/Event_Scripts"][i]initPlayerServer.sqf[/i][/url] is executed (server only)
[*]Functions with [i]postInit[/i] param set to 1 are called
[*][i]BIS_fnc_init" variable is set to true[/i]
[*][url="https://community.bistudio.com/wiki/Event_Scripts"][i]init.sqs[/i][/url] is executed in multiplayer
[*][url="https://community.bistudio.com/wiki/Event_Scripts"][i]init.sqf[/i][/url] is executed in multiplayer
[/list]

You could put a trigger in the editor set to condition = true then put your code in the activation on run once.

in the vehicle init have a time>5 delay before running the bis_fnc_mp

Edited by KevsnoTrev

Share this post


Link to post
Share on other sites

Maybe it's then easier to simply declare it in the description.ext and only change BIS_fnc_MP call to:

nul = [[this], 'Blasturbator_fnc_create_crateMHQ', true, true] call BIS_fnc_MP; 

add to description.ext:

class CfgFunctions
{
class Blasturbator
{
	class dontKnow
	{
		class create_crateMHQ {file = "Scripts\mhq\fnc_create_crateMHQ.sqf"; recompile = 1;};
	};
};
};

greetings Na_Palm

Share this post


Link to post
Share on other sites

Well thanks for the replies guys, but i managed to fix the problem by putting what was in the vehicle init later on in a script activated by an action on the vehicle, which i realised i needed to do anyway because the function adds actions to vehicles spawned by said script.

But there is a new problem that i could use your help with, the actions only show up for the person who activated the script to spawn the vehicles :/ i was using BIS_fnc_mp to prevent this but it clearly does not seem to have worked.

None of the OP code has changed except the vehicle init which was moved into a script and had a parameter changed

nul = [[mhq], 'fnc_create_crateMHQ', true, true] call BIS_fnc_MP;

To explain this more clearly, a script on the vehicle "mhq" spawns four crates (mhqcrate1~4) and then runs the function 'fnc_create_crateMHQ' to provide addActions for the four crates. However only the person activating the script can see the addActions despite the use of BIS_fnc_MP.

edit: while i'm here, would (!colCheck) mean colCheck = false if colCheck was a boolean?

edit: I am testing this on a dedi server using two PCs.

Edited by Blasturbator

Share this post


Link to post
Share on other sites
Well thanks for the replies guys, but i managed to fix the problem by putting what was in the vehicle init later on in a script activated by an action on the vehicle, which i realised i needed to do anyway because the function adds actions to vehicles spawned by said script.

But there is a new problem that i could use your help with, the actions only show up for the person who activated the script to spawn the vehicles :/ i was using BIS_fnc_mp to prevent this but it clearly does not seem to have worked.

None of the OP code has changed except the vehicle init which was moved into a script and had a parameter changed

nul = [[mhq], 'fnc_create_crateMHQ', true, true] call BIS_fnc_MP;

To explain this more clearly, a script on the vehicle "mhq" spawns four crates (mhqcrate1~4) and then runs the function 'fnc_create_crateMHQ' to provide addActions for the four crates. However only the person activating the script can see the addActions despite the use of BIS_fnc_MP.

Think you have a slight misconception of BIS_fnc_MP and how it works.

The 4 crate names, (mhqcrate1~4), are local to the machine that created them, although the crates now exists on all machines.

What you have to do is change the BIS_fnc_MP call to:

nul = [[mhqcrate1, mhqcrate2, mhqcrate3, mhqcrate4], 'fnc_create_crateMHQ', true, true] call BIS_fnc_MP;

and then change fnc_create_crateMHQ.sqf:

if isServer exitWith {};
{ 
_x addAction["<t color='#ff1111'>NATO Gear Crate</t>", VASopen]; 
}forEach _this;

That way you tell the script on the other clients which objects to use.

Global variables are local per machine, too.

edit: while i'm here, would (!colCheck) mean colCheck = false if colCheck was a boolean?

(!colCheck) would mean colCheck == false as it is an comparison and == don't works for booleans.

greetings Na_Palm

Share this post


Link to post
Share on other sites

Thanks Na_Palm, coming to the rescue as usual :) Tbh i've learnt most of my scripting knowledge by reverse engineering other peoples scripts so i don't really "understand" any of it xD mostly i just know cause and effect.

The fix works great on dedi. I have another question though because I don't feel like it's worthy of a seperate thread as the issue is somewhat similar. Do vehicles spawned by createVehicle (i.e. an ATV) require some sort of MP function as well? Because my mhq spawns two of those as well as the crates and for some reason only the host client can't drive them, the host can get in but can't start the engine :/

Share this post


Link to post
Share on other sites

Hover your mouse cursor over the "G" in the upper left hand corner of this linked page below and read the description that appears:

https://community.bistudio.com/wiki/createVehicle

G (and L) symbols tell you about locality. G commands mean that they have Global effect. L commands mean they are Local to the client or server process that executed the code.

That said, there appear to be some locality issues (bugs) in the current ARMA 3 release. So don't be surprised to find G commands not quite working as expected.

Edited by Jacmac

Share this post


Link to post
Share on other sites

The createVehicle command should be global then, all the more reason for me to be concerned as to why i can't drive them but everyone else can. Would this be one of those bugs you mentioned?

Share this post


Link to post
Share on other sites

there are 3 createVehicle commands.

createVehicle

createVehicle_array

createVehicleLocal

The first is mostly an leftover, for compatibility with "old" missions.

For almost all chases, i would use the second one, createVehicle_array.

The third can be handy, in some cases, if you want an object only to spawn locally. Used it only once for an check in my "Lootspawner" scripts.

createVehicle_array has also no locality issues as far as i know, on stable branch. Is it really the creation thats bugged on your host client or maybe an other function you use afterwards on the object clientside?

Maybe this could help, if it only occurs on the host client.

exchange

if isServer exitWith {};

with

if (isServer && !hasInterface) exitWith {};

greetings Na_Palm

Share this post


Link to post
Share on other sites

Hmm i'm not sure how i'd implement that into the script, here's what i've got:

if (isDedicated) exitWith {};

_veh = _this select 0;
_man = _this select 1;
_mhq = mhq;

_option = (_this select 3) select 0;

if (_man != player) exitWith {};

//Deploy
if (_option == "Deploy") exitWith {

   // Exit if in vehicle
   if (vehicle _man != player) then {
       hint "You must dissembark before you can perform this action.";
   } else {

       _man playMove "AinvPknlMstpSlayWrflDnon_medic";
	_mhq allowDamage false;        
	sleep 5;

	"respawn_west1" setMarkerPos getPos mhq;

       vehCamo = "CamoNet_BLUFOR_big_F" createVehicle [0,0,0];
	vehcamo allowDamage false;	
	vehBag1 = "Land_BagFence_Round_F" createvehicle [0,0,0];
	vehBag2 = "Land_BagFence_Long_F" createvehicle [0,0,0];
	vehBag3 = "Land_BagFence_Round_F" createvehicle [0,0,0];
	vehBag4 = "Land_BagFence_Round_F" createvehicle [0,0,0];
	vehBag5 = "Land_BagFence_Long_F" createvehicle [0,0,0];
	vehBag6 = "Land_BagFence_Round_F" createvehicle [0,0,0];	

	mhqatv1 = "B_Quadbike_01_F" createVehicle [0,0,0];			//The ATV spawns
	mhqatv2 = "B_Quadbike_01_F" createVehicle [0,0,0];
	mhqatv1 allowDamage false;									//part of the fix detailed below
	mhqatv2 allowDamage false;									// v   v   v   v   v   v   v   v

	mhqcrate1 = "B_supplyCrate_F" createVehicle [0,0,0];
	mhqcrate2 = "B_supplyCrate_F" createVehicle [0,0,0];
	mhqcrate3 = "B_supplyCrate_F" createVehicle [0,0,0];
	mhqcrate4 = "B_supplyCrate_F" createVehicle [0,0,0];
	mhqcrate1 allowDamage false;
	mhqcrate2 allowDamage false;
	mhqcrate3 allowDamage false;
	mhqcrate4 allowDamage false;

       vehCamo setDir ((direction _veh) +0);
       vehCamo setPos (_veh modelToWorld [0,0,((position _veh) select 2)-2.0]);		
       vehBag1 setDir ((direction _veh) +50);
       vehBag1 setPos (_veh modelToWorld [-4,-4,((position _veh) select 2)-2.0]);
       vehBag2 setDir ((direction _veh) +90);
       vehBag2 setPos (_veh modelToWorld [-4.6,0,((position _veh) select 2)-2.0]);
       vehBag3 setDir ((direction _veh) +130);
       vehBag3 setPos (_veh modelToWorld [-4,4,((position _veh) select 2)-2.0]);
       vehBag4 setDir ((direction _veh) +230);
       vehBag4 setPos (_veh modelToWorld [4,4,((position _veh) select 2)-2.0]);
       vehBag5 setDir ((direction _veh) +270);
       vehBag5 setPos (_veh modelToWorld [4.6,0,((position _veh) select 2)-2.0]);
       vehBag6 setDir ((direction _veh) +310);
       vehBag6 setPos (_veh modelToWorld [4,-4,((position _veh) select 2)-2.0]);  

       //ATV setDir/setPos
       mhqatv1 setDir ((direction _veh) +180);
       mhqatv1 setPos (_veh modelToWorld [1.5,-9,((position _veh) select 2)-1.5]);
       mhqatv2 setDir ((direction _veh) +180);
       mhqatv2 setPos (_veh modelToWorld [-1.5,-9,((position _veh) select 2)-1.5]);	

	mhqcrate1 setDir ((direction _veh) +90);
       mhqcrate1 setPos (_veh modelToWorld [-1.8,-2,((position _veh) select 2)-2.0]);
	mhqcrate2 setDir ((direction _veh) +90);
       mhqcrate2 setPos (_veh modelToWorld [-1.8,0,((position _veh) select 2)-2.0]);
	mhqcrate3 setDir ((direction _veh) +90);
       mhqcrate3 setPos (_veh modelToWorld [1.9,-2,((position _veh) select 2)-2.0]);
	mhqcrate4 setDir ((direction _veh) +90);
       mhqcrate4 setPos (_veh modelToWorld [1.9,0,((position _veh) select 2)-2.0]);

	//fill crates
	nul = [[mhqcrate1, mhqcrate2, mhqcrate3, mhqcrate4], 'fnc_create_crateMHQ', true, true] call BIS_fnc_MP;  

       // Set variable for vehicle
       _veh setVariable ["CamoDeployed", true, true];

	//these lines are the fix for the exploding ATVs on some terrain.
	mhqatv1 setDamage 0;			
	mhqatv2 setDamage 0;
	sleep 5;
	mhqatv1 allowDamage true;
	mhqatv2 allowDamage true;

   };
};

// Stow
if (_option == "Stow") exitWith {

   // Exit if in vehicle
   if (vehicle _man != player) then {
       hint "You must dissembark before you can perform this action.";
   } else {

       _Net = nearestObject [_veh, "CamoNet_BLUFOR_big_F"];
	_Net setDamage 1;

       _man playMove "AinvPknlMstpSlayWrflDnon_medic";
       sleep 5; 

	{ deleteVehicle _x; } forEach nearestObjects [getpos player,["CamoNet_BLUFOR_big_F"],15];
	{ deleteVehicle _x; } forEach nearestObjects [getpos player,["Land_BagFence_Round_F"],15];
	{ deleteVehicle _x; } forEach nearestObjects [getpos player,["Land_BagFence_Long_F"],15];
	{ deleteVehicle _x; } forEach nearestObjects [getpos player,["B_Quadbike_01_F"],15];
	{ deleteVehicle _x; } forEach nearestObjects [getpos player,["B_supplyCrate_F"],15];

	"respawn_west1" setMarkerPos getMarkerPos "base_foxtrot";

	_mhq allowDamage true;

       // Set variable for vehicle
       _veh setVariable ["CamoDeployed", false, true];
   };
};

Edit: I think i may have solved the problem by doing what you recommended and using createVehicle arrays, the positions are slightly off but i can adjust that. Testing on dedi now.

Edit: Yeah it's working now, thanks for your help gents. I'll use the arrays in the future :)

Edited by Blasturbator
Solved

Share this post


Link to post
Share on other sites
The createVehicle command should be global then, all the more reason for me to be concerned as to why i can't drive them but everyone else can. Would this be one of those bugs you mentioned?

createVehicle should work just fine and if your client executes code that creates a vehicle and you are the only one that can not drive it in MP, then I would say that it is quite possibly another locality bug or an extension of the same bugs in locality that are present now. The only way you should get locked out of driving a vehicle is if the vehicle init code executed something that checked for you and kept you out. Otherwise, everyone should be able to drive it.

Share this post


Link to post
Share on other sites

edit line 1 to:

if (isServer && !hasInterface) exitWith {};

if you further have the bug on host client, only.

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
Sign in to follow this  

×