Jump to content

Recommended Posts

Hello, community! I am creating a MP mission, but I want to use a script for saving my proffered loadout. For example, when I get killed, I need to spawn with the same gear. I did a little research last night and I found a script that works for me only. I haven't tested it with friends, but it doesn't work for bots. There it is:

 

in init.sqf

// Set Units current Loadout     Fnc_Set_Loadout =     {     _unit = _this select 0;     _unit setVariable ["Saved_Loadout",getUnitLoadout _unit];     }; // Get Units current Loadout     Fnc_Get_Loadout =     {     _unit = _this select 0;     _unit setUnitLoadout (_unit getVariable ["Saved_Loadout",[]]);     };

 

in initPlayerLocal.sqf

player addEventhandler ["Killed",  {_this spawn Fnc_Set_Loadout}]; player addEventHandler ["Respawn", {_this spawn Fnc_Get_Loadout}];

 

Would it work for other players when they use the playable units or not? If not, what could be done?

Thanks in advance and cheers!

Share this post


Link to post
Share on other sites
Just now, black_hawk_mw2_87 said:

Hello, community! I am creating a MP mission, but I want to use a script for saving my proffered loadout. For example, when I get killed, I need to spawn with the same gear. I did a little research last night and I found a script that works for me only. I haven't tested it with friends, but it doesn't work for bots. There it is:

 

in init.sqf

// Set Units current Loadout     Fnc_Set_Loadout =     {     _unit = _this select 0;     _unit setVariable ["Saved_Loadout",getUnitLoadout _unit];     }; // Get Units current Loadout     Fnc_Get_Loadout =     {     _unit = _this select 0;     _unit setUnitLoadout (_unit getVariable ["Saved_Loadout",[]]);     };

 

in initPlayerLocal.sqf

player addEventhandler ["Killed",  {_this spawn Fnc_Set_Loadout}]; player addEventHandler ["Respawn", {_this spawn Fnc_Get_Loadout}];

 

Would it work for other players when they use the playable units or not? If not, what could be done?

Thanks in advance and cheers!

This is where I found the script:

 

Share this post


Link to post
Share on other sites

Hello there black_hawk_mw2_87 !

 

add these two .sqf in your mission :

 

( only for players )

 

onPlayerKilled.sqf

[player, [missionNamespace, "inventory_var"]] call BIS_fnc_saveInventory;

onPlayerRespawn.sqf

[player, [missionNamespace, "inventory_var"]] call BIS_fnc_loadInventory;

 

  • Like 3

Share this post


Link to post
Share on other sites
1 minute ago, GEORGE FLOROS GR said:

Hello there black_hawk_mw2_87 !

 

add these two .sqf in your mission :

 

onPlayerKilled.sqf


[player, [missionNamespace, "inventory_var"]] call BIS_fnc_saveInventory;

onPlayerRespawn.sqf


[player, [missionNamespace, "inventory_var"]] call BIS_fnc_loadInventory;

 

Thanks a lot. I've already tried with this. And with several other possible ways. For example with initPlayerLocal.sqf. But all I get is the pre-dead inventory and loadout. I even managed to get the custom loadout I choose from the virtual arsenal AFTER death, BUT with the current amount of mags/ammo/grenades etc. before I got killed. What I want is to get the same custom loadout, BUT whit replenished ammo etc.

Share this post


Link to post
Share on other sites
1 minute ago, black_hawk_mw2_87 said:

What I want is to get the same custom loadout, BUT whit replenished ammo etc.

 

Just to understand more , you want to be in the mission and get in a virtual ammobox ( arsenal ) and load your loadout and when you die to have the loaded loadout from the arsenal back , right ?

Share this post


Link to post
Share on other sites
1 minute ago, GEORGE FLOROS GR said:

 

Just to understand more , you want to be in the mission and get in a virtual ammobox ( arsenal ) and load your loadout and when you die to have the loaded loadout from the arsenal back , right ?

I have a script for a virtual arsenal that works in MP. I have saved several custom loadouts there. When I load any of them and respawn, I get the first loadout on mission's start. NOT the custom one I loaded from the arsenal. I want the custom one, and without ammo loses, if there are some while fighting.

Share this post


Link to post
Share on other sites

If yes :

 

On 2/28/2018 at 11:13 PM, davidoss said:

initPlayerLocal.sqf


[missionNamespace, "arsenalClosed", {
	player setVariable ["Saved_Loadout",getUnitLoadout player];
	hint "Selected gear saved!"
	}] call BIS_fnc_addScriptedEventHandler;
player addEventHandler ["Respawn",{

		0 = [_this select 0] spawn {
		
			params [["_player",objNull,[objNull]]];
				waitUntil {sleep .2; alive _player};
				_player setUnitLoadout (_player getVariable ["Saved_Loadout",[]]);
				
		};
}];

Share this post


Link to post
Share on other sites
1 minute ago, black_hawk_mw2_87 said:

