Jump to content
Sign in to follow this  
Eatingyou

addWeapon Problems, no RPT file

Recommended Posts

I have got some problems with my script to spawn random npcs on a random marker and with random weapons and random magazines. The random Npcs on the random positions are working fine, but i can't figure out, how to use the addWeapon and addMagazine comand in the initialisation line of the spawned npcs. I removed the default weapons with the removeAllWeapons comand. The point of my plan with this script is, to randomize the amount of magazines of the npcs. Please post some ideas how to get this script working with a random amount of magazines.

_GrpTwo = createGroup EAST;

_skill = random 1;
if (_skill <= 0.3) then {_skill = _skill + 0.3};

Hint "Die Russen kommen!!!";

_spawnArray = ["AI1","AI2","AI3"];
_enemyArray = ["RU_Soldier","RU_Soldier_Medic","RU_Soldier_MG","RU_Soldier_Sniper","RU_Soldier_AT","RU_Soldier_GL","RU_Soldier_Officer","RU_Soldier2","RU_Soldier_Marksman","RU_Soldier","RU_Soldier2"];

_spawn = _spawnArray select (floor (random (count _spawnArray)));
_enemy = _enemyArray select (floor (random (count _enemyArray)));

_unit = _GrpTwo createUnit [_enemy, getMarkerPos _spawn,[],0, "FORM"];
_unit setrank "PRIVATE";
_unit setskill _skill;
removeAllWeapons _unit;
removeAllItems _unit;
sleep 0.1;
nul = [_unit] execVM "Scripts\Spawn\RU Kits\Kits.sqf";

Scripts\Spawn\RU Kits\Kits.sqf

private ["_unit"];
_unit = this select 0;
hint "Los";


_kit1 = ["AK_107_kobra", "30Rnd_545x39_AK"];
_kit2 = ["SVD", "10Rnd_762x54_SVD"];
_kit3 = ["RPK_74", "75Rnd_545x39_RPK"];

_kitArray = [_kit1, _kit2, _kit3];

hint "1";
_kit = _kitArray select (floor (random (count _kitArray)));

_weapon = _kit select 0;
_magazine = _kit select 1;
hint "2";
_unit addWeapon _weapon;

amnt = ceil (random 3);
counter = 0;

while{counter <= amnt} do {
  _unit addmagazine _magazine;
  counter = counter +1;};
  hint "3";

Share this post


Link to post
Share on other sites

I got the same problem not sure, what the problem was, never found a reason, maybe something with the primary Weapon.

Anyone else maybe know?

Share this post


Link to post
Share on other sites

You're using a nested array and not selecting it properly. Think of it like this. _kitArray equals the following:

_kitarray = [["AK_107_kobra", "30Rnd_545x39_AK"],["SVD", "10Rnd_762x54_SVD"],["RPK_74", "75Rnd_545x39_RPK"]]; 

Now let's say the randomization gets 0, so you select 0. Now _kitArray is essentially this:

_kitArray = [["AK_107_kobra", "30Rnd_545x39_AK"]];

Another select 0 wouldn't worl because you'd just keep selecting the nested array. The workaround here is to use another select in conjunction with the first select, like this:

_kitArray = [["AK_107_kobra", "30Rnd_545x39_AK"]];
_kit = (_kitArray select 0) select (floor(random(count _kitArray)));

This should select the first array in _kitArray (which is the nested array) and then proceed to select a random entity out of that. You might have to do the randomization in another variable though as _kitArray essentially equals 0 (due to 1 nested array present).

Share this post


Link to post
Share on other sites

@tryteyker thanks for your help but if i use your idea in my script

private ["_unit"];
_unit = this select 0;
hint "Los";


_kit1 = ["AK_107_kobra", "30Rnd_545x39_AK"];
_kit2 = ["SVD", "10Rnd_762x54_SVD"];
_kit3 = ["RPK_74", "75Rnd_545x39_RPK"];

_kitArray = [_kit1, _kit2, _kit3];

hint "1";
_kit = _kitArray select (floor (random (count _kitArray)));

_weapon = (_kit select 0) select 0;
_magazine = (_kit select 0) select 1;
hint "2";
_unit addWeapon _weapon;

amnt = ceil (random 3);
counter = 0;

while{counter <= amnt} do {
  _unit addmagazine _magazine;
  counter = counter +1;};
  hint "3";

i get this error messege and the unit stil hasn't got a gun:

Error in expression <kitArray)));

_weapon = (_kit select 0) select 0;

_magazine = (_kit select 0) se>

Error position: <select 0;

_magazine = (_kit select 0) se>

Error select: Type String, expected Array,Config entry
File C:\Users\Lennart\Documents\ArmA 2 Other Profiles\Eatingyou\missions\ALONE.Shapur_BAF\Scripts\Spawn\RU Kits\Kits.sqf, line 15

Maybe i didn't understood your idea as you ment it so I hope you can explain your idea a little bit more precise for my script if i was doing it wrong.

Share this post


Link to post
Share on other sites

Possibly something like this?

_unit = this select 0;

WepArray =
[
["AK_107_kobra", "30Rnd_545x39_AK"],
["SVD", "10Rnd_762x54_SVD"],
["RPK_74", "75Rnd_545x39_RPK"]
];

