Jump to content
Sign in to follow this  
Nutlink

Using BIS_fnc_addRespawnInventory for different units

Recommended Posts

I've tried searching for something like this, but I can't seem to find it anywhere. Anywho, here's my dilemma. I have 7 units placed down. I'd like each of those units to have their own list of preset kits to choose from, but only for that particular unit. Looking at the Biki for this it shows it should work with objects, however I can't seem to get it to work. This is what I have in a script executed via init.sqf:

[west, "Rifleman1"] call BIS_fnc_addRespawnInventory;
[west, "Grenadier1"] call BIS_fnc_addRespawnInventory;
[west, "Marksman1"] call BIS_fnc_addRespawnInventory;
[west, "Medic1"] call BIS_fnc_addRespawnInventory;
[west, "UAV1"] call BIS_fnc_addRespawnInventory;
[west, "Lead1"] call BIS_fnc_addRespawnInventory;
[west, "AutoRifleman1"] call BIS_fnc_addRespawnInventory;

However, if I put this code in the init of a unit and replace west with this, it works just fine. I'd rather not do it that way because I plan on having multiple kits for each unit (and I'm trying to avoid being overly sloppy about it). I've tried replacing west with the units name and the units class, with and without quotes, in the script without success. I'm pretty sure it works because if I leave it at west, everyone is able to select the kits and I get zero script errors with -showScriptErrors on.

Note I actually have more than this (ex Rifleman2, Rifleman3, Marksman2, Marksman3, etc etc) but I cut it out for testing.

I'm sorry if this has been asked before, but like I said I cannot seem to find anything about it. Here is the Biki page for reference:

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

Share this post


Link to post
Share on other sites

Here is how I do it ... YMMV

if (player isKindOf "B_medic_F") then {
[player,"Medic1"] call BIS_fnc_addRespawnInventory;
};

or

if (player isKindOf "B_medic_F" || player isKindOf "B_recon_medic_F") then {
[player,"Medic1"] call BIS_fnc_addRespawnInventory;
};

or

_medics = ["B_medic_F","B_recon_medic_F","B_G_medic_F"];
if (((player isKindOf _x) count _medics) > 0) then {
_medicInventories = ["Medic1","Medic2","Medic3"];
{[player,_x] call BIS_fnc_addRespawnInventory;} forEach _medicInventories;
};

The last option is the cleanest and most flexible.

Note: I run it on the players machine, not the server machine. It has global effect and I haven't tested that yet. ie. Something that requires testing: Player 1 enters game as medic, loads medic classes. Player 2 enters game as Autorifleman, loads Autorifleman classes. Does global effect of the function also then load the autorifleman classes onto the medic?

Edited by MDCCLXXVI

Share this post


Link to post
Share on other sites

Awesome! I just tested it out, and the first two work just fine, but the last one doesn't seem to want to cooperate. It tells me _x is an undefined variable. I'll mess around with it a little more, and I'll also let you know if it loads for multiple classes and how well it works on a dedicated server over the weekend.

Still, like I said the first two definitely work in initial testing. Thanks!

EDIT 1: Ok, it looks like it works unless you back out to the lobby. Once I did that and selected a different class, it wouldn't give me the option for anything, even if I went back to the same class. I wonder if this could be taken care of via an event handler?

EDIT 2: Also looks like if you back out of a server and rejoin with the mission still in progress it displays only the right kit. I'm guessing it's the way I launch the script.

EDIT 3: Temporarily resolved by doing while loops on a sleep timer. Not a huge deal for the smaller mission, but something to look at later on.

Edited by BOTA:49

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  

×