Einzelnen Beitrag anzeigen
Alt 01.04.2016, 22:12   #1 (permalink)
Wolkenbeisser
50 Beiträge100 Beiträge250 Beiträge
 
Benutzerbild von Wolkenbeisser
 
Registriert seit: 05.11.2010
Ort: Schweiz
Beiträge: 297
Standard Loadout nach Respawn geht mit EDEN nicht mehr

Hallo zusammen

Ich bin hier gerade ein wenig am verzweifeln. Ich verwendete bisher zwei Scripts, um den Spielern nach dem Respawn (MP-Coop Missionen) wieder diejenige Bewaffnung zu geben, die sie bei ihrem Tod hatten. Leider funktionieren diese jedoch nur solange ich die Mission nicht mit dem 3D Editor anpasse. Sobald eine Mutation mit EDEN stattgefunden hat, funktionieren sie nicht mehr. Der Spieler hat dann nach dem Respawn die Standardbewaffnung dieses Soldatentyps...

Ich habe das hier im I-Net gefunden dazu: https://forums.bistudio.com/topic/18...problem/page-2. Aber ich sehe die Lösung darin nicht...

Weiss jemand, wie man das Problem beheben könnte? Vielen Dank schon mal für eure Hilfe.

In der Init.sqf sieht der entpsrechende Abschnitt so aus:
Code:
//////////// --- Verwendung der richtigen Scripts für die Wiederherstellung der Vortodesbewaffnung --- ////////////
waitUntil { !isNull player }; // Wartet bis der Spieler wieder da ist //

// Bewaffnungs-Scripts kompilieren //
getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf';
setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf';
                                                
// Ausrüstung alle 2 Sekunden speichern //
[] spawn {
    while{true} do {
        if(alive player) then {
            loadout = [player,["repetitive"]] call getLoadout;
        };
    sleep 2;  
    };
};

// Ausrüstung laden beim Respawn //
player addEventHandler ["Respawn", {
        [player,loadout] spawn setLoadout;
    }
];

Das ist die get_loadout.sqf:
Code:
/*

	AUTHOR: aeroson
	NAME: get_loadout.sqf
	VERSION: 3.4
	
	DOWNLOAD & PARTICIPATE:
	https://github.com/aeroson/a3-loadout
	http://forums.bistudio.com/showthread.php?148577-GET-SET-Loadout-(saves-and-loads-pretty-much-everything)
	
	DESCRIPTION:
	I guarantee backwards compatibility.
	These scripts allows you set/get (load/save) all of the unit's gear, including:
	uniform, vest, backpack, contents of it, all quiped items, all three weapons with their attachments, currently loaded magazines and number of ammo in magazines.
	All this while preserving order of items.
	Useful for saving/loading loadouts. 
	Ideal for revive scripts where you have to set exactly the same loadout to newly created unit.
	Uses workaround with placeholders to add vest/backpack items, so items stay where you put them.
	
	PARAMETER(S):
	0 : target unit
	1 : (optional) array of options, default [] : 
		"ammo" will save ammo count of partially emptied magazines
		"repetitive" intended for repetitive use, will not use selectWeapon, means no visible effect on solder, but will not save magazines of assigned items such as laser designator batteries
	
	RETURNS:
	Array : array of strings/arrays containing target unit's loadout, to be used by fnc_set_loadout.sqf
	
	addAction support:
	Saves player's loadout into global var loadout

*/

private ["_target","_options","_saveMagsAmmo","_isRepetitive","_isOnFoot","_currentWeapon","_currentMode","_isFlashlightOn","_isIRLaserOn","_magazinesAmmo","_loadedMagazines","_saveWeaponMagazines","_getMagsAmmo","_backPackItems","_assignedItems","_data"];

_options = [];

// addAction support
if(count _this < 4) then {
	#define PARAM_START private ["_PARAM_INDEX"]; _PARAM_INDEX=0;
	#define PARAM_REQ(A) if (count _this <= _PARAM_INDEX) exitWith { systemChat format["required param '%1' not supplied in file:'%2' at line:%3", #A ,__FILE__,__LINE__]; }; A = _this select _PARAM_INDEX; _PARAM_INDEX=_PARAM_INDEX+1;
	#define PARAM(A,B) A = B; if (count _this > _PARAM_INDEX) then { A = _this select _PARAM_INDEX; }; _PARAM_INDEX=_PARAM_INDEX+1;
	PARAM_START
	PARAM_REQ(_target)
	PARAM(_options,[])
} else {
	_target = player;
};
 
