Home   Help Search Login Register  

Author Topic: some ammo of primary weapon  (Read 4726 times)

0 Members and 1 Guest are viewing this topic.

Offline 456820

  • Contributing Member
  • **
some ammo of primary weapon
« on: 11 Jun 2005, 10:32:16 »
okay ive got this script
here it is
Code: [Select]
? !someAmmo player : goto "out"
? someAmmo player : goto "exit"

#out
? ammo : goto "ammo2"
player groupchat "Damn im out of ammo"
ammo = true
EXIT

#ammo2
player groupchat "God damn it im out of ammo again"
EXIT
#exit
EXIT

that detects if the player is out of ammo but only out of primary and secondary weapons so im wondering how i can turn it into just primary weapon say the player is out of m16 ammo he says damn im out of ammo for example
how would this be done

Note - im running this through a fired event handler from the players init field if that makes a difference also there is a weapon selection so it cant just be one weapon has to be any primary rifle

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:some ammo of primary weapon
« Reply #1 on: 11 Jun 2005, 10:58:25 »
What about some combination of

unit ammo magazine

and
primaryWeapon vehicle

unit ammo primaryWeapon unit
would be where I would start.  It may need some tweeking to make it work

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #2 on: 11 Jun 2005, 11:37:43 »
ill have a go right now
thanks

EDIT - didnt work i tried
? someammo primaryWeapon player == 0 : goto "out"
and also
player ammo primaryWeapon player :  goto "out"
« Last Edit: 11 Jun 2005, 11:43:31 by 456820 »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:some ammo of primary weapon
« Reply #3 on: 11 Jun 2005, 12:17:42 »
This is a comment on ammo from Gereral Barron in comref:

Quote
Actually, the syntax for this command is incorrect. Really it works like this:

unit ammo muzzle

Where "muzzle" is a weapon's muzzle name. Often this is the same as the weapon's name, but sometimes it is different. Weapons can have multiple muzzles, such as the m16+grenades.

You can find what muzzle you are firing by putting this in the player's init field:
Quote:this addEventHandler ["fired", {hint format [{Muzzle = "%1"}, _this select 2]}];


