Jump to content
Sign in to follow this  
greensha

What does BIS_fnc_spawn do?

Recommended Posts

I've been having the same problems. I don't have forum permissions to create new threads so I'm going to ask these questions here since they are somewhat related.

What does BIS_fnc_spawn do? I can't find an entry for it anywhere in the BI wiki (https://community.bistudio.com/wiki/BIS_fnc_spawn leads to a blank page).

Also, I've been trying to use the following code but my access to a server is limited so I can't fully test it. I also don't like putting code in my scripts that I don't fully understand and I am confused by a couple of things...

In the players init field:

null = [this] execVM "loadout.sqf"; 

In onPlayerRespawn.sqf:

//
// Respawn script for both sides
//

if (side player == east) then 
{
null = [player] execVM "loadout.sqf";

_repawnPosition = floor random 4;

switch _repawnPosition do 
{
	case 0: { player setPos ( spawnBuilding1 buildingPos 1); };
	case 1: { player setPos ( spawnBuilding1 buildingPos 2); };
	case 2: { player setPos ( spawnBuilding1 buildingPos 3); };
	case 3: { player setPos ( spawnBuilding1 buildingPos 4); };
};
}
else // if player is NATO
{
player setPos westRespawnPoint;
};

loadout.sqf:

waitUntil {!isNull player};       //to prevent MP / JIP issues

_unit = _this select 0;

//
// Remove uniform and equipment
//
removeHeadgear _unit;
removeGoggles _unit;
removeVest _unit;    
removeBackpack _unit;    
removeUniform _unit;   
removeAllWeapons _unit;    
removeAllAssignedItems _unit;
removeAllcontainers _unit;   


//
// Set player's clothes
//
_clothesArray = ["U_C_Poloshirt_tricolour", "U_C_Commoner1_1", "U_C_Poloshirt_blue", "U_C_Poloshirt_redwhite"];
_clothes = _clothesArray select floor random count _clothesArray;
sleep 1;
[[player, {_unit addUniform _clothes}], "BIS_fnc_spawn", true] call BIS_fnc_MP;

So my big question is in the last line of the loadout script, why can't it look like this:

[[_unit, {_unit addUniform _clothes}], "BIS_fnc_spawn", true] call BIS_fnc_MP;

Or in fact, do I even need to get the "_unit" variable from the select statement and can I use "player" instead? I'm pretty new to Arma 3 scripting, but I've spent several days scouring the forums and BI wiki and I'm still a little confused. I suspect that the answer to my questions is probably quite a bit more simple that I am making it.

Thanks!

Share this post


Link to post
Share on other sites
What does BIS_fnc_spawn do? I can't find an entry for it anywhere in the BI wiki (https://community.bistudio.com/wiki/BIS_fnc_spawn leads to a blank page).

I think it's just used as a tool for sending code (instead of a predefined function) through BIS_fnc_MP, since the latter doesn't normally support this.

First thing I noticed: you're initially executing loadout.sqf through the unit's init field. The init fields are executed by all players. In such a circumstance you shouldn't get a random item from an array, because everyone will get a different random result - and then at the end everyone runs BIS_fnc_MP and broadcasts their choice. Chaos! Madness! It needs a different solution.

Secondly, BIS_fnc_spawn almost certainly uses the parameters given in the first parameter, and you can't pass local variables into the code part itself. It should probably look like this:

[[_unit, _clothes], {(_this select 0) addUniform (_this select 1)}], "BIS_fnc_spawn", TRUE] call BIS_fnc_MP;

Or in fact, do I even need to get the "_unit" variable from the select statement and can I use "player" instead?

You can use "player" (as a parameter, not in the actual code) in the script you call from onPlayerRespawn, but if you use it in the one you call from the unit init, every player calls it as their own unit.

Also, I've been trying to use the following code but my access to a server is limited so I can't fully test it.

Just to be sure (sorry just in case), are you aware of arma3server.exe in the Arma 3 Steam directory? If you have access to the game itself, you can simply open that and then join through the LAN menu. Obviously it's not as good as testing with players, especially in this case, but in many instances it'll still give a much closer impression of how things will actually play out in MP.

Share this post


Link to post
Share on other sites
I think it's just used as a tool for sending code (instead of a predefined function) through BIS_fnc_MP, since the latter doesn't normally support this.

First thing I noticed: you're initially executing loadout.sqf through the unit's init field. The init fields are executed by all players. In such a circumstance you shouldn't get a random item from an array, because everyone will get a different random result - and then at the end everyone runs BIS_fnc_MP and broadcasts their choice. Chaos! Madness! It needs a different solution.