_saveMagsAmmo = "ammo" in _options;
_isRepetitive = "repetitive" in _options;
_isOnFoot = vehicle _target == _target;
         
_currentWeapon = "";
_currentMode = "";
_isFlashlightOn = false;
_isIRLaserOn = false;

_magazinesAmmo = magazinesAmmoFull _target;

// save weapon mode and muzzle
if(_isOnFoot) then {
	_currentWeapon = currentMuzzle _target;
	_currentMode = currentWeaponMode _target;
	_isFlashlightOn = _target isFlashlightOn _currentWeapon;
	_isIRLaserOn = _target isIRLaserOn _currentWeapon;
} else {
	_currentWeapon = currentWeapon _target;
};
	

_loadedMagazines=[];

// universal weapon saving
_saveWeaponMagazines = {
	private ["_weapon","_magazines","_muzzles","_saveMagazine"];
	_weapon = _this select 0;
	_magazines = []; 	

	_saveMagazine = { // find, save and eat mag for _weapon		
		private ["_weapon","_magazine","_ammo"];
		_weapon = _this select 0;
		_magazine = "";
		_ammo = 0;
		{ 			
			if((_x select 4)==_weapon) then {
				_magazine = _x select 0;				
				_ammo = _x select 1;
				_x = -1;
			};
		} forEach _magazinesAmmo;
		_magazinesAmmo = _magazinesAmmo - [-1];	
		if(_magazine!="") then {
			if(_saveMagsAmmo) then {
				_magazines set [count _magazines, [_magazine, _ammo]];
			} else {
				_magazines set [count _magazines, _magazine];
			};
		};
	};	

	if(_weapon != "") then {
		[_weapon] call _saveMagazine;
		_muzzles = configFile>>"CfgWeapons">>_weapon>>"muzzles";
		if(isArray(_muzzles)) then { 	
			{ // add one mag for each muzzle
				if (_x != "this") then {					
					[_x] call _saveMagazine;			
				};
			} forEach getArray(_muzzles);		
		};
	};

	_loadedMagazines set [count _loadedMagazines, _magazines];
};

// save loaded mags for each weapon separetely, since some weapons can use same magazines
[primaryWeapon _target] call _saveWeaponMagazines;
[handgunWeapon _target] call _saveWeaponMagazines;
[secondaryWeapon _target] call _saveWeaponMagazines;

_getMagsAmmo = { // default function with _saveMagsAmmo == false
	_this select 0;
};
if(_saveMagsAmmo) then {
	// check if input array contains magazine, if it does, find it add ammo count
	_getMagsAmmo = {
		private ["_items","_location","_item","_itemIndex"];
		_items = _this select 0;		
		_location = _this select 1;
		{
			_item = _x;
			_itemIndex = _forEachIndex;
			{
				if((_x select 4)==_location && (_x select 0)==_item) then {
					_items set[_itemIndex, [_item, _x select 1]];
					_x = -1;					
				};
			} forEach _magazinesAmmo;
			_magazinesAmmo = _magazinesAmmo - [-1];	
		} forEach _items;
		_items;
	};
	
};

// get backpack items
_cargo = getbackpackcargo (unitbackpack _target);
_backpacks = [];
{
	for "_i" from 1 to ((_cargo select 1) select _foreachindex) do {
		_backpacks set [count _backpacks, _x];
	};
} foreach (_cargo select 0);	
_backPackItems = (backpackitems _target) + _backpacks;

// get assigned items, headgear and goggles is not part of assignedItems
_assignedItems = assignedItems _target;
_headgear = headgear _target;
_goggles = goggles _target;
if((_headgear != "") && !(_headgear in _assignedItems)) then {
	_assignedItems set [count _assignedItems, _headgear];
};
if((_goggles != "") && !(_goggles in _assignedItems)) then {
	_assignedItems set [count _assignedItems, _goggles];
};



