Jump to content
Svartalfheim

Creating default units in editor

Recommended Posts

When i add an unit and then play the scenario, die and then respawn, the loadout that i created returns to default. is there any way to create a unit with my loadout or solving this thing?
i tried creating a custom composition but it didn't worked out for me.

  • Like 2

Share this post


Link to post
Share on other sites

I used the one posted here by @GEORGE FLOROS GR 

And after so much time I now discovered that it has to be in the initPlayerLocal.sqf !!!

Might have to change this for all our missions. Now going crazy 🤪

  • Like 2

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/27/2020 at 2:49 PM, Svartalfheim said:

die and then respawn, the loadout that i created returns to default.

 

On 3/27/2020 at 5:53 PM, JohnKalo said:

initPlayerLocal.sqf

 

Hello there Guys !

Welcome also @Svartalfheim to BI Forums !

 

It's good to take a look always here :

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

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

 

Since the certain code is about all the units , players and ai , you can add this in the init.sqf :

addMissionEventHandler ["EntityKilled", {
	params ["_unit", "_killer", "_instigator", "_useEffects"];
	
	if(isPlayer _unit)then{
		[_unit, [profileNamespace, "inventory_var"]] call BIS_fnc_saveInventory;
	}else{
		[_unit, [missionNamespace, "inventory_var"]] call BIS_fnc_saveInventory;
	};
}];

addMissionEventHandler ["EntityRespawned", {
	params ["_entity", "_corpse"];
	if(isPlayer _entity)then{
		if ( profileNamespace getVariable[ "bis_fnc_saveInventory_data", [] ] find "inventory_var" > -1 ) then {
			[_entity, [profileNamespace, "inventory_var"]] call BIS_fnc_loadInventory;
		};
	}else{
		[_entity, [missionNamespace, "inventory_var"]] call BIS_fnc_loadInventory;
	};
}];

 

Edited by GEORGE FLOROS GR
updated ( from Larrow's post )
  • Like 2

Share this post


Link to post
Share on other sites

But for init.sqf it says it applies for Single Player. The method I used so far worked only for host as it seems although the two files were execVM through the init.sqf.

 

execVM "Scripts\onPlayerKilled.sqf";
execVM "Scripts\onPlayerRespawn.sqf";

EDIT: Found it. The EventHandlers work for all. Thanks 👍

  • Like 2

Share this post


Link to post
Share on other sites

Update: Updated all my missions :thumb_down: The above method works although it does show an error at the editor in the beggining of the mission stating:

 

[BIS_fnc_loadInventory] Inventory "inventory_var" not found

Hope it is nothing cause I spent about an hour and a half updating all missions.

  • Like 2

Share this post


Link to post
Share on other sites
10 hours ago, JohnKalo said:

[BIS_fnc_loadInventory] Inventory "inventory_var" not found

 

NO idea !

  • Like 2

Share this post


Link to post
Share on other sites

Well since it works all good 👌

If anything happens at MP further testing we will check it again.

  • Like 2

Share this post


Link to post
Share on other sites
On 3/29/2020 at 1:29 PM, JohnKalo said:

[BIS_fnc_loadInventory] Inventory "inventory_var" not found

addMissionEventHandler ["EntityRespawned", {
	params ["_entity", "_corpse"];
	if(isPlayer _entity)then{
		if ( profileNamespace getVariable[ "bis_fnc_saveInventory_data", [] ] find "inventory_var" > -1 ) then {
			[_entity, [profileNamespace, "inventory_var"]] call BIS_fnc_loadInventory;
		};
	}else
	//snip

I'm guessing players are respawn on start, so the inventory var does not exist yet.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

@Larrow Thanks but is it ok if I leave it as it was? Because it did work one time that I tested it and I do have it in all missions now  :scratchchin:

Also does the above work for players and AI too? I suspect it does but just to be 200% sure.

 

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

×