So you will probably have to use primaryWeapon to find which weapon the unit has then do something like:
_mags = ""
if (unit primaryWeapon == "m16") then {_mags = "m16mag"}
if (unit primaryWeapon == you get the idea
etc.
etc.

then check unit ammo _mags

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:some ammo of primary weapon
« Reply #4 on: 11 Jun 2005, 12:17:49 »
Don't use someammo, it has no usage in this...

Quote
player ammo primaryWeapon player :  goto "out"
? (player ammo (primaryWeapon player)) == 0: goto "out"

This worked in a script I made a while ago..
« Last Edit: 11 Jun 2005, 12:18:42 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #5 on: 11 Jun 2005, 12:58:33 »
ill try both of those ideas thanks
also i thought the command was someammo not just ammo
anyway ill have a go

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #6 on: 12 Jun 2005, 11:05:03 »
HateR_Kint that kind of works but when his mag is emptu then it runs but the player still hs another 3 full mags

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:some ammo of primary weapon
« Reply #7 on: 12 Jun 2005, 11:58:08 »
Ah, I see..
So then you need to check whether the unit has the mags left and then check that ammo too..

So, first you check whether the unit has the mags you want or not and if not, exit and don't go to the ammo check yet, something like:

Code: [Select]
#checkmags
? (primaryWeapon player) in (magazines player): exit
goto "checkammo"

#checkammo
? (player ammo (primaryWeapon player)) == 0: goto "out"
exit

No guarantees whatsoever... :P

Of course that method requires that the magazine is named the same as the weapon itself, like "M16"...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #8 on: 12 Jun 2005, 15:45:24 »
okay thanks ill have a go at it

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #9 on: 16 Jun 2005, 17:45:13 »
right ive had a go with what i have so far and have come up with this

Code: [Select]
#checkmags
? (primaryWeapon player) in (magazines player) : exit
goto "checkammo"

#checkammo
? player ammo primaryWeapon player == 0 : goto "out"

#out
? ammo : goto "out2"
ammo = true
player groupchat "DAMN IM OUT OF AMMO"

#out2
if (50 > random 100) then {player groupchat "GOD DAMN IM OUT AGAIN!"} else {player groupchat "DAMN I NEED MORE AMMO"}

exit

but it doesnt work but were close the line that doesnt work is
Code: [Select]
? player ammo primaryWeapon player == 0 : goto "out"even though not long ago it worked perfectly but not now for some weird reason doe anyone know why ?
It says something like

Code: [Select]
? player #ammo primaryWeapon player == 0 : goto "out" : error unknown operator ammoso the command ammo is wrong but i checked in the com ref and it should work

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #10 on: 16 Jun 2005, 17:52:40 »
look again at hateR_kint's syntax -

Code: [Select]
? (player ammo (primaryWeapon player)) == 0: goto "out"
can anyone say 'brackets'?

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #11 on: 16 Jun 2005, 18:05:20 »
thanks but that doesnt work though it just kind of skips that line and carry's on with the script even though hes only shot one round so i start getting my out of ammo messages when ive got ammo ?

EDIT - next time i tried i got the unknown operator message on the command ammo
« Last Edit: 16 Jun 2005, 18:11:07 by 456820 »

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #12 on: 17 Jun 2005, 17:52:58 »
Quote
_player = _this select 0
_ammo = _this select 2

#checkmags
? (primaryWeapon player) in (magazines player) : exit
goto "checkammo"

#checkammo
? _player ammo _ammo == 0 : goto "out"

#out
? ammo : goto "out2"
ammo = true
player groupchat "DAMN IM OUT OF AMMO"

#out2
if (50 > random 100) then {player groupchat "GOD DAMN IM OUT AGAIN!"} else {player groupchat "DAMN I NEED MORE AMMO"}

exit

ive now tried this script but still unkown operator ammo and ive resulteed in trying the variables such as _ammo = _this select 2
but still no luck for some reason plus im not to sure if the magazine count is working as it just carry's on through the script when ive got 4 mags left ?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #13 on: 17 Jun 2005, 18:47:00 »
will this always involve an m16? or is this script going to be called for a unit who may have any type of weapon?

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #14 on: 17 Jun 2005, 18:51:09 »
different types i have a list of the weapons if needed
oh well why not

Beretta
Binocular
HK
LAWLauncher
M16
M21
Steyr

that should be all of them

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #15 on: 17 Jun 2005, 19:17:15 »
right. so as stated by hateR_kint above

Quote
this requires that the magazine is named the same as the weapon itself, like "M16"...

which the steyr and beretta magazines aren't. the muzzle mode of these may also be different. that's just one problem.

also -

Code: [Select]
#checkammo
? _player ammo _ammo == 0 : goto "out"

#out
? ammo : goto "out2"
ammo = true
player groupchat "d**n IM OUT OF AMMO"

let's look at that for a moment. if the ammo is equal to 0, then goto 'out'. what happens if it's not equal to 0? it goes on to the next line of code, which is what?

the 'out of ammo' routine....

then comes the

Code: [Select]
? ammo : goto "out2"
bit. have you looked at the comref entry for the ammo command? does it look like it can be used like a boolean check? if you're using a variable like this, no problem. but this is a reserved term. flashpoint is looking for its use as a command, not a variable.

thus, putting 'ammo = true' will not work either.

« Last Edit: 17 Jun 2005, 19:30:08 by bedges »

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #16 on: 17 Jun 2005, 20:03:50 »
emm interesting and this is one pain in the arse i never relised the no exit line suppose i better add that in thats why it was showing the text.
so instead of ammo = true what could i do to check if its been to the 'out' part again then go to out2 if its been to out ?

Quote
have you looked at the comref entry for the ammo command? does it look like it can be used like a boolean check? if you're using a variable like this, no problem. but this is a reserved term. flashpoint is looking for its use as a command, not a variable.
ive looked several times and was wondering why it wasnt working just a few questions
1) whats a boolean check
2) By reserved term how do you mean
ill check the com ref for the answer
hang on maybe this is it.
its a true or false statement, and the line isnt a true or false statement.
cant find out about the reserved statement though

okay i kind of understand now but not really enough
basically the code doesnt work because it is not a true or false statement, correct ?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:some ammo of primary weapon
« Reply #17 on: 17 Jun 2005, 20:44:45 »
Quote
1) whats a boolean check
Boolean check means the check for true or false (actually, 1 or 0...)
Like if you have a variable Myvar = true you can check whether it's true with
? Myvar: hint "Myvar true"

Quote
By reserved term how do you mean
You can't have a variable called ammo because that is a OFP function...


The reason why bedges got into the boolean stuff is because of the lines
Code: [Select]
#out
? ammo : goto "out2"
ammo = true
player groupchat "d**n IM OUT OF AMMO"
in your script...

You have a variable called ammo there which you treat as a boolean and you can't do that since ammo is OFP function, and therefore reserved ...
« Last Edit: 17 Jun 2005, 20:45:00 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #18 on: 17 Jun 2005, 20:55:47 »
in programming, when something is 'reserved' it means it's needed by the operating system and thus cannot be used as a user-defined variable. for example, if i was to call myself 'tony blair', that'd be silly, because there already is one, and it's used by parliament. an example of a reserved variable in flashpoint would be 'time' or '_this'. these are variables that flashpoint uses.

more to the point, 'ammo' cannot be used as a variable as it's part of a command. '_ammo', as far as i know, would be fine as a local variable name.

the trick is to use commands to create a boolean check for true or false. looking over the previous posts, all the clues are there.

from THobson's post -

