Home   Help Search Login Register  

Author Topic: [SOLVED] How to convert ammo to another type  (Read 2497 times)

0 Members and 1 Guest are viewing this topic.

Offline AlteredBeast

  • Members
  • *
[SOLVED] How to convert ammo to another type
« on: 30 Jan 2012, 21:19:52 »
Hi everyone. First of all, sorry for my bad english, I don't speak it very well. Second, this is one of the best games I ever played, and I'm glad to see that the community isn't dead !

I have somes question about a little modification I'm trying to do. It consist on offer player's choice for removing/adding a silencer for a handgun (a colt 1911 for precision) during the battlefield (I mean not in the briefing screen but directly in game).

I succed for switching between the "1911 classic" to "1911 silenced", but I'm stuck with the ammo, because they haven't the same type. I try to do addmagazine or removemagazine, but this way I've got infinite ammo everytime I switch, and is not the point...

Maybe I must use a script with a loop to count and add/remove the magazines, but I don't know how to do, because I'm a very beginner at programmation.

So, please, someone can explain me, what can I do to convert the ammo everytime I switch, to have the same magazines numbers (not more, not less)?

Thanks for all possible help ! :D
« Last Edit: 31 Jan 2012, 05:15:14 by AlteredBeast »

Re: How to convert ammo to another type
« Reply #1 on: 30 Jan 2012, 22:17:53 »
Hi, welcome to OFPEC! :)

   If I understood correct, you want a script that makes you get same number of magazines every time you switch from "normal" gun to "silenced" gun (and viceversa of course). I guess you perform switch via "action menu".

   Well... You should look for weapon and magazines names in "config.cpp" file which you can find inside addon file and you should also take note of number of the bullets each magazine can hold. I can teach you how to make this script but, since I don't know real names of those magazines and weapons and I don't know how many bullets make one magazine, I will use fake names and fake number which you have to manually replace with correct ones by yourself.

   Here is an example of script you may need when switching from NORMAL pistol to SILENCED pistol. I call normal pistol "Colt" and silenced pistol "ColtS"; I call normal magazine "ColtMag" and silenced magazine "ColtSMag"; I consider each magazine holding 7 bullets.

Code: [Select]
; Check how many bullets left
_ammo = player ammo "ColtMag"

; Player has 0 bullets left so it means player has no magazine left
? (_ammo == 0) : player removeMagazines "ColtMag"; goto "addPistol"

; Player has a minimum of 1 and a maximum of 7 bullets left so it means player has 1 magazine left
? (_ammo >= 1) and (_ammo <= 7) : player removeMagazines "ColtMag"; player addMagazine "ColtSMag"; goto "addPistol"

; Player has a minimum of 8 and a maximum of 14 bullets left so it means player has 2 magazines left
? (_ammo >= 8) and (_ammo <= 14): player removeMagazines "ColtMag"; player addMagazine "ColtSMag"; player addMagazine "ColtSMag"; goto "addPistol"

; Player has a minimum of 15 and a maximum of 21 bullets left so it means player has 3 magazines left
? (_ammo >= 15) and (_ammo <= 21): player removeMagazines "ColtMag"; player addMagazine "ColtSMag"; player addMagazine "ColtSMag"; player addMagazine "ColtSMag"; goto "addPistol"

; Player has a minimum of 22 and a maximum of 28 bullets left so it means player has 4 magazines left
? (_ammo >= 22) and (_ammo <= 28): player removeMagazines "ColtMag"; player addMagazine "ColtSMag"; player addMagazine "ColtSMag"; player addMagazine "ColtSMag"; player addMagazine "ColtSMag"; goto "addPistol"

#addPistol
; Removing normal pistol
player removeWeapon "Colt"

; Adding silenced pistol
player addWeapon "ColtS"
player selectWeapon "ColtS"

; End of script
exit

   Even if you have 8 bullets left, you will still get two full magazines and you cannot prevent that because it is limit of Cold War Assault game...

   To switch from SILENCED pistol to NORMAL pistol, you can copy the same script above by taking care of replacing every name accordingly.

   If I solved your question, please don't forget to add [SOLVED] before thread name.

Cheers! ;)
« Last Edit: 31 Jan 2012, 00:53:55 by Doktor Headshot »
? (this == thinkable) : this = scriptable

Offline AlteredBeast

  • Members
  • *
Re: How to convert ammo to another type
« Reply #2 on: 30 Jan 2012, 23:24:31 »
Great thanks to you Doktor Headshot, but sadly, at my amazing it don't work  :confused:

