Jump to content
Sign in to follow this  
addicted

save gear

Recommended Posts

Hello

I need help with script which will save my current gear. I'm beginner scripter then for now its to difficult for me.

I was looking around and I haven't foud it yet. I found scripts wchich will respawn players with the same gear when they died, same gear when they started, i found big module called virtual ammo box. But all of this it's not what I'm looking for. Probably in Virtuall ammmo box there is module to save gear but its to big for me to find it and use it properly.

Regards

Share this post


Link to post
Share on other sites

Hello, while I may not be able to help you with your query, please allow me to help you get help from more competent people than myself.

For what purpose do you need your gear saved? I'm not sure if it'll make a difference in the answers you receive, but detail and extra information is always handy.

Share this post


Link to post
Share on other sites

Maybe something like this. Untested.

unit init line

this addEventHandler ["Killed",{call TAG_KilledEH_Loadout}];

init.sqf

[] call compile preprocessFile "Loadout.sqf";

loadout.sqf

TAG_KilledEH_Loadout = {

_unit = _this select 0;

_uniform = uniform _unit;
_vest = vest _unit;
_headGear = headGear _unit;
_backPack = backpack _unit;

_primaryWeapon = primaryWeapon _unit;
_secondaryWeapon = secondaryWeapon _unit;
_handGunWeapon = handGunWeapon _unit;

_uniformItems = uniformItems _unit;
_vestItems = vestItems _unit;
_backPackItems = backPackItems _unit;
_primaryWeaponItems = primaryWeaponItems _unit;
_secondaryWeaponItems = secondaryWeaponItems _unit;
_handGunItems = handgunItems _unit;

waitUntil { alive _unit };

removeAllWeapons _unit;
removeHeadgear _unit;
removeVest _unit;
removeUniform _unit;
removeBackPack _unit;

_unit addUniform _uniform;
_unit addVest _vest;
_unit addBackPack _backPack
_unit addHeadGear _headGear;
{_unit addItemToUniform _x} forEach _uniformItems;
{_unit addItemToVest _x} forEach _vestItems;
{_unit addItemToBackpack _x} forEach _backPackItems;
_unit addWeapon _primaryWeapon;
_unit addWeapon _secondaryWeapon;
_unit addWeapon _handGunWeapon;

};

Share this post


Link to post
Share on other sites

Hello

@Bashkire Thanks for interests. I'm trying to make multiplayer mission. I plan to equipe soldiers like this. After choosing some slot (AT, crewman grenadier ect.)on beginning they will have to choose some of his predefined weapons ammo and granades from scroll menu, then they will have possibility to choose other not so important stuff like siut optic (but not scopes), backpacks ect. After this i need to save gear to prevent players frome choosing gear every time after respawn.

@Iceman77 Thanks a lot. I will it test soon.

Edit. This script looks like should save gear when I was killed. For me it doesn't work other way I'm looking for script which will save gear when i want it. For example after choose all equipment I will choose action from action menu "save gear". Can you try to make some script like this? I will try to use your idea to make that script but I'm just a beginner.

Edited by addIcted

Share this post


Link to post
Share on other sites

I was fiddling with it last night. There was an error or two. Also, the addItemToXXX commands are broken on stable build. I'm also wanting to save a loadout at any given time, so I'll let you know what I come up with, if you haven't found something by then.

Share this post


Link to post
Share on other sites

Yeah I've a working one. Trying to test it for any glaring holes before I give it to you.

Share this post


Link to post
Share on other sites

this might work..

player init or anywhere:

nul = player addaction ["Save Loadout","saveLoadout.sqf"];

/*

in Init.sqf

*/

globalRespawnLoadout = [];

/*
SaveLoadout.sqf
*/
//[target,caller,id,arg]
(_this select 0) removeaction (_this select 2);

hint "Loadout saved.";
globalRespawnLoadout = 
[
uniform player,
vest player,
backpack player,
headgear player,
magazines player,
weapons player,
primaryWeaponItems player,
secondaryWeaponItems player,
handgunItems player,
items player,
assignedItems player,
goggles player
];

/*
onPlayerRespawn.sqf
*/

_new = _this select 0;
_old = _this select 1;
//check if gear saved and load it

if (count globalRespawnLoadout > 0) then
{
removeAllAssignedItems _new;
removeAllItems _new;
removeAllWeapons _new;
removeUniform _new;
_new addUniform (globalRespawnLoadout select 0);
removeVest _new;
_new addVest (globalRespawnLoadout select 1);
removeBackpack _new;
_new addBackpack (globalRespawnLoadout select 2);
removeHeadgear _new;
_new addHeadgear (globalRespawnLoadout select 3);

{_new addMagazine _x} forEach (globalRespawnLoadout select 4);
{_new addWeapon _x} forEach (globalRespawnLoadout select 5);
{_new addPrimaryWeaponItem _x} forEach (globalRespawnLoadout select 6);
{_new addSecondaryWeaponItem _x} forEach (globalRespawnLoadout select 7);
{_new addHandgunItem _x} forEach (globalRespawnLoadout select 8);
{_new addItem _x} forEach (globalRespawnLoadout select 9);
{_new addItem _x} forEach (globalRespawnLoadout select 10);
{_new assignItem _x} forEach (globalRespawnLoadout select 10);
removeGoggles _new;
_new addgoggles (globalRespawnLoadout select 11);
};