Quote
So you will probably have to use primaryWeapon to find which weapon the unit has then do something like:
_mags = ""
if (unit primaryWeapon == "m16") then {_mags = "m16mag"}
if (unit primaryWeapon == you get the idea...

this means that if the player might have different weapons, you need to make the script check which weapon it is, otherwise it won't work.

so you check which weapon the player has, and according to that, you decide which muzzle mode is needed for the 'ammo' command and take it from there...

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #19 on: 18 Jun 2005, 08:57:07 »
thanks alot HateR_Kint and Bedges i think i get it now i just need to test

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #20 on: 18 Jun 2005, 09:57:56 »
Quote
if (unit primaryWeapon == "m16") then {_mags = "m16mag"}
okay ive tried this but now im getting unknown operator or something on the code 'primaryweapon' ?
so i thought ill have a nother go with the code ammo, and im so near just this is the new script

Code: [Select]
_shooter = _this select 0
_amount = _this select 2
_mags = ""

#checkammo
? player ammo "M16" == 0 : goto "out"
? player ammo "XMS" == 0 : goto "out"
? player ammo "HK" == 0 : goto "out"
? player ammo "M21" == 0 : goto "out"
? player ammo "steyr" == 0 : goto "out"
? player ammo "ak74" == 0 : goto "out"
? player ammo "PK" == 0 : goto "out"
EXIT

#out
? ammoa : goto "out2"
ammoa = true
player groupchat "DAMN IM OUT OF AMMO"

#out2
if (50 > random 100) then {player groupchat "GOD DAMN IM OUT AGAIN!"} else {player groupchat "DAMN I NEED MORE AMMO"}

#exit
exit

but when i shoot i just get one thing wrong no error messages it just says the writing anyway and ive got exit after the code i also used the name of the weapon is this becuase im using an  XMS and the magazine is called 'M4' ?
i feel like im getting close
im also sorry to everyone who is helping this must feel like a pain in the arse for you and me.
but thanks for your help so far

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #21 on: 18 Jun 2005, 10:13:52 »
what is 'ammoa'?

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #22 on: 18 Jun 2005, 10:14:54 »
well i did use ammo = true and since that's a code in ofp i checnged it to ammoa = true

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #23 on: 18 Jun 2005, 10:15:37 »
again, what is 'ammoa'?

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #24 on: 18 Jun 2005, 10:18:00 »
well its not a code im using it to trigger if that part of the script has been activated and if it has it goes on to another part with new messages i supose its not really needed too much just
if ammoa = true then it moves on to anther part of the script so you get more radio text
dont ask why its called ammoa i just tapped any random button without looking and thats what i got so ive just left it like that

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #25 on: 18 Jun 2005, 10:27:25 »
okay. so once again, look at this part of the script:

Code: [Select]
#out
? ammoa : goto "out2"
ammoa = true
player groupchat "d**n IM OUT OF AMMO"

#out2
if (50 > random 100) then {player groupchat "GOD d**n IM OUT AGAIN!"} else {player groupchat "d**n I NEED MORE AMMO"}

assuming 'ammoa' is set to 'true' someplace else - as it isn't in this script - the script jumps to "out2".

if 'ammoa' is false, the script goes to the next line, which sets 'ammoa' to true, shows the first group chat, then moves down to the next line, #out2, and shows one of the other group chats.

looking at the rest of the code, let's say the unit has an m16. the script will get to the first line of #checkammo, and if the unit has no ammo, it will go to the #out sequence. fine.

what if the unit still has ammo in his m16?

then the script continues onto the next line. it then looks for xm3 ammo, finds none - as the unit has an m16 - and triggers the #out sequence.

what if the unit doesn't have an m16. what if the unit has the m21, with plenty of ammo? then the script goes to the first check, the m16, finds no m16 ammo, and jumps to the #out sequence....
« Last Edit: 18 Jun 2005, 10:27:46 by bedges »

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #26 on: 18 Jun 2005, 10:29:30 »
oh yeah i supose i need 'or' then well ill have a go with that and report back with what happens thanks alot

EDIT - Okay i tried or now and got no error message but ohh now i relised that or wont work because he doesnt have any of the other kind of ammo but atleast i got no error messages

EDIT 2 - okay i remembereed this is an event handler fired and _this select 1 is what weapon so i can do
? player ammo _weapname == 0 : goto "out"
EXIT
wich is what im about to try

TESTED and almost there and i think i know what to do now
« Last Edit: 18 Jun 2005, 10:45:19 by 456820 »

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #27 on: 18 Jun 2005, 10:51:22 »
okay my ideaa didnt work what it was is i remember seeing a command

magazines vehicle

Operand types:
vehicle: Object
Type of returned value:
Array
Description:
Returns array of types names of all vehicle's magazines.

Example:
magazines player
 
and i thought
magazines player == 0 but that didnt work
and nothing in the fired event handler to help about what kind of magazine used the closest is the amm type used
any more suggestions?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:some ammo of primary weapon
« Reply #28 on: 18 Jun 2005, 10:55:35 »
i have found that the best way to learn something is through trial and error, but in this case i'm just going to do it for you. see attached.
« Last Edit: 18 Jun 2005, 11:50:31 by bedges »

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #29 on: 18 Jun 2005, 12:01:27 »
thanks alot bedges im just testing it now

Offline 456820

  • Contributing Member
  • **
Re:some ammo of primary weapon
« Reply #30 on: 18 Jun 2005, 12:17:03 »
Yep thankyou so much it works great couldnt of done it with out you
Topic solved