OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: 456820 on 11 Jun 2005, 10:32:16
-
okay ive got this script
here it is
? !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
-
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
-
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"
-
This is a comment on ammo from Gereral Barron in comref:
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
-
Don't use someammo, it has no usage in this...
player ammo primaryWeapon player : goto "out"
? (player ammo (primaryWeapon player)) == 0: goto "out"
This worked in a script I made a while ago..
-
ill try both of those ideas thanks
also i thought the command was someammo not just ammo
anyway ill have a go
-
HateR_Kint that kind of works but when his mag is emptu then it runs but the player still hs another 3 full mags
-
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:
#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"...
-
okay thanks ill have a go at it
-
right ive had a go with what i have so far and have come up with this
#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
? 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
? player #ammo primaryWeapon player == 0 : goto "out" : error unknown operator ammo
so the command ammo is wrong but i checked in the com ref and it should work
-
look again at hateR_kint's syntax -
? (player ammo (primaryWeapon player)) == 0: goto "out"
can anyone say 'brackets'?
-
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
-
_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 ?
-
will this always involve an m16? or is this script going to be called for a unit who may have any type of weapon?
-
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
-
right. so as stated by hateR_kint above
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 -
#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
? 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.
-
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 ?
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 ?
-
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"
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
#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 ...
-
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 -
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...
-
thanks alot HateR_Kint and Bedges i think i get it now i just need to test
-
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
_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
-
what is 'ammoa'?
-
well i did use ammo = true and since that's a code in ofp i checnged it to ammoa = true
-
again, what is 'ammoa'?
-
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
-
okay. so once again, look at this part of the script:
#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....
-
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
-
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?
-
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.
-
thanks alot bedges im just testing it now
-
Yep thankyou so much it works great couldnt of done it with out you
Topic solved