Home   Help Search Login Register  

Author Topic: Replacing inventory  (Read 428 times)

0 Members and 1 Guest are viewing this topic.

Offline KTottE

  • Former Staff
  • ****
Replacing inventory
« on: 17 Jul 2003, 21:00:35 »
Okay, help :)

Code: [Select]
mag1="M16"
nmag1="M4"
mag2="M4"
nmag2="M16"
prigun1="M16"
nprigun1="M4"
prigun2="M4"
nprigun2="M16"

_player = _this select 0
hint format ["%1",magazines _player]
_magazines = magazines _player
_newmags = []
_i = 0
_j = count _magazines
#loop
?(_magazines select _i) == mag1 : _newmags set [_i,nmag1]
?(_magazines select _i) == mag2 : _newmags set [_i,nmag2]
_i = _i + 1
?(_i > _j) : goto "replace"
goto "loop"

#replace
_weapon = primaryweapon _player
_newgun = ""

_player removeweapon primaryweapon _player
_player removemagazines _weapon


?(_weapon) == prigun1 : _newgun = nprigun1
?(_weapon) == prigun2 : _newgun = nprigun2
hint format ["%1\n%2\n%3\n%4",_magazines,_newmags,_weapon,_newgun]

"_player addmagazine _x" foreach _newmags
_player addweapon _newgun
_player selectweapon _newgun
exit

I have the above code (big thanks to TheCaptain) and it works flawlessly. What it does is it switches the M16 for the XM-177, and all M16 mags for XM-ones. I've also tried switching an AK74 for an AK47.

Now, when I try this with my own addon however (which is the reason I want/need the script), it doesn't work. What happens is it doesn't remove the current mags, so they stay there (doubling the amount of mags).
Now, I don't know why this is, but I had a theory that it's because my mag-names differ from the weapon-names. I.E the M16 is called the M16 and the M16 mags are called M16, but mine don't work like that.
So I was wondering if anyone could like, show me to where the problem lies, or write a better script, I'd be very much pleased.
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

peter

  • Guest
Re:Replacing inventory
« Reply #1 on: 17 Jul 2003, 21:59:38 »
donÂ't have resistance, but your problem is:

_player removemagazines _weapon
(works only if the mags name is the same as the weapons ...)

use instead:

?(_weapon) == prigun1 : _player removemagazines mag1
?(_weapon) == prigun2 : _player removemagazines mag2

Offline KTottE

  • Former Staff
  • ****
Re:Replacing inventory
« Reply #2 on: 17 Jul 2003, 22:01:07 »
Gawd I'm stupid.
I'm too tired from working with my .cpp all day, I didn't even spot that one :)
Thanks mate ;D

edit

Okay, now I have a little problem :)

I've got three kinds of weapons that I use this on, it works flawless on two of them (M203 and Masterkey versions btw) but on the first one (Bipod) it doesn't do anything about mag3 and mag4 that I've added. All the scripts I use for this are identical apart from the names of the weapons and magazines, and I just triple checked the names in the script used for the bipod version, and it's accurate, so, any ideas?
« Last Edit: 20 Jul 2003, 21:54:22 by KTottE »
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"