/*
// use this once magazinesAmmoFull is fixed and shows magazines of assignedItems

// get magazines of everything else except weapons, most likely assigned items
// only ["Uniform","Vest","Backpack"] locations remain, weapon locations have already been eaten
_magazines = [];
{	
	if(_x select 2) then {
		if(_saveMagsAmmo) then {
			_magazines set[count _magazines, [_x select 0, _x select 1]];
		} else {
			_magazines set[count _magazines, _x select 0];
		};
		_x = -1;
	};
} forEach _magazinesAmmo;
_magazinesAmmo = _magazinesAmmo - [-1];	
_loadedMagazines set [3, _magazines];
*/


// old method using selectWeapon, cycles and tries to selectWeapon all assigned items
if(!_isRepetitive) then {
	private ["_weaponHasChanged"];
	_weaponHasChanged = false;

	// get magazines of all assigned items
	_magazines = [];
	{
		_target selectWeapon _x;
		if(currentWeapon _target==_x) then {
			_weaponHasChanged = true;
			_magazine = currentMagazine _target;
			if(_magazine != "") then {
				if(_saveMagsAmmo) then {
					_magazines set[count _magazines, [_magazine, _target ammo _x]];
				} else {
					_magazines set[count _magazines, _magazine];
				};
			};	
		};
	} forEach _assignedItems;
	_loadedMagazines set [3, _magazines];

	// select back originaly selected weapon and mode, only if weapon has changed
	if(_weaponHasChanged) then {
		if(_isOnFoot) then {
			if(_currentWeapon != "" && _currentMode != "") then {
				_muzzles = 0;
				while{ (_currentWeapon != currentMuzzle _target || _currentMode != currentWeaponMode _target ) && _muzzles < 200 } do {
					_target action ["SWITCHWEAPON", _target, _target, _muzzles];
					_muzzles = _muzzles + 1;
				};
				if(_isFlashlightOn) then {
					_target action ["GunLightOn"];
				} else {
					_target action ["GunLightOff"];
				};
				if(_isIRLaserOn) then {
					_target action ["IRLaserOn"];
				} else {
					_target action ["IRLaserOff"];
				};	
			};
		} else {
			_currentMode = "";
		};
		if(_currentMode == "") then {
			if(_currentWeapon=="") then {
				_target action ["SWITCHWEAPON", _target, _target, 0];			
			} else {
				_target selectWeapon _currentWeapon;
			};
		};
	};
};

   
_data = [
	_assignedItems, //0 []

	primaryWeapon _target, //1 ""
	primaryWeaponItems _target, //2 []

	handgunWeapon _target, //3 ""
	handgunItems _target, //4 []

	secondaryWeapon _target, //5 ""
	secondaryWeaponItems _target, //6 []

	uniform _target, //7 ""
	[uniformItems _target, "Uniform"] call _getMagsAmmo, //8 ["magazine without ammo count",["magazine with ammo count",30], ....]

	vest _target, //9 ""
	[vestItems _target, "Vest"] call _getMagsAmmo, //10

	backpack _target, //11  ""
	[_backPackItems, "Backpack"] call _getMagsAmmo, //12

	_loadedMagazines, //13 (optional) [[primary mags],[handgun mags],[secondary mags],[other mags]]
	_currentWeapon, //14 (optional) ""
	_currentMode //15 (optional) ""
];

// addAction support
if(count _this < 4) then {
	_data;
} else {  
	loadout = _data;
	//playSound3D ["A3\Sounds_F\sfx\ZoomOut.wav", _target];
};
und das ist die set_loadout.sqf:
Code:
/*

	AUTHOR: aeroson
	NAME: set_loadout.sqf
	VERSION: 4.3
	
	DOWNLOAD & PARTICIPATE:
	https://github.com/aeroson/a3-loadout
	http://forums.bistudio.com/showthread.php?148577-GET-SET-Loadout-(saves-and-loads-pretty-much-everything)
	
	DESCRIPTION:
	I guarantee backwards compatibility.
	These scripts allows you set/get (load/save) all of the unit's gear, including:
	uniform, vest, backpack, contents of it, all quiped items, all three weapons with their attachments, currently loaded magazines and number of ammo in magazines.
	All this while preserving order of items.
	Useful for saving/loading loadouts. 
	Ideal for revive scripts where you have to set exactly the same loadout to newly created unit.
	Uses workaround with placeholders to add vest/backpack items, so items stay where you put them.
	
	PARAMETER(S):
	0 : target unit
	1 : array of strings/arrays containing desired target unit's loadout, obtained from get_loadout.sqf
	2 : (optional) array of options, default [] : ["ammo"]  will allow loading of partially emptied magazines, otherwise magazines will be full 	 	
	
	addAction support:
	Sets player's loadout from global var loadout
  
*/