I have a script for a virtual arsenal that works in MP. I have saved several custom loadouts there. When I load any of them and respawn, I get the first loadout on mission's start. NOT the custom one I loaded from the arsenal. I want the custom one, and without ammo loses, if there are some while fighting.

I actually managed to get the custom loadout back AFTER respawn, BUT with the current ammo on death.

Share this post


Link to post
Share on other sites
1 minute ago, GEORGE FLOROS GR said:

If yes :

 

OK, should I activate the initPlayerLocal.sqf  file in my init.sqf file OR only add this one in my mission's folder?

Share this post


Link to post
Share on other sites

Did you check the code above ?

Because we post very quickly and might missed the raw !

Share this post


Link to post
Share on other sites
2 minutes ago, GEORGE FLOROS GR said:

Did you check the code above ?

Because we post very quickly and might missed the raw !

I placed this iniPlayerLocal file in the folder. But should I activate it anyway in my init.sqf file? 🙂

Like this:

execVM"initPlayerLocal.sqf";

Edited by black_hawk_mw2_87

Share this post


Link to post
Share on other sites

as davidoss said , create an initPlayerLocal.sqf and add the code there.

Share this post


Link to post
Share on other sites
5 hours ago, black_hawk_mw2_87 said:

Like this:

execVM"initPlayerLocal.sqf";

 

no it's not working like this and since you mentioned this , check also here :

 

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

 

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

 

You just need to add the initPlayerLocal.sqf in your mission folder .

generally you should follow the   example above and sort your scripts according to this , since this an MP mission.

Share this post


Link to post
Share on other sites
9 minutes ago, GEORGE FLOROS GR said:

If yes :

 

I did it and, just in case, I added that line for sqf activation in my init.sqf file, and IT WORKED.

SO! LET US BE HELPFUL TO EVERYONE WHO'D USE THIS.

1. Create initPlayerLocal.sqf file and place it in mission's folder;

2. Put this code from above inside the file.

3. Add this line inside your init.sqf file.

execVM"initPlayerLocal.sqf";

 

And we are all set!

You start the mission WITHOUT current loadout. When you pick one from the arsenal, messages appear to notify the player that the current custom loadout is closed and saved. Even if you shoot and die, you'll get absolutely the same custom loadout. Voila! 🙂

Share this post


Link to post
Share on other sites
2 minutes ago, black_hawk_mw2_87 said:

3. Add this line inside your init.sqf file.

execVM"initPlayerLocal.sqf";

 

#No read above !

Share this post


Link to post
Share on other sites
18 minutes ago, GEORGE FLOROS GR said:

 

#No read above !

I saw that. But all in all, it is your code in the .sqf file and it works. 🙂

Share this post


Link to post
Share on other sites
//////////////////////////////save and restore loadout by HAZJ. All credit to him.
player addEventHandler ["Killed",
{
	params ["_unit"];
  [_unit, [missionNamespace, "savedLoadout"]] call BIS_fnc_saveInventory;
}];

player addEventHandler ["Respawn",
{
	params ["_unit"];
  if (!isNil {missionNamespace getVariable "savedLoadout"}) exitWith {};
  [_unit, [missionNamespace, "savedLoadout"]] call BIS_fnc_loadInventory;
  hintSilent "Gear loaded";
	
}];
///////////////////////////////////////////

In init.sqf

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, major-stiffy said:

In init.sqf

 

Besically this is the same as :

5 hours ago, GEORGE FLOROS GR said:

onPlayerKilled.sqf


[player, [missionNamespace, "inventory_var"]] call BIS_fnc_saveInventory;

onPlayerRespawn.sqf


[player, [missionNamespace, "inventory_var"]] call BIS_fnc_loadInventory;

 

 

but the code from davidoss above , is when exiting the arsenal , saving your Gear and load on respawn.

5 hours ago, GEORGE FLOROS GR said:
  On 2/28/2018 at 11:13 PM, davidoss said:

initPlayerLocal.sqf


[missionNamespace, "arsenalClosed", {
	player setVariable ["Saved_Loadout",getUnitLoadout player];
	hint "Selected gear saved!"
	}] call BIS_fnc_addScriptedEventHandler;
player addEventHandler ["Respawn",{

		0 = [_this select 0] spawn {
		
			params [["_player",objNull,[objNull]]];
				waitUntil {sleep .2; alive _player};
				_player setUnitLoadout (_player getVariable ["Saved_Loadout",[]]);
				
		};
}];

 

Share this post


Link to post
Share on other sites

 Don't you need to name it initserver.sqf any more??

 

// Play3r

Share this post


Link to post
Share on other sites
1 minute ago, Play3r said:

Don't you need to name it initserver.sqf any more??

 

Generally as said before ,  when editing an mp mission everything should be based on

5 hours ago, GEORGE FLOROS GR said:

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

 

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

 

You just need to add the initPlayerLocal.sqf in your mission folder .

generally you should follow the   example above and sort your scripts according to this , since this an MP mission.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

You can also swap missionNamespace to profileNamespace which will make it save to your client's profile (.vars file). This will allow you to automatically load it on mission start or whatever.

  • Like 3

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

×