Now, always I switch the silencer in both ways, I've got 0 bullets. Don't know why, but it remove all my magazines ??? (even if I have 4 mags before I switch)
Like it the count return 0 even if I'm full, is weird...

Re: How to convert ammo to another type
« Reply #3 on: 31 Jan 2012, 02:47:06 »
Quote
Great thanks to you Doktor Headshot, but sadly, at my amazing it don't work  :confused:
  Sorry, it was my mistake :o. Now, I tested script with Glock and GlockS and it works well. I also added actions that enable/disable themselves accordingly to situation. First of all, make a new "init.sqs" file and copy/paste following lines into your init file (which you should save in your mission folder):

Code: [Select]
? (player hasWeapon "Glock") : action1 = player addAction ["Suppresser ON", "switch1.sqs"]
? (player hasWeapon "GlockS") : action2 = player addAction ["Suppresser OFF", "switch2.sqs"]

   Here you are correct script in order to switch from SILENCED pistol NORMAL pistol and you save it as "switch2.sqs" file:

Code: [Select]
; TAKING SUPPRESSER OFF

; Remove old action
player removeAction action2

; Check how many magazines are left and then remove them
_magazines = {_x == "GlockSMag"} count magazines player
player removeMagazines "GlockSMag"

; Player has 4 magazines left
? (_magazines == 4) : player addMagazine "GlockMag"; player addMagazine "GlockMag"; player addMagazine "GlockMag"; player addMagazine "GlockMag"; goto "addPistol"

; Player has 3 magazines left
? (_magazines == 3) : player addMagazine "GlockMag"; player addMagazine "GlockMag"; player addMagazine "GlockMag"; goto "addPistol"

; Player has 2 magazines left
? (_magazines == 2) : player addMagazine "GlockMag"; player addMagazine "GlockMag"; goto "addPistol"

; Player has 1 magazine left
? (_magazines == 1) : player addMagazine "GlockMag"; goto "addPistol"

#addPistol
; Remove old pistol
player removeWeapon "GlockS"

; Add new pistol
player addWeapon "Glock"
player selectWeapon "Glock"

; Add new action
action1 = player addAction ["Suppresser ON", "switch1.sqs"]

; End of script
exit

   As I wrote before, you cannot prevent fully refilling a magazine when switching between guns because it is limit of Cold War Assault game. I think the only work-around could be to allow switching action only when it involves full magazines and, if magazine is not full, to force player to reload a magazine before switching it; however, this will end with the player unable to switch between guns when last magazine has less bullets than it can hold.

   To switch from NORMAL pistol to SILENCED pistol, you can copy the same script above by taking care of replacing every name accordingly. To avoid confusion, I attached example mission file. Don't forget to replace "Glock" and "GlockS" with the correct name of Colt 1911!

   If I solved your question, please don't forget to add [SOLVED] before thread name.

Cheers! ;)
« Last Edit: 31 Jan 2012, 02:52:47 by Doktor Headshot »
? (this == thinkable) : this = scriptable

Offline AlteredBeast

  • Members
  • *
Re: How to convert ammo to another type
« Reply #4 on: 31 Jan 2012, 03:49:02 »
You are awesome, thanks again for your help it works!  :clap:

Too bad that the "ammo" command don't work with hand guns, I noticed that corrected the infinite ammo when switching adding/removing the supressor, specially when we've got 0 rounds and magazines, and by magic we've got another magazine.


EDIT :
Ok, I think i've got the key for fix that problem. Sorry to bother you again but, do you know if it's possible to remove one magazine always we perform the action "reloading" ? That would be great.
« Last Edit: 31 Jan 2012, 04:32:29 by AlteredBeast »

Re: [SOLVED] How to convert ammo to another type
« Reply #5 on: 31 Jan 2012, 11:29:18 »
Quote
You are awesome, thanks again for your help it works! :clap:
I am glad to hear that ;)

Quote
Too bad that the "ammo" command don't work with hand guns, I noticed that corrected the infinite ammo when switching adding/removing the supressor, specially when we've got 0 rounds and magazines, and by magic we've got another magazine.
I would like to point that "ammo" command works with every weapon and handguns are also supported. You may check it, just for fun, by using a radio trigger with following line in the activation field and comparing what you read in the box with what you read in the top left of corner showing ammo and magazines left:

