Jump to content
Sign in to follow this  
Hellster

How to keep Rucksack loadout after respawn?

Recommended Posts

I'm trying to script in a pretty hefty custom loadout for the start of a number of custom ACE2 missions developed by my group and I. I have that working just fine using shk's gear script http://forums.bistudio.com/showthread.php?t=89952

This init.sqs code is working for everything in the units standard slots. What can I do to modify this to keep the rucksack and it's loadout after respawn?

#start

@ (! alive player)

_weapons = weapons player

_magazines = magazines player

@ (alive player)

removeallweapons player

{player addMagazine _x} foreach _magazines

{player addWeapon _x} foreach _weapons

goto "start"

Edited by He||razør

Share this post


Link to post
Share on other sites

I got a similar problem. I usually use ACE2 and the norrin-revive script (dec2009). Sometimes after respawn or revive the rucksack is empty or gone. If i shouldered the rucksack to carry a SMAW or Javelin too even the SMAW or Javelin are gone or the SMAW/Javelin is still there but the rucksack has gone.

I think i need a new x_playerweapons.sqf in which the rucksack is used, too. Maybe someone got a suggestion.

Share this post


Link to post
Share on other sites

i use this script ... i found it somewhere here in the forum

// ruck_reloaded.sqf

_hasruck = false;

_ruckType = "";

_ruckMags = [];

_ruckWeps = [];

while {true} do

{

if (alive player) then

{

_hasruck = player call ACE_Sys_Ruck_fnc_hasRuck;

if (_hasruck) then

{

_ruckType = player call ACE_Sys_Ruck_fnc_FindRuck;

_ruckMags = player getVariable "ACE_RuckMagContents";

_ruckWeps = player getVariable "ACE_RuckWepContents";

//hint format ["%1", _ruckType];

};

} else {

waitUntil {alive player};

sleep 1;

if (_hasruck) then

{

player addWeapon _ruckType;

player setVariable ["ACE_RuckMagContents", _ruckMags, true];

player setVariable ["ACE_RuckWepContents", _ruckWeps, true];

};

};

sleep 1;

};

Share this post


Link to post
Share on other sites

The weapon on back is stored in the variable "ACE_weapononback".

So you can put a weapon on back with the command

player setVariable ["ACE_weapononback",<weapon>,false],

and obtain it by

_weapononback = player getVariable "ACE_weapononback".

Edited by Bon

Share this post


Link to post
Share on other sites

@tobmic

Currently i use this x_playerweapons by XENO. Could you help me implement your script in the following one:

// by Xeno

private ["_weapons", "_magazines", "_p", "_primw", "_muzzles"];

if (!(local player)) exitWith {};

while {true} do {

waitUntil {!alive player};

_weapons = weapons player;

_magazines = magazines player;

waitUntil {alive player};

_p = player;

removeAllItems _p;

removeAllWeapons _p;

{_p addMagazine _x;} forEach _magazines;

{_p addWeapon _x;} forEach _weapons;

_primw = primaryWeapon _p;

if (_primw != "") then {

_p selectWeapon _primw;

// Fix for weapons with grenade launcher

_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");

_p selectWeapon (_muzzles select 0);

};

};

That would be great. Thx in advance.

Share this post


Link to post
Share on other sites
@tobmic

Currently i use this x_playerweapons by XENO. Could you help me implement your script in the following one:

That would be great. Thx in advance.