Thanks for the reply! The addUniform function is a local function so even though it's executed via the init field, it's only executed on the local machine. I need the BIS_fnc_MP command to make sure that everyone's uniform is sync'ed. Of course, I could be wrong about the way I'm doing this. For the purposes of the mission, it doesn't really matter if a player's uniform looks different to every other player, just as long as it's a civilian uniform. If you have different solution for getting one side clothed in civilian clothes, that would be very helpful.

Just to be sure (sorry just in case), are you aware of arma3server.exe in the Arma 3 Steam directory? If you have access to the game itself, you can simply open that and then join through the LAN menu. Obviously it's not as good as testing with players, especially in this case, but in many instances it'll still give a much closer impression of how things will actually play out in MP.

Is that the same as hosting a new session through the multiplayer menu? I seem to get similar behaviours when I do either one. The big problem, of course, is seeing what happens when other people join. Also, since the server and my machine are the same, I'm not sure if I'm seeing a different between functions that act globally and ones (like addUniform) that only act locally.

Thanks again for your help!

Share this post


Link to post
Share on other sites
Thanks for the reply! The addUniform function is a local function so even though it's executed via the init field, it's only executed on the local machine. I need the BIS_fnc_MP command to make sure that everyone's uniform is sync'ed. Of course, I could be wrong about the way I'm doing this. For the purposes of the mission, it doesn't really matter if a player's uniform looks different to every other player, just as long as it's a civilian uniform. If you have different solution for getting one side clothed in civilian clothes, that would be very helpful.

You're completely right trying to execute addUniform globally. Actually I came across this in the addUniform thread:

[[{}, _unit addUniform "Uniform Classname Here"], "BIS_fnc_spawn", true] call BIS_fnc_MP; //attention to the syntax here. This, and only this syntax worked for me, even with other resources showing differently

The syntax looks really weird, but apparently it works, so it'd be best to test both.

I'm actually a poor person to advise with loadouts, since I keep getting into problems with them, and every working system confuses me further. LEA, for example, calls the loadout only for the server and the local player playing the unit, while the addUniform thread example above has it not run on the server at all.

Something like the following could work could work. Leave the editor init line as it is, add player setVariable ["respawn_init", TRUE]; before the execVM line in onPlayerRespawn.sqf, and then try something like this for loadout.sqf:

// try to avoid JIP issues
waitUntil {!isNull player};

// Declare private variables (local to this scope)
private ["_clothesArray","_clothes","_unit","_respawn_init"];

_unit         = _this select 0;
_respawn_init = _unit getVariable ["respawn_init", FALSE]; 

// since the remove commands are global, it should be alright to run them only
// for the server and the player of the unit, right? ...right?
if (_unit == player OR isServer) then
{
// Remove uniform and equipment

removeAllContainers    _unit; // Removes uniform, vest, backpack 
removeAllWeapons       _unit;
removeAllAssignedItems _unit;
removeHeadgear         _unit;
removeGoggles          _unit;


// Set player's clothes (through the server, or through respawn)

if (isServer OR _respawn_init) then
{
               _clothesArray = ["U_C_Poloshirt_tricolour",
                                "U_C_Commoner1_1",
                                "U_C_Poloshirt_blue",
                                "U_C_Poloshirt_redwhite"];

	_clothes = _clothesArray call BIS_fnc_selectRandom; // does a function look simpler?

	[
		[_unit, _clothes],
		{(_this select 0) addUniform (_this select 1)}],
		"BIS_fnc_spawn", TRUE
	] call BIS_fnc_MP;		


	// Alternative way (comment/remove the above three lines if used):
	/*    Remove this line if below's in use

	switch (round (random 3) do
	{
		case 0: [[{}, _unit addUniform "U_C_Poloshirt_tricolour"], "BIS_fnc_spawn", TRUE] call BIS_fnc_MP;
		case 1: [[{}, _unit addUniform "U_C_Commoner1_1"],         "BIS_fnc_spawn", TRUE] call BIS_fnc_MP;
		case 2: [[{}, _unit addUniform "U_C_Poloshirt_blue"],      "BIS_fnc_spawn", TRUE] call BIS_fnc_MP;
		case 3: [[{}, _unit addUniform "U_C_Poloshirt_redwhite"],  "BIS_fnc_spawn", TRUE] call BIS_fnc_MP;		
	};
	*/ // Remove this line if above's in use
};
};

Is that the same as hosting a new session through the multiplayer menu?

It's not the same, since when hosting from the multiplayer menu, server == your client. On a dedicated, even if it's on the same machine, this isn't the case. On this issue it doesn't help as much, since you'll still need other players to make sure that the loadout is working, but for many other situations it'll be helpful.

Edited by Magirot
trying to make the code clearer and failing horribly

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  

×