private ["_target","_options","_loadMagsAmmo","_data","_loadedMagazines","_placeholderCount","_loadBeforeAdd","_add","_outfit","_addWeapon","_addPrimary","_addHandgun","_addSecondary","_addOrder","_currentWeapon","_currentMode"];

_options = [];

// addAction support
if(count _this < 4) then {
	#define PARAM_START private ["_PARAM_INDEX"]; _PARAM_INDEX=0;
	#define PARAM_REQ(A) if (count _this <= _PARAM_INDEX) exitWith { systemChat format["required param '%1' not supplied in file:'%2' at line:%3", #A ,__FILE__,__LINE__]; }; A = _this select _PARAM_INDEX; _PARAM_INDEX=_PARAM_INDEX+1;
	#define PARAM(A,B) A = B; if (count _this > _PARAM_INDEX) then { A = _this select _PARAM_INDEX; }; _PARAM_INDEX=_PARAM_INDEX+1;
	PARAM_START
	PARAM_REQ(_target)
	PARAM_REQ(_data)
	PARAM(_options,[])
} else {
	_target = player;
	_data = loadout;
	//playSound3D ["A3\Sounds_F\sfx\ZoomIn.wav", _target]; 
};

if(isNil{_data}) exitWith {
	systemChat "you are trying to set/load empty loadout";
};
if(count _data < 13) exitWith {
	systemChat "you are trying to set/load corrupted loadout";
};

#define QUOTE(A) #A
#define EL(A,B) ((A) select (B))
#define _THIS(A) EL(_this,A)

// placeholders
#define PLACEHOLDER_BACKPACK QUOTE(B_Kitbag_mcamo) // any backpack with capacity>0
#define PLACEHOLDER_ITEM QUOTE(ItemWatch) // addItem placeholder should be smallest item possible

_loadMagsAmmo = "ammo" in _options;
_loadedMagazines = [];
if(count _data > 13) then {
	if(typeName(_data select 13)=="ARRAY") then {
		_loadedMagazines = _data select 13;
	};
};

_currentWeapon = "";
if(count _data > 14) then {
	_currentWeapon = _data select 14;
};
_currentMode = ""; 
if(count _data > 15) then {
	_currentMode = _data select 15;
};	

_placeholderCount = 0;

// basic add function intended for use with uniform and vest
_add = {
	private ["_target","_item","_callback"];	
	_target = _this select 0;
	_item = _this select 1;
	_callback = _this select 2;
	if(typename _item == "ARRAY") then {
		if(_item select 0 != "") then {
			if(_loadMagsAmmo) then {
				_target addMagazine _item;
			} else {
				(_item select 0) call _callback;
			};
		};
	} else {
		if(_item != "") then {
			_item call _callback;
		};
	};
};

// remove clothes to prevent incorrect mag loading
removeUniform _target;
removeVest _target;
removeBackpack _target;


_outfit = PLACEHOLDER_BACKPACK; // we need to add items somewhere before we can assign them
_target addBackpack _outfit;
clearAllItemsFromBackpack _target;
removeAllAssignedItems _target;
removeHeadgear _target;
removeGoggles _target;

// add loaded magazines of assigned items
if(count _loadedMagazines>=3) then {
	{ 
		[_target, _x, { _target addItemToBackpack _x }] call _add;
	} forEach (_loadedMagazines select 3);
};

// add assigned items
{ 
	[_target, _x, { _target addItemToBackpack _x }] call _add;
	_target assignItem _x;
} forEach (_data select 0);