Share this post


Link to post
Share on other sites

LOl, this is what I came up with. You may want to use Kunsa's! With the addItemToXXXX commands broken, I made this alot longer than it should have been (atleast according to my personal, initial plans). I did alot of checks in there becasue i kept getting 'No cfgWeapons entry' errors. Also kept getting 'bad vehicle type' if i didn't do a backpack check. I said the hell with it and ran some checks all over the place!

ammo crate init line

s_Action = this addAction ["Save Loadout", "loadSaveAction.sqf", [], 0, false, true, "", ""]; 

init.sqf

player addEventHandler ["respawn",{call TAG_LoadGet}];
[] call compile preprocessFileLineNumbers "scripts\LoadSave.sqf";
[] call compile preprocessFileLineNumbers "scripts\LoadGet.sqf";

loadSaveAction.sqf

[(_this select 1)] call TAG_LoadSave;

loadSave.sqf

TAG_LoadSave = {
loadSaved=True;
_unit = _this select 0;

if (goggles _unit != "") then {
  gGoggles = goggles _unit; 
  pGoggles=true;
} else {pGoggles=false;};

if (headGear _unit != "") then {
  gHeadGear = headGear _unit;
  pHeadGear=True;
} else {pHeadGear=false;};

if (uniform _unit != "") then {
  gUniform = uniform _unit;
  gUniformItems = uniformItems _unit;
  pUniform=true;
} else {pUniform=false;};

if (vest _unit != "") then {
  gVest = vest _unit;
  gVestItems = vestItems _unit;
  pVest=true;
} else {pVest=false;};

if (backPack _unit != "") then {
  gBackPack = backpack _unit;
  gBackPackItems = backPackItems _unit;
  pBackPack=true;
} else {pBackPack=false;};

if (primaryWeapon _unit != "") then {
  gPrimaryWeapon = primaryWeapon _unit;
  gPrimaryItems = primaryWeaponItems _unit;
  pPrimaryWeapon=true;
} else {pPrimaryWeapon=false;};

if (secondaryWeapon _unit != "") then {
  gSecondaryWeapon = secondaryWeapon _unit;
  gSecondaryItems = secondaryWeaponItems _unit;
  pSecondaryWeapon=true;
} else {pSecondaryWeapon=false;};

if (handGunWeapon _unit != "") then {
  gHandGunWeapon = handGunWeapon _unit;
  gHandGunItems = handgunItems _unit;
  pHandGunWeapon=true;
} else {pHandGunWeapon=false;};

if (count primaryWeaponMagazine _unit > 0) then {
  gPrimaryMag = primaryWeaponMagazine _unit;
  pPrimaryMag=true;
} else {pPrimaryMag=false;};

if (count secondaryWeaponMagazine _unit > 0) then {
   gSecondaryMag = secondaryWeaponMagazine _unit;
   pSecondaryMag=true;
} else {pSecondaryMag=false;};

if (count handGunmagazine _unit > 0) then {
  gHandGunMag = handGunMagazine _unit;
  pHandGunMag=true;
} else {pHandGunMag=false;};

};

loadget.sqf

loadSaved=false;

TAG_LoadGet = {

if (!loadSaved) exitWith {hint format ["No previous loadout was saved %1. You must use the addaction to save your loadout. You have respawned with your default loadout!", name player];};

_unit =_this select 0;

removeAllWeapons _unit;
removeHeadgear _unit;
removeVest _unit;
removeUniform _unit;
removeBackPack _unit;

if (pGoggles) then {_unit addGoggles gGoggles;};
if (pUniform) then {_unit addUniform gUniform;};
if (pVest) then {_unit addVest gVest;};
if (pBackPack) then {_unit addBackPack gBackPack;clearAllItemsFromBackpack _unit;};
if (pHeadGear) then {_unit addHeadGear gHeadGear;};
if (pUniform) then {
  {
    if (isClass (configFile >> "cfgMagazines" >> _x)) then {_unit addMagazine _x;} else {_unit addWeapon _x;};
  } forEach gUniformItems;
};

if (pVest) then {
  {
    if (isClass (configFile >> "cfgMagazines" >> _x)) then {_unit addMagazine _x;} else {_unit addWeapon _x;};
  } forEach gVestItems;
};

if (pBackPack) then {
  {
    if (isClass (configFile >> "cfgMagazines" >> _x)) then {_unit addMagazine _x;} else {_unit addWeapon _x;};
  } forEach gBackPackItems;
};

if (pPrimaryMag) then {_unit addmagazine gPrimaryMag;};
if (pSecondaryMag) then {_unit addmagazine gSecondaryMag;};
if (phandGunMag) then {_unit addmagazine gHandGunMag;};

if (pPrimaryWeapon) then {
   _unit addWeapon gPrimaryWeapon;
  {_unit addPrimaryWeaponItem _x} forEach gPrimaryItems;
};

if (pSecondaryWeapon) then {
   _unit addWeapon gSecondaryWeapon;
  {_unit addsecondaryWeaponItem _x} forEach gSecondaryItems;
};

if (pHandGunWeapon) then {
   _unit addWeapon gHandGunWeapon;
  {_unit addhandGunItem _x} forEach gHandGunItems;
};

};