I dont realy know how to do this : (

But maybe you try to execute both scripts ?

In the init.sqf i wrote this for my mission it works (maybe i should execute it another way ?)

[] spawn {

waitUntil {!isNull player};

execVM "weaponrespawn.sqf";

};

[] spawn {

waitUntil {!isNull player};

execVM "rucksackrespawn.sqf";

};

Only thing that doesnt work for me is that the second weapon slot does not respawn

Share this post


Link to post
Share on other sites

@Sickboy

Could you explain that a little bit? I am trying to re-setup the x_playerweapons from XENO that after respawn or revive all waepons and magazines are still there.

At the moment when i use a backpack and a at-launcher (at back) one of them is always gone. So after revive i only got the backpack (which is sometimes empty, sometimes full) or i only got the launcher and the backpack is gone. It would be great to have them both (backpack and launcher) after revive.

Maybe you got a mission where this is going to work. So i can take a look for myself, because i dont know how to implement the features from your link in my x_playerweapons.

Share this post


Link to post
Share on other sites
It is really recommended (and the only supported method) to use the official ACE 2 API:

Add magazine to Ruck: http://dev-heaven.net/docs/ace/files/sys_ruck/fnc_PackMagazine-sqf.html

Read magazine list from Ruck: http://dev-heaven.net/docs/ace/files/sys_ruck/fnc_RuckMagazinesList-sqf.html

etc.

Agree with Sickboy. Use the provided API functions. You never know if/when other stuff will change due to bug fixes, reworking of algorithms, or reoganization of code/variables. If it does, your mission scripts are likely to break badly. The API functions provide the extra error checking and conversion to ensure that you get the behavior you want.

I can add a new API calls fairly easily if needed by the mission makers.

Share this post


Link to post
Share on other sites
Can somebody tell me how to use those APIs?

Bump - this looks great, if it works it's perfect. Is there anyone who could do this?

EDIT:

I found this:

// By Lq.Snake
// Questions?  PM nthamma on TG forums

// Should only be run client side since player does not exist in dedicated servers

// Checking if player has successfully synchronized (for JIPs)
if (!isDedicated && isNull player) then
{
waitUntil {!isNull player};
};

sleep 5; /* Small delay that will wait until the gear of each unit initializes */

private ["_weaponsinit", "_itemsinit", "_magazinesinit", "_weaponOnBack"];

// Initializing/Declaration of local variables
_weaponsinit = weapons player; /* Returns all the weapons of the player and assigns it to the variable */
_itemsinit = items player; /* Returns all items of the player and assigns it to the variable */
_magazinesinit = magazines player; /* Returns all magazines of player and assigns it to the variable */
_arrayRuck = player call ACE_Sys_Ruck_fnc_RuckMagazines; /* Returns all ruck items and stores them into variable */
_weaponOnBack = player getVariable "ACE_WeaponOnBack"; /* Returns the weapon on back and stores it into a variable */

while {true} do
{
if (!alive player) then
{
	waitUntil {alive player}; /* Wait until player respawns */
	sleep 0.1; /* Small delay to make sure player has respawned */
	if (player != player) exitWith {}; /* Checks to see if player has not gone back to the lobby screen (who knows?) */


	// Rearming player
	removeAllWeapons player;
	removeAllItems player;
	{player addMagazine _x} forEach _magazinesinit;
	{player addWeapon _x} forEach _weaponsinit;
	{player addweapon _x} forEach _itemsinit;
	// Checking to see if player has rucksack
	if (player call ACE_Sys_Ruck_fnc_hasRuck) then {{[player, _x] call ACE_Sys_Ruck_fnc_AddMagToRuck} forEach _arrayRuck;};
	// Checking if player had weapon on back
	if (format["%1", _weaponOnBack] != "<NULL>") then {player setVariable ["ACE_WeaponOnBack", _weaponOnBack];};
	player selectWeapon primaryWeapon player;
	hint format["%1 tickets remaining", TICKETS];
};
sleep 5;
}; /* End of while loop */

It gives you the equipment you spawn with.

Could anybody change that so you spawn with the equipment you DIED with?

Also it would be nice to CLEAR OUT the corpse's equipment to prevent bug-using.

Thanks in advance!

Edited by megagoth1702

Share this post


Link to post
Share on other sites

GOT IT!

Here we go!

This will give you the gear you died with and CLEAR THE CORPSE.

// By Lq.Snake

// Purpose: Preserve unit's gear at time of death

// Locality: Client

// Execution: In init.sqf, add a line of code that will execute this script. (ie. [] execVM "preserveGear.sqf";)

#define _DEBUG false

if (_DEBUG) then { player sideChat "preserveGear.sqf running..." };

// JIP

if (!isDedicated && isNull player) then { waitUntil { !isNull player }; };

if (!isDedicated) then

{

ls_Preserve_Kit =

{

if (_DEBUG) then { player sideChat "Inside code" };

_unit = _this select 0;

_weaponskilled = weapons _unit;

_magazineskilled = magazines _unit;

_arrayRuck = _unit call ACE_Sys_Ruck_fnc_RuckMagazines;

_weaponOnBack = _unit getVariable "ACE_WeaponOnBack";

if (_DEBUG) then { player sideChat format["%1", _weaponOnBack] };

if (_DEBUG) then { player sideChat format["%1", _weaponskilled] };

removeAllWeapons player;

removeAllItems player;

waitUntil { alive player };

if (_DEBUG) then { player sideChat "Gearing player..." };

removeAllWeapons player;

removeAllItems player;

{ player addMagazine _x } forEach _magazineskilled;

{ player addWeapon _x } forEach _weaponskilled;

if (player call ACE_Sys_Ruck_fnc_hasRuck) then { {[player, _x] call ACE_Sys_Ruck_fnc_AddMagToRuck} forEach _arrayRuck; };

if (_weaponOnBack != "") then { player setVariable ["ACE_WeaponOnBack", _weaponOnBack]; };

player selectWeapon (primaryWeapon player);

};

player addEventHandler ["killed", { _this spawn ls_Preserve_Kit}];

if (_DEBUG) then { player sideChat "preserveGear.sqf: EOF" };

};

Share this post


Link to post
Share on other sites

i know this thread is quite old but ive got strage issues with the posted script.

ive hacked my mission together with editor and copy-paste and tried to analyze the scripts i used. the weaponPreserve.sqf in the last post works well with one acception: the gear inside the ruck just adds on respawn. exapmple: my unit had 2 stanag magazines in the ruck before it was killed, on respawn the standard editor loadout for this type of unit is deleted (i can see it for half a second or so) and the pre-death gear is equipped, but in the ruck there are 4 magaznes now.

every respawn doubles the ruck contents!

maybe it would help to clear the ruck loadout together with the standard loadout before equipping the unit on spawn but i dont know how.

is it a possibly bug?

does anyone know a workaround for that in such case?

Share this post


Link to post
Share on other sites

Whoops - absolutely no idea. :-/ Do you use more than one resupply-script?

For me that thing up there works perfectly.

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  

×