PDA

View Full Version : Some scripting problems [noob question]



milobr
Dec 10 2006, 18:08
Sorry for bothering with this stupid questions, but..

I made a very, very simple script that adds weapons and ammo to any character in-game. It's like that:


Quote[/b] ]this addMagazine "30Rnd_545x39_AK"
this addMagazine "30Rnd_545x39_AK"
this addWeapon "AK74"
exit

But when the character runs it, he only gets the AK without any ammo. Can anyone help me? http://forums.bistudio.com/oldsmileys/huh.gif

Thanks.

Vänskä
Dec 10 2006, 20:19
Sorry for bothering with this stupid questions, but..

I made a very, very simple script that adds weapons and ammo to any character in-game. It's like that:


Quote[/b] ]this addMagazine "30Rnd_545x39_AK"
this addMagazine "30Rnd_545x39_AK"
this addWeapon "AK74"
exit

But when the character runs it, he only gets the AK without any ammo. Can anyone help me? http://forums.bistudio.com/oldsmileys/huh.gif

Thanks.
this addweapon "AK74"; this addMagazine "30Rnd_545x39_AK"

You have to put this on your units init field. If you use it in another context you have to replace "this" with your units name.

milobr
Dec 10 2006, 20:38
But I put "[this] exec "ak74.sqs" in the init field of the units I want to give the AK. They all get the AK, but no ammo. I suppose "this" in the script is replaced by the unit which is executing it, right?

Anyway, thanks for the help. I'll check it out.

Lolsav
Dec 10 2006, 21:14
addweapon command has always have to be placed before the addmagazine command to make it work.

Edit: Oh make sure you start with RemoveAllWeapons this before trying adding new weapons

MrZig
Dec 10 2006, 22:20
addweapon command has always have to be placed before the addmagazine command to make it work.

Edit: Oh make sure you start with RemoveAllWeapons this before trying adding new weapons
No, you are wrong about the placement, although a removeallweapons this certainly helps from manually removing the other mags/weapons.

But you can put addmagazine and should put addmagazine before addweapon. This is because if you put addweapon afterwards, you have to reload. Oh, and makesure to use this at the end.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this switchweapon primaryweapon this[/QUOTE]


Anyways, back to the original dismayimafy.



Quote[/b] ]But I put "[this] exec "ak74.sqs" in the init field of the units I want to give the AK. They all get the AK, but no ammo. I suppose "this" in the script is replaced by the unit which is executing it, right?

Anyway, thanks for the help. I&#39;ll check it out.

Exec your script like this
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">This exec &#34;Ammoscript.sqs&#34;[/QUOTE]
Use this script:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
removeallweapons _this
_this addMagazine &#34;30Rnd_545x39_AK&#34;
_this addMagazine &#34;30Rnd_545x39_AK&#34;
_this addWeapon &#34;AK74&#34;
_this selectweapon &#40;primaryweapon _this&#41;
exit[/QUOTE]

milobr
Dec 10 2006, 22:29
Thanks, MrZig, ir worked. http://forums.bistudio.com/oldsmileys/thumbs-up.gif