Code: [Select]
hint format ["%1", player ammo "GlockSMag"]
Problem is that "ammo" command only shows (technically "returns") how many ammo are left in the current magazine and don't let you add single ammo like you can do it with single magazine (which make it pretty useless). If you want to know how many ammo remain in your pistol, then you may want to consider eating a bit of math and think about TA = {[(TM - 1) * FA] - CA}
- where "TA" is number of total ammo left in your pistol
- where "TM" is number of total magazine you can determine with the code provided in the previous script
- where "1" refers to the magazine you are using which has limited ammo that you will separately count later
- where "FA" is fixed number of ammo a magazine can hold (e.g. 14 for a silenced Glock)
- where "CA" is number of ammo left in current magazine which you can determine with the code shown above

Quote
Ok, I think i've got the key for fix that problem. Sorry to bother you again but, do you know if it's possible to remove one magazine always we perform the action "reloading" ? That would be great.
Well, I didn't understood clearly what you meant with "reloading". However, I think you may refers either to switching between pistol magazines types or to action you perform via action menu.

- if "reloading" means switching between pistol magazines type, sure you can do it. I guess you want to achieve that, when switching from magazine type to other magazine type, you want ammo in current magazine to get wasted (which add more realism to "reloading" because in real life, if you drop a magazine with some ammo, those ammo will not get magically back in your hands). Well, you can do it by just adding following line after line you use for returning how many magazines remain in your pistol:

Code: [Select]
? (player ammo "GlockS" <= 13) : _magazines = _magazines - 1
so it would look:

Code: [Select]
_magazines = {_x == "GlockSMag"} count magazines player
? (player ammo "GlockS" <= 13) : _magazines = _magazines - 1
player removeMagazines "GlockSMag"

and this way you can switch between magazine types without wasting any ammo when you switch full magazine because, only in this case, you can save your ammo accordingly to Cold War Assault limit.

- if "reloading" means making use of action menu, then you should consider about opening a new thread and post this question there.

Cheers!
« Last Edit: 01 Feb 2012, 20:32:45 by Doktor Headshot »
? (this == thinkable) : this = scriptable

Offline AlteredBeast

  • Members
  • *
Re: [SOLVED] How to convert ammo to another type
« Reply #6 on: 31 Jan 2012, 14:34:31 »
Ok forget about the "reload" thing, I was dreaming because it solves nothing.

Thanks for the last scripts line, it's really good. Perfect :good:

One last thing, and I don't bother you again (I promess). Do you know what line i must put to play "reloading animation" always I switch the supressor ?

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: [SOLVED] How to convert ammo to another type
« Reply #7 on: 31 Jan 2012, 17:18:50 »
Code: [Select]
unitname playmove "HandGunStandReloadMagazine"
That should be it. It could be switchmove instead of playmove. Not sure about that :dunno:
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Re: [SOLVED] How to convert ammo to another type
« Reply #8 on: 31 Jan 2012, 18:06:11 »
Quote
One last thing, and I don't bother you again (I promess).
You don't need feeling like you are bothering me! :) I just think that the cool of OFP editing (and the correct way to learn it) it is to experiment and play around with commands in order to find what they do. When they were first times I got involved with OFP editing, I used to take a look at COMREF but, of course, sometimes I posted here questions to solve my issues with editor and scripting. And those long times ago, people who replied to my post didn't feel bothered at all and, furthermore, they were as kind as much I am trying to be with you now.

Quote
Do you know what line i must put to play "reloading animation" always I switch the supressor ?
What you ask, technically it is to play animation via playmove command. Perhaps it is one of the simplest command OFP can have and it is:

Code: [Select]
player playMove "animation name"
You have three reloading animations for each specific position of player (stand up, crouch and prone) so you need to play these three anims accordingly to those positions but detecting the player's position it is something technically difficult which has also been asked before in this thread (always remember that searching in the old threads via search function can be as much helpful as posting new threads) and which has not been solved yet (AFAIK).

As far as it concerns your question, to prevent player from getting up when putting/removing suppressor (not "suppresser" like I wrongly wrote) by lying and to prevent player from getting down when putting/removing suppressor
by standing up, I think a good compromise it is to play animation which makes player to reload by staying crouched and lines you need to add is:
Code: [Select]
; Force player crouching when putting on suppressor
player playMove "HandGunCrouchReloadMagazine"

otherwise you may want to decide to don't play any animation at all!

Cheers!

ADDED LATER: looks like Gruntage posted answer before me when I was writing! I am happy to see he tought same answer as me, it means I was right!
« Last Edit: 31 Jan 2012, 18:14:33 by Doktor Headshot »
? (this == thinkable) : this = scriptable

Offline AlteredBeast

  • Members
  • *
Re: [SOLVED] How to convert ammo to another type
« Reply #9 on: 31 Jan 2012, 20:08:40 »
Ok, thanks to you two. I'm learning a lot of things here, it's cool :)