Jump to content
Sign in to follow this  
spectrersg

Remembering Gear & Getting a players model classname

Recommended Posts

Hi all,

I'm making a script that adds a new player model at the players location, switches you to the new model and deletes your original; effectively allowing you to switch your model when you use the addaction.

My problem is that the players inventory is set to whatever the model default is; how do I make the script remember and give you your original gear so people don't lose it when switching models?

Also is there a way to have a script get your models classname and remember that as well?

Share this post


Link to post
Share on other sites

Thanks for the quick response; I'm aware of the addsweapon and that it grants you specific gear... My issue is that players will customize their load out and then will change their model, losing the gear they chose.

---------- Post added at 16:06 ---------- Previous post was at 15:58 ----------

Just to clarify my script is adding a specific player model, switching you to that model and adding an action to go in reverse; to put you back into your original model.

The current way I have it is split into two scripts, one to put you in the new model, another to put you back into your model.

Problem is I have to specify in each script individual players and models; I'm looking for a way to automate that process without the need to edit the scripts.

Share this post


Link to post
Share on other sites

Save the old class name to the player namespace, then you can retrieve it dynamically.

[color=#0000BB][font=monospace]_classname [/font][/color][color=#007700][font=monospace]= [/font][/color][color=#0000BB][font=monospace]typeOf player[/font][/color][color=#007700][font=monospace];

player setVariable ["myOldClass", [/font][/color][color=#0000BB][font=monospace]_classname];[/font][/color]

then later in your script that sets it back:

_myoldClass = player getVariable [color=#007700][font=monospace]"myOldClass";[/font][/color]

Share this post


Link to post
Share on other sites

Thanks my man, I'll take a look.

Any idea on how to retain weapons that you grab out of a crate to follow you between model switches?

Share this post


Link to post
Share on other sites

this is not tested but it should be pretty close, I may have made a small error here or there, but you get the picture.

Put in your script before you change player:

_weparray = weapons player;
_mags = magazines player;
_backpack = typeOf unitBackpack player;
_WeaponsRuckList = getWeaponCargo unitBackpack player;
_MagazinesRuckList = getMagazineCargo unitBackpack player;


_gearArray = [_weparray,_mags,_backpack,_WeaponsRuckList,_MagazinesRuckList];


player setVariable ["savedGear",_gearArray];

Then put this in the script after you change:

_oldGear = player getVariable "savedGear";


_wepons = _oldGear select 0;
_mags = _oldGear select 1;
_backpack = _oldGear select 2;
_wepsbackpack = _oldGear select 3;
_magsbackpack = _oldGear select 4;


removeAllItems player;
removeAllWeapons player;
removeBackpack player;


{player addMagazine _x;} forEach _mags;


{player addWeapon _x;} forEach _wepons;


{player addWeapon _x;} forEach _wepons;


if (count _backpack > 0) then {


   player addBackpack (_backpack select 0);


   if (count _wepsbackpack > 0) then {        
       {(unitBackpack player) addWeaponCargo [_x,1];} forEach _wepsbackpack;
       };


   if (count _magsbackpack > 0) then {
       {(unitBackpack player) addMagazineCargo [_x,1];} forEach _magsbackpack;


       };
};


// This will make sure the correct muzzle is selected on your weapon.

firstmuz = {
  private "_ma";
  _ma = getArray (configFile >> "CfgWeapons" >> _this >> "muzzles");
  if (_ma select 0 != "this") exitWith {_ma select 0};
  _this
};


_primary = primaryWeapon player;
if (_primary != "") then
{
  player selectWeapon (_primary call firstmuz);
};



---------- Post added at 08:50 PM ---------- Previous post was at 08:47 PM ----------

If you use ACE then you will have to change the backpack stuff a little, but if you need help with that just let me know.

Share this post


Link to post
Share on other sites

There seems to be something wrong with the localization of the setPlayer with the model switching... Any ideas?

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  

×