Jump to content
GamersFortitude

Giving ammo based off random weapons chosen

Recommended Posts

Hi all, Im running a wasteland server with IFA3 and ive got the AI groups that spawn for missions being created with mod weapons, unfortunately they spawned in with no ammo. Looking through the A3 Wiki i found the 'if' statements and based off the SetAmmo command 'example 3' (as below), I made an attempt at giving the AI ammo.


I originally posted this on the A3Wasteland forums but no one has been able to help, let alone reply.
 

if (local vehicle player) then {
    vehicle player setAmmo [currentWeapon vehicle player, 5];
} else {
    hint "Vehicle must be local to this machine for 'setAmmo' to work";
};

 

I grabbed the code and tried to modify it so it grabs the current weapon and gives the appropriate ammo class.

I originally based it off the uniform, and i had this in the code

if (uniform _soldier isequalto _usrifleman) then 
(	
	_solder addMagazine "LIB_15Rnd_762x33_t";
	_solder addMagazine "LIB_15Rnd_762x33_t";
	_solder addMagazine "LIB_15Rnd_762x33_t";
	_solder addWeapon "LIB_M1_Carbine";
);

Having the above code in the file resulted in the below error. So i removed it and tried a different method.

 0:40:26 File mpmissions\__cur_mp.malden\server\missions\factoryMethods\createUnits\createRandomSoldierC.sqf..., line 33
 0:40:26 Error in expression <_solder addMagazine "LIB_15Rnd_762x33_t";
_solder addMagazine "LIB_15Rnd_762x33_>
 0:40:26   Error position: <;
_solder addMagazine "LIB_15Rnd_762x33_>

What you see below is what i attempted , starting at "If currentweapon _soldier =" (fig.2)

I only did a few to test to see if it works. But alas it does not.


(fig.2)
 

// ******************************************************************************************
// * This project is licensed under the GNU Affero GPL v3. Copyright © 2014 A3Wasteland.com *
// ******************************************************************************************
//    @file Name: createRandomSoldierC.sqf

if (!isServer) exitWith {};

private ["_soldierTypes", "_weaponTypes", "_group", "_position", "_soldier"];

_soldierTypes = ["LIB_US_rifleman", "LIB_US_FC_rifleman", "LIB_US_smgunner", "LIB_SOV_rifleman", "LIB_SOV_LC_rifleman","LIB_SOV_scout_smgunner", "LIB_GER_rifleman", "LIB_GER_ober_rifleman", "LIB_GER_mgunner"];
_weaponTypes = ["LIB_P38","LIB_MP40","LIB_K98","LIB_G43","LIB_TT33","LIB_M9130","LIB_M1895","LIB_PPSh41_m","lib_f1","LIB_M1A1_Thompson","LIB_M1_Carbine","LIB_M1_Garand","LIB_Colt_M1911","LIB_US_Mk_2"];
_group = _this select 0;
_position = _this select 1;
_soldier = _group createUnit [_soldierTypes call BIS_fnc_selectRandom, _position, [], 0, "NONE"];
[_soldier, _weaponTypes call BIS_fnc_selectRandom, 3] call BIS_fnc_addWeapon;

//if (currentWeapon _soldier = LIB_P38) then setAmmo [LIB_8Rnd_9x19 _solder, 10];

if (currentWeapon _soldier = LIB_P38) then
{
    _solder setAmmo [LIB_8Rnd_9x19 _solder, 5];
}
else if (currentWeapon _soldier = LIB_MP40) then
{
    _solder setAmmo [LIB_32rnd_9x19 _solder, 5];
{    
else if (currentWeapon _soldier = LIB_K98) then
{
    _solder setAmmo [LIB_5Rnd_792x57 _solder, 5];
};
/* // Unsure about this & disabled
switch (_condition) do
{
    case 1: {if (currentWeapon _soldier = LIB_P38) then setAmmo [LIB_8Rnd_9x19 _solder, 10]};
    case 2: {if (currentWeapon _soldier = LIB_MP40) then setAmmo [LIB_32rnd_9x19 _solder, 10]};
}
*/
_soldier call setMissionSkill;

_soldier addEventHandler ["Killed", server_playerDied];

_soldier

I decided to look into the switch command but im still learning with that aspect, thats why it's disabled.

Is there anything i can do otherwise to get the appropriate ammo given to the AI?

On a side note, a3wasteland comes with a "refilPrimaryAmmo" which only seems to work for mods that actually have a cfg file, where as IFA3 does not. Hense my attempt at giving ammo.

 

Thanks to anyone who can help with this matter.

 

Share this post


Link to post
Share on other sites

Good morning!

Here is my suggestion: 

 

description.ext: (to load the function)

class CfgFunctions {
  class JF {
    class Wasteland {
      class createRandomSoldierC {file = "createRandomSoldierC.sqf"};
    };
  };
};

 

initServer.sqf: (i am not sure in what context you are calling the function, but i highly recommend you to call the function within initServer.sqf or one of it's functions)

[createGroup east, [4831,5112,0]] spawn JF_fnc_createRandomSoldierC; //creates one random unit

 

createRandomSoldierC.sqf:

params ["_group", "_position"];

private _soldierTypes = ["LIB_US_rifleman", "LIB_US_FC_rifleman", "LIB_US_smgunner", "LIB_SOV_rifleman", "LIB_SOV_LC_rifleman","LIB_SOV_scout_smgunner", "LIB_GER_rifleman", "LIB_GER_ober_rifleman", "LIB_GER_mgunner"];
private _weaponTypes = ["LIB_P38","LIB_MP40","LIB_K98","LIB_G43","LIB_TT33","LIB_M9130","LIB_M1895","LIB_PPSh41_m","lib_f1","LIB_M1A1_Thompson","LIB_M1_Carbine","LIB_M1_Garand","LIB_Colt_M1911","LIB_US_Mk_2"];

private _soldier = _group createUnit [selectRandom _soldierTypes, _position, [], 0, "NONE"];


private _oldMagazinesP = [primaryWeapon _soldier] call BIS_fnc_compatibleMagazines;
private _oldMagazinesS = [secondaryWeapon _soldier] call BIS_fnc_compatibleMagazines;
removeAllWeapons _soldier;

{
  for [{_i = 0}, {_i < count _x}, {_i = _i+1}] do {
    _soldier removeMagazines (_x select _i);
  };
} forEach [_oldMagazinesP, _oldMagazinesS];


_soldier addWeapon (selectRandom _weaponTypes);
private _magazine = ([(weapons _soldier) select 0] call BIS_fnc_compatibleMagazines) select 0;
_soldier addMagazines [_magazine, 3]; //adds 3 mags to the unit


_soldier call setMissionSkill; //not sure if that's right
_soldier addEventHandler ["Killed", server_playerDied]; //same here

_soldier //do you really need to return the unit? I'd work with it in this file or at least create all units here and return the group

I'd also define _soldierTypes and _weaponTypes somewhere else to make it easier to edit later on.

 

(I got an error at some time. Double check your weapon classnames, one might be wrong. Maybe it was me and it's allready fixed. Don't know ^^)

Share this post


Link to post
Share on other sites

Thanks for that, yeah the file is called in other files when missions get created. i'll modify the file in the weekend and see if that works.

 

Thank you.

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

×