clearAllItemsFromBackpack _target;

// get assigned items, headgear and goggles is not part of assignedItems
private ["_assignedItems","_headgear","_goggles"];
_assignedItems = assignedItems _target;
_headgear = headgear _target;
_goggles = goggles _target;
if((_headgear != "") && !(_headgear in _assignedItems)) then {
	_assignedItems set [count _assignedItems, _headgear];
};
if((_goggles != "") && !(_goggles in _assignedItems)) then {
	_assignedItems set [count _assignedItems, _goggles];
};
// add asigned items that could not be added with assign item
// asuming each assigned item can be put only into one slot
{
	if(!(_x in _assignedItems)) then {
		_target addWeapon _x;
	}
} forEach (_data select 0);



// universal add weapon to hands
_addWeapon = {
	private ["_weapon","_magazines","_muzzles"];
	clearAllItemsFromBackpack _target;
	_target removeWeapon ([] call _THIS(0));
	_weapon = _data select _THIS(1);     
	if(_weapon != "") then {
		if(isClass(configFile>>"CfgWeapons">>_weapon)) then {
			if (_currentWeapon == "") then {
				_currentWeapon = _weapon;
			}; 
			if(count _loadedMagazines > 0) then {
				_magazines = _loadedMagazines select _THIS(5); // get loaded magazines from saved loadout				
				if(typename _magazines != "ARRAY") then { // backwards compatibility, make sure _magazines is array
					if(_magazines=="") then { 
						_magazines = [];
					} else {
						_magazines = [_magazines];
					};
				};
			} else {          
				_magazines = [getArray(configFile>>"CfgWeapons">>_weapon>>"magazines") select 0]; // generate weapon magazine
				_muzzles = configFile>>"CfgWeapons">>_weapon>>"muzzles";
				if(isArray(_muzzles)) then { // generate magazine for each muzzle	
					{
						if (_x != "this") then {
							_magazines set [count _magazines, toLower(getArray(configFile>>"CfgWeapons">>_weapon>>_x>>"magazines") select 0)];
						};
					} forEach getArray(_muzzles);	
				};
			};        	  
			{
				[_target, _x, { _target addItemToBackpack _x }] call _add;
			} forEach _magazines; // add magazines							
			_target addWeapon _weapon;                                                                                                                
			{ 
				if(_x!="" && !(_x in ([] call _THIS(3)))) then { 
					_x call _THIS(4); 
				}; 
			} forEach (_data select (1+_THIS(1))); // add weapon items
		} else {
			systemchat format["%1 %2 doesn't exist",_THIS(2),_weapon];
			if (_currentWeapon == _weapon) then {
				_currentWeapon = "";
				_currentMode = "";
			};
		};                             											                                                                                               
	};
};

// add primary weapon, add primary weapon loaded magazine, add primary weapon items
_addPrimary = {
	[
		{ primaryWeapon _target }, // 0 // get current weapon
		1, // 1 //weapon classname index in _data
		"primary", // 2 // weapon debug type
		{ primaryWeaponItems _target }, // 3 // weapon items
		{ _target addPrimaryWeaponItem _this }, // 4 // add weapon item
		0 // 5 // index in _loadedMagazines
	] call _addWeapon;
};

// add handgun weapon, add handgun weapon loaded magazine, add handgun weapon items
_addHandgun = {
	[
		{ handgunWeapon _target }, // 0 // get current weapon
		3, // 1 //weapon classname index in _data
		"handgun", // 2 // weapon debug type
		{ handgunItems _target }, // 3 // weapon items
		{ _target addHandgunItem _this }, // 4 // add weapon item
		1 // 5 // index in _loadedMagazines
	] call _addWeapon;
};
      
// add secondary weapon, add secondary weapon loaded magazine, add secondary weapon items
_addSecondary = {
	[
		{ secondaryWeapon _target }, // 0 // get current weapon
		5, // 1 //weapon classname index in _data in _data
		"secondary", // 2 // weapon debug type
		{ secondaryWeaponItems _target }, // 3 // weapon items
		{ _target addSecondaryWeaponItem _this }, // 4 // add weapon item
		2 // 5 // index in _loadedMagazines
	] call _addWeapon;
};


