OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: fleepee on 25 Feb 2009, 09:02:48

Title: give back a weapon to AIs after swim!
Post by: fleepee on 25 Feb 2009, 09:02:48
Hi everybody!
I need a small script to give back weapons and ammo to AIs after their swimming...
I know one that works great with players, but not with AIs...
I've tried doing it myself, but definetely, i'm not a talented scripter! ::)
Thanks!! :good:

Here is what i've done as I don't care of the type of weapon, I just don't want to see unarmed AIs:
Created a trigger with in the activation line:
Code: [Select]
{[_x] exec "addweapons.sqs"} forEach units groupone
Then a small script:
Code: [Select]
? !isServer : exit

_unit = _this select 0
?!(_unit hasWeapon) then goto "add"

#add
_unit addweapon "AK74";
_unit addMagazine "30Rnd_545x39_AK";
_unit addMagazine "30Rnd_545x39_AK";
_unit addMagazine "30Rnd_545x39_AK";
_unit addMagazine "30Rnd_545x39_AK";
_unit addMagazine "30Rnd_545x39_AK";
_unit addMagazine "30Rnd_545x39_AK";
exit

And I've got that message: (see picture)
I really don't know why!
And when I test it, the AIs get the corect number of magazines...
Help!!
Title: Re: give back a weapon to AIs after swim!
Post by: Spooner on 26 Feb 2009, 18:28:15
You are using hasWeapon and then incorrectly (?: is one way, if-then-else is another).

If you want a more complex method, that saves the whole inventory, you could look at SPON Scuba (http://www.ofpec.com/forum/index.php?topic=32442.0). Couldn't find a simple solution at OFPEC, but searching at Armaholic  (http://www.armaholic.com/page.php?id=830)works for me.
Title: Re: give back a weapon to AIs after swim!
Post by: fleepee on 26 Feb 2009, 20:10:23
 ;) thanks for your help!
But it's not a simple script...
SO I modified mine:
Code: [Select]
? !isServer : exit
_unit = _this select 0
_mag= "30Rnd_545x39_AK"
_weapon= "ak74"
?(primaryWeapon _unit == "") : goto "add"

#add
_unit addMagazine _mag
_unit addMagazine _mag
_unit addMagazine _mag
_unit addMagazine _mag
_unit addMagazine _mag
_unit addMagazine _mag
_unit addweapon _weapon
exit

The error message was a consequence of my init file...
Seems ok, AI that swam gets an AK74 when the script is triggered