[SOLVED] Add ammo for randomly selected weapon?

4 posts in this topic

I'm using BetterDeadThanZed's script for a random uniform and loadout.  I have edited it to give a weapon and ammo instead of food.

At the moment I've only got one weapon in the array and the ammo to go in it, in another. I would like to have a longer list of weapons in the array and then add 2 magazines for the chosen weapon.  Is there an easy way to have relevant ammo added once a weapon is selected?



 * ExileServer_object_player_network_createPlayerRequest
 * Exile Mod
 * © 2015 Exile Mod Team
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit
_sessionID = _this select 0;
_parameters = _this select 1;
_requestingPlayer = _sessionID call ExileServer_system_session_getPlayerObject;

_bambiuniforms = [
] call BIS_fnc_selectRandom;
_bambiammo = ["16Rnd_9x21_Mag","16Rnd_9x21_Mag"] call BIS_fnc_selectRandom;
_bambiweapon = ["hgun_PDW2000_F","hgun_PDW2000_F"] call BIS_fnc_selectRandom;

    if (isNull _requestingPlayer) then 
        throw format ["Session %1 requested a bambi character, but does not have a player object. Hacker or Monday?", _sessionID];
    _spawnLocationMarkerName = _parameters select 0;
    _playerUID = getPlayerUID _requestingPlayer;
    if(_playerUID isEqualTo "")then
        throw format ["Player: '%1' has no player UID. Arma/Steam sucks!.",name _requestingPlayer];
    _accountData = format["getAccountStats:%1", _playerUID] call ExileServer_system_database_query_selectSingle;
    _group = call ExileServer_system_group_getOrCreateLoneWolfGroup;
    _bambiPlayer = _group createUnit ["Exile_Unit_Player", [0,0,0], [], 0, "CAN_COLLIDE"];
    _bambiplayer forceadduniform _bambiuniforms;
    _bambiplayer addMagazine _bambiammo;
    _bambiplayer addWeapon _bambiweapon;
    _bambiplayer addMagazine _bambiammo;
        _cargoType = _x call ExileClient_util_cargo_getType;
        switch (_cargoType) do
            case 1:     { _bambiPlayer addItem _x; };
            case 2:     { _bambiPlayer addWeaponGlobal _x; };
            case 3:     { _bambiPlayer addBackpackGlobal _x; };
            case 4:        { _bambiPlayer linkItem _x; };
            default                     { _bambiPlayer addItem _x; };
    forEach getArray(configFile >> "CfgSettings" >> "BambiSettings" >> "loadOut");
    [_sessionID, _requestingPlayer, _spawnLocationMarkerName, _bambiPlayer, _accountData] call ExileServer_object_player_createBambi;
    _exception call ExileServer_util_log;

Thanks in advance.

Edited by StonedReality

Share this post

Link to post
Share on other sites

The BIS_fnc_addWeapon function, might give you some hints. Look into the "// Add maganzines" part here:

	File: addWeapon.sqf
	Author: Mika Hannola
	Add a weapon to a unit with the right magazines. Magazine class is fetched from the weapon's config.
	_this select 0: <object> unit that is issued new equipment
	_this select 1: <string> weapon classname
	_this select 2: <scalar> number of magazines
	_this select 3 (Optional): <scalar> index of magazine class in weapon's config (default 0) OR <string> magazine classname
	Primary muzzle name for a followup selectWeapon.
	How to use:
	_muzzle = [player, "arifle_SDAR_F", 6] call BIS_fnc_addWeapon;
	Equips the player with an underwater rifle and six dual purpose magazines.
	_muzzle = [player, "arifle_SDAR_F", 6, 1] call BIS_fnc_addWeapon;
	_muzzle = [player, "arifle_SDAR_F", 6, "30Rnd_556x45_Stanag"] call BIS_fnc_addWeapon;
	Equips the player with an underwater rifle and six normal magazines.

private ["_unit", "_weapon", "_magazineCount", "_magazineClass", "_weaponExists", "_magazines", "_i", "_muzzles", "_muzzle"];

_unit = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_weapon = [_this, 1, "", [""]] call BIS_fnc_param;
_magazineCount = [_this, 2, 0, [0]] call BIS_fnc_param;
_magazineClass = [_this, 3, 0, [0, ""]] call BIS_fnc_param;
_weaponExists = isClass (configFile / "CfgWeapons" / _weapon);

//Add magazines
if (_magazineCount > 0) then
	if (typeName _magazineClass == typeName 0) then
		_magazines = getArray (configFile / "CfgWeapons" / _weapon / "magazines");
		if (count _magazines > 0 && _weaponExists) then
			_magazineClass = _magazines select (_magazineClass min (count _magazines - 1));
			_magazineClass = "";
	if (isClass (configFile / "CfgMagazines" / _magazineClass)) then
		for "_i" from 1 to _magazineCount do
			_unit addMagazine _magazineClass;

_muzzle = "";
if (_weaponExists) then
	//Add weapon if unit doesn't have it yet
	if !(_weapon in weapons _unit) then
		_unit addWeapon _weapon;
	//Determine right muzzle name
	_muzzles = getArray (configFile / "CfgWeapons" / _weapon / "muzzles");
	_muzzle = if (_muzzles select 0 == "this") then {_weapon;} else {_muzzles select 0;};



Edited by [RG] Salutesh
1 person likes this

Share this post

Link to post
Share on other sites
4 hours ago, StonedReality said:

Solved.  Will release the files in the scripts section.

I am glad you made it!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.