_kit1Wep = (WepArray select 0) select 0);
_kit1Mag = (WepArray select 0) select 1);

_kit2Wep = (WepArray select 1) select 0);
_kit2Mag = (WepArray select 1) select 1);

_kit3Wep = (WepArray select 2) select 0);
_kit3Mag = (WepArray select 2) select 1);

KitArray = 
[
[_kit1Wep,_kit1Mag],
[_kit2Wep,_kit2Mag],
[_kit3Wep,_kit3Mag]
];

_randKit = floor (random (count KitArray));
_wep = (KitArray select _randKit) select 0);
_ammo = (KitArray select _randKit) select 1);

_randAmmoAmt = ceil(random 3);
_unit addWeapon _weapon;
_unit addMagazine [_ammo,(_randAmmoAmt)];

Edited by dcthehole
Fix error

Share this post


Link to post
Share on other sites
Possibly something like this?

private["_unit","_kit1Wep","_kit1Mag","_kit2Wep","_kit2Mag","_kit3Wep","_kit3Mag","_randKit","_wep","_ammo","_randAmmoAmt"];
_unit = this select 0;

WepArray =
[
["AK_107_kobra", "30Rnd_545x39_AK"],
["SVD", "10Rnd_762x54_SVD"],
["RPK_74", "75Rnd_545x39_RPK"]
];

_kit1Wep = (WepArray select 0) select 0);
_kit1Mag = (WepArray select 0) select 1);

_kit2Wep = (WepArray select 1) select 0);
_kit2Mag = (WepArray select 1) select 1);

_kit3Wep = (WepArray select 2) select 0);
_kit3Mag = (WepArray select 2) select 1);

KitArray = 
[
[_kit1Wep,_kit1Mag],
[_kit2Wep,_kit2Mag],
[_kit3Wep,_kit3Mag]
];

_randKit = floor (random (count KitArray));
_wep = (KitArray select _rand) select 0);
_ammo = (KitArray select _rand) select 1);

_randAmmoAmt = ceil (random 3);
_unit addWeapon _weapon;
_unit addMagazine [_ammo,(_randAmmoAmt)];

But I think he don't get all these vars you added to private, is he?

Share this post


Link to post
Share on other sites

private is unnecessary if he's not executing code in any kind of loop or statement (or function). So just remove it. Additionally you could return the content of _kitArray like this:

hint format ["%1",_kitArray];

Put this after creating _kitArray.

Share this post


Link to post
Share on other sites
You're using a nested array and not selecting it properly. Think of it like this. _kitArray equals the following:

_kitarray = [["AK_107_kobra", "30Rnd_545x39_AK"],["SVD", "10Rnd_762x54_SVD"],["RPK_74", "75Rnd_545x39_RPK"]]; 

Now let's say the randomization gets 0, so you select 0. Now _kitArray is essentially this:

_kitArray = [["AK_107_kobra", "30Rnd_545x39_AK"]];

Another select 0 wouldn't worl because you'd just keep selecting the nested array. The workaround here is to use another select in conjunction with the first select, like this:

_kitArray = [["AK_107_kobra", "30Rnd_545x39_AK"]];
_kit = (_kitArray select 0) select (floor(random(count _kitArray)));

This should select the first array in _kitArray (which is the nested array) and then proceed to select a random entity out of that. You might have to do the randomization in another variable though as _kitArray essentially equals 0 (due to 1 nested array present).

I may be totally wrong, BUT

_kitarray = [["AK_107_kobra", "30Rnd_545x39_AK"],["SVD", "10Rnd_762x54_SVD"],["RPK_74", "75Rnd_545x39_RPK"]]; 

_kit = _kitarray select 0;

Then _kit IS

["AK_107_kobra", "30Rnd_545x39_AK"]

and not

 
[["AK_107_kobra", "30Rnd_545x39_AK"]]

Sarge, happy to be corrected if the above is wrong.

Share this post


Link to post
Share on other sites

The code looks ok, apart from that you probably better off adding magazines before adding weapon. What's the last hint displayed when you run your script OP?

---------- Post added at 22:17 ---------- Previous post was at 22:14 ----------

Possibly something like this?

_unit = this select 0;

WepArray =
[
["AK_107_kobra", "30Rnd_545x39_AK"],
["SVD", "10Rnd_762x54_SVD"],
["RPK_74", "75Rnd_545x39_RPK"]
];

_kit1Wep = (WepArray select 0) select 0);
_kit1Mag = (WepArray select 0) select 1);

_kit2Wep = (WepArray select 1) select 0);
_kit2Mag = (WepArray select 1) select 1);

_kit3Wep = (WepArray select 2) select 0);
_kit3Mag = (WepArray select 2) select 1);

KitArray = 
[
[_kit1Wep,_kit1Mag],
[_kit2Wep,_kit2Mag],
[_kit3Wep,_kit3Mag]
];

_randKit = floor (random (count KitArray));
_wep = (KitArray select _randKit) select 0);
_ammo = (KitArray select _randKit) select 1);

_randAmmoAmt = ceil(random 3);
_unit addWeapon _weapon;
_unit addMagazine [_ammo,(_randAmmoAmt)];

KitArray will be identical to WepArray, what is the point?

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  

×