Edited by Iceman77

Share this post


Link to post
Share on other sites

:D :) Thanks a lot Kunsa and Iceman. I will test it today and at least I have possibility to end that mission.

Share this post


Link to post
Share on other sites

You can also check aeroson's get/set loadout as well.

http://forums.bistudio.com/showthread.php?148577-GET-SET-Loadout-%28saves-and-loads-pretty-much-everything%29

Although it is getting too complicated, it has some nice tricks. Eg. counting loaded mags and stuff.

Iceman: yours is nice as well, and it is simple: thanks for this too.

(Tip: you can check if !isNull and there is no need for an extra bool variable everywhere. And see Problems and facts @ the link above) :)

Share this post


Link to post
Share on other sites

Iceman: yours is nice as well, and it is simple: thanks for this too.

(Tip: you can check if !isNull and there is no need for an extra bool variable everywhere. And see Problems and facts @ the link above) :)

Thanks for the tip. That's a great idea. Also thanks for the link. Note: I wish the addItemToXXX commands weren't broken on stable. It takes only 3 lines to give all inventory items back to the player lol.

Share this post


Link to post
Share on other sites

Thanks one more time.

@Iceman Do you have the same problem with script that after respawn you have one mag less than on save?

Share this post


Link to post
Share on other sites

addIcted: It is caused by loaded mag not saved, so a new one gets loaded upon load, thus the one less in inventory.

Share this post


Link to post
Share on other sites

Hmm, the loaded mag is saved though and then added. Well, it should be atleast.

if (count primaryWeaponMagazine _unit > 0) then {    
  gPrimaryMag = primaryWeaponMagazine _unit; 
  pPrimaryMag=true; 
} else {pPrimaryMag=false;};

if (pPrimaryMag) then {_unit addmagazine gPrimaryMag;};

There are still some glaring holes anyhow. Medikits wont get saved and readded for some reason etc etc. I'm going to redo it all anyhow. To get rid of the silly variables.

Share this post


Link to post
Share on other sites
Maybe something like this. Untested.

unit init line

this addEventHandler ["Killed",{call TAG_KilledEH_Loadout}];

init.sqf

[] call compile preprocessFile "Loadout.sqf";

loadout.sqf

TAG_KilledEH_Loadout = {

_unit = _this select 0;

_uniform = uniform _unit;
_vest = vest _unit;
_headGear = headGear _unit;
_backPack = backpack _unit;

_primaryWeapon = primaryWeapon _unit;
_secondaryWeapon = secondaryWeapon _unit;
_handGunWeapon = handGunWeapon _unit;

_uniformItems = uniformItems _unit;
_vestItems = vestItems _unit;
_backPackItems = backPackItems _unit;
_primaryWeaponItems = primaryWeaponItems _unit;
_secondaryWeaponItems = secondaryWeaponItems _unit;
_handGunItems = handgunItems _unit;

waitUntil { alive _unit };

removeAllWeapons _unit;
removeHeadgear _unit;
removeVest _unit;
removeUniform _unit;
removeBackPack _unit;

_unit addUniform _uniform;
_unit addVest _vest;
_unit addBackPack _backPack
_unit addHeadGear _headGear;
{_unit addItemToUniform _x} forEach _uniformItems;
{_unit addItemToVest _x} forEach _vestItems;
{_unit addItemToBackpack _x} forEach _backPackItems;
_unit addWeapon _primaryWeapon;
_unit addWeapon _secondaryWeapon;
_unit addWeapon _handGunWeapon;

};

Hey everyone,

First let me say I am very new at modding Arma3. The last game I really edited was Rome: TW, and those were stat balancing changes only.

So am very new at scripting.

I am making an MP Co-op Mission, and want the loadouts I entered into the INITIALIZATION BOX in each soldier in the Editor to persist after death, and both Players and AI will respawn with the correct gear.

What is the Unit Init?

This is separate from the regular Init.

Thank you in advance for your patience in dealing with me. :)

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  

×