// first added weapon is selected weapon, order add functions to firstly add currently selected weapon
_addOrder=[_addPrimary,_addHandgun,_addSecondary];
if(_currentWeapon!="") then {
	_addOrder = switch _currentWeapon do { 
		case (_data select 3): {[_addHandgun,_addPrimary,_addSecondary]};
		case (_data select 5): {[_addSecondary,_addPrimary,_addHandgun]};
		default {_addOrder};  
	};			
};
{
	[] call _x;
} forEach _addOrder;

// select weapon and firing mode
if(vehicle _target == _target && _currentWeapon != "" && _currentMode != "") then {
	_muzzles = 0;                                                                                                           
	while { (_currentWeapon != currentMuzzle _target || _currentMode != currentWeaponMode _target ) && _muzzles < 100 } do {
		_target action ["SWITCHWEAPON", _target, _target, _muzzles];
		_muzzles = _muzzles + 1;
	};
	if(_muzzles >= 100) then {
		systemchat format["mode %1 for %2 doesn't exist", _currentMode, _currentWeapon];
		_currentMode = "";		
	};
} else {
	_currentMode = "";
};
if(_currentMode == "" && _currentWeapon != "") then {
	_target selectWeapon _currentWeapon;
};

clearAllItemsFromBackpack _target;

// add uniform, add uniform items and fill uniform with item placeholders
_outfit = _data select 7;  
if(_outfit != "") then {
	if(isClass(configFile>>"CfgWeapons">>_outfit)) then {			
		_target addUniform _outfit;
		_target addItem PLACEHOLDER_ITEM;
		if(loadUniform _target > 0) then {
			_placeholderCount = _placeholderCount + 1;
			{ 
				[_target, _x, { _target addItemToUniform _x }] call _add;
			} forEach (_data select 8);			
			while{true} do {
				_loadBeforeAdd = loadUniform _target;
				_target addItem PLACEHOLDER_ITEM;
				if(loadUniform _target == _loadBeforeAdd) exitWith {};
				_placeholderCount = _placeholderCount + 1;					
			};		
		};
	} else {
		systemchat format["uniform %1 doesn't exist",_outfit];
	};		
};

// add vest, add vest items and fill vest with item placeholders
_outfit = _data select 9; 
if(_outfit != "") then {
	if(isClass(configFile>>"CfgWeapons">>_outfit)) then {
		_target addVest _outfit;
		_target addItem PLACEHOLDER_ITEM;
		if(loadVest _target > 0) then {
			_placeholderCount = _placeholderCount + 1;	
			{ 
				[_target, _x, { _target addItemToVest _x }] call _add;
			} forEach (_data select 10);
			while{true} do {
				_loadBeforeAdd = loadVest _target;
				_target addItem PLACEHOLDER_ITEM;
				if(loadVest _target == _loadBeforeAdd) exitWith {};
				_placeholderCount = _placeholderCount + 1;	
			};				
		};
	} else {
		systemchat format["vest %1 doesn't exist",_outfit];
	};
};      
 
// add backpack and add backpack items
removeBackpack _target;
_outfit = _data select 11; 
if(_outfit != "") then {
	if(getNumber(configFile>>"CfgVehicles">>_outfit>>"isbackpack")==1) then {
		_target addBackpack _outfit;                                                                    
		clearAllItemsFromBackpack _target;
		_target addItem PLACEHOLDER_ITEM;
		_placeholderCount = _placeholderCount + 1;
		if(loadBackpack _target > 0) then {		
			{
				[_target, _x, { _target addItemToBackpack _x }] call _add;
			} forEach (_data select 12);
		};
	} else {
		systemchat format["backpack %1 doesn't exist",_outfit];
	};
};

// remove item placeholders
for "_i" from 1 to _placeholderCount do {
	_target removeItem PLACEHOLDER_ITEM; 
};


// make loadout visible fix?
if(vehicle _target == _target) then {
	//_target switchMove (getArray(configFile>>"CfgMovesMaleSdr">>"States">>animationState player>>"ConnectTo") select 0);
	_target setPosATL (getPosATL _target);
};
Wolkenbeisser ist offline