Jump to content
Sign in to follow this  
Messiah

Check for reload

Recommended Posts

basically i'm scripting my static MG to have a sound played when reloading (on top of the basic reload sound) - now, i dont want to change the reload sound, or merge the two, as this script will be added to later with other things related to reloading...

basically, i have a 200 round mag... and i need the script to check when the weapon has ran out of rounds and is reloading...

cheers smile_o.gif

Share this post


Link to post
Share on other sites

If you want I can merge the two files into one with some audio software i got.

Share this post


Link to post
Share on other sites

Something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0

_oldcount = _unit ammo "WeaponNameHere"

#MainLoop

?(!alive _unit) : exit

~.1

_count = _unit ammo "WeaponNameHere"

; If the ammo has risen, go to the reload section

?((_count - _oldcount) > 0) : goto "Reload"

_oldcount = _count

goto "MainLoop"

#Reload

;Stuff here

goto "MainLoop"

This should work when the ammo count increases, so it'll be

_after_ reloading. I don't know if a specific EH is fired when

reloading, so it could be hard.

If you want it to _only_ work when the ammo count drops to

zero, then:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0

#MainLoop

?(!alive _unit) : exit

~.1

_count = _unit ammo "WeaponNameHere"

; If the ammo is exhausted, go to the wait-for-reload section

?(_count == 0) : goto "ReloadLoop"

goto "MainLoop"

#ReloadLoop

?(!alive _unit) : exit

~.1

_count = _unit ammo "WeaponNameHere"

; If the ammo has risen, go to the reload section

?(_count != 0) : goto "Reload"

goto "ReloadLoop"

#Reload

;Stuff here

goto "MainLoop"

Share this post


Link to post
Share on other sites

Since you have a static weapon (which is basicly a vehicle) you could use the fired-eventhandler to call a script as soon as the current magazine runs out of ammo.

fired= {if ((count _this select ..) == {playthesound}};

can't remember exactly which index you should use, look in the comref, it should be the one that returnes the magazine.

Share this post


Link to post
Share on other sites

cheers for the quick replies...

it is indeed a static MG so i was going along the lines of using the eventhandler fired to fire the script off to check ammo count...

footmunch - i'll try your scripts out and see how they go  smile_o.gif

the first one works by total ammo the weapon holds (including spare mags? or just loaded) because i need the script to fire when the current ammo belt is exhausted and new one is reloaded from stock...

the 2nd one... im asuming that waits till there is no ammo at all, including spare stock, or no ammo in the current mag loaded?

legend as always guys biggrin_o.gif

Share this post


Link to post
Share on other sites

hmmm... ok... nothing seems to be working, although i may have fired the script off incorrectly - used an init.sqs in the addon to fire it off from the start - but when it reloads a mag, no change rock.gif

weird... i modified the first of footmunch's scripts to add some animations etc when the ammo count reached 0... otherwise crazy_o.gif

Share this post


Link to post
Share on other sites

I think 'ammo' just referred to the 'loaded' magazine, but it

may include the 'total' rounds carried.

Should be starting this with:

init = "[_this select 0] exec {\addonname\reloadscript.sqs} "

Try putting a few 'debug' statements like:

player globalchat format["%1", _unit]

into the sqs to make sure everything's getting passed properly.

Share this post


Link to post
Share on other sites
Should be starting this with:

init = "[_this select 0] exec {\addonname\reloadscript.sqs} "

in the config i assume?

Share this post


Link to post
Share on other sites
Should be starting this with:

init = "[_this select 0] exec {\addonname\reloadscript.sqs} "

in the config i assume?

Yep, in class EventHandlers, in class AddonName, in class CfgVehicles.

Share this post


Link to post
Share on other sites
all of them  rock.gif

class CfgVehicles

{

  ...

  class AddonName : ...

  {

      ...

      class EventHandlers

      {

           //init line here, please

      };

   };

};

Comme ca.

Share this post


Link to post
Share on other sites

ok... added it to the config, and modified the script (didnt need to check when it had been reloaded, just when it ran out of bullets:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0

#MainLoop

?(!alive _unit) : exit

~.1

_count = _unit ammo "UKF_GPMG_Mounted"

; If the ammo is exhausted, go to the wait-for-reload section

?(_count == 0) : goto "ReloadLoop"

goto "MainLoop"

#ReloadLoop

?(!alive _unit) : exit

~.1

_count = _unit ammo "UKF_GPMG_Mounted"

_unit animate ["ani_reload", 1]

~0.8

_unit animate ]"ani_reload", 0]

0.3

_unit animate ["ani_reload", 1]

~0.3

~5

_unit animate ["ani_reload", 0]

~0.4

_unit animate ["ani_handle" 1]

~0.1

_unit animate ["ani_handle" 0]

#Reload

goto "MainLoop"

and the config is like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">};

class EventHandlers

{

fired = "[_this select 0] exec ""\UKF_SF\UKF_Linkeject.sqs""; [_this select 0] exec ""\UKF_SF\UKF_Casingeject.sqs"" "

};

{

init = "[_this select 0] exec {\UKF_SF\UKF_Checkreload.sqs} "

};

};

so... lets see how it goes tounge_o.gif

Share this post


Link to post
Share on other sites

well, besides add the thing to the config wrong, too many { and }; as awlays, it kinda works...

the script does fire... but only once all the ammo is gone, including the magzines spare... which isnt exactly what i needed sad_o.gif

hmmmm... anyway to check for individual mags? oh, and my animation started erroring saying stuff like invalid numbers etc crazy_o.gif

Share this post


Link to post
Share on other sites

I don't think you need to loop the script checking whether it's _count == 0

just check each time it's fired.

ie, moved the EH from init to fired and replace

goto "MainLoop" with exit

STT

Share this post


Link to post
Share on other sites

cheers STT... i'll swap it around and check  smile_o.gif

I'd still be correct in saying that that will only work still when all magazines and rounds are expended, and not after every magazine?

Share this post


Link to post
Share on other sites

A tip for this:

In the the EH fired you test how many shot are left, if it's one the mag will be empty next shot, and you will have empty mag next call of the EH.

Like this :

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if ( _TheAddon ammo {OFrP_ANF1V} == 1) then {_MagEmpty ={AnEmpyMag} createvehicle getpos _TheAddon; _MagEmpty setdir random 360; _MagEmpty animate [{cover}, (random 10)/10]}

note:

unit ammo magazine

Operand types:

unit: Object

magazine: String

Type of returned value:

Number

Description:

Count how many shots are left for given magazine type.

Example:

player ammo "M16"

Share this post


Link to post
Share on other sites

cheers guys.... testing it out now... have a few other things to work out too along the same lines

Share this post


Link to post
Share on other sites

If you want the 'event' to happen exactly when the last (or

penultimate) bullet is fired, you can use the fired EH.

If you want the event to happen when the user executes the

reload action, then you'll need the loop script.

(Fired EH isn't called by a reload, is it STT?)

There's a ] in the second anim statement that should be [

Share this post


Link to post
Share on other sites

the MG reloads automatically, so the player doesnt press R etc... so am trying STT's modifications...

Share this post


Link to post
Share on other sites

Other problem the savegame for avoid it only one solution work with the init and a test on time (this variable is set to zero when player load a saved game) like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;number of ammo

_NbAmmo = {_x == _Type} count (magazines (_weapon))

#return

; this test for dedicate server the save game test not useful and create problems

If (format["%1",player] == "<NULL-object>" )   then  {goto {SkipTimeForDeDicate}}

@(_NbAmmo != {_x == _Type} count (magazines (_gun)) )  || (time < 1 )

#SkipTimeForDeDicate

;if the number of ammo change the weapon is reloading

@(_NbAmmo != {_x == _Type} count (magazines (_gun)) )

; here your work

goto {return}

In the scripts of the ANF1 of OFrP I use both methods (EH & init) the init for showing belt and magazines if the MG is full of ammos and the EH for create and empty magazine on the ground (and create also empty cartridges on the ground)

Share this post


Link to post
Share on other sites

tried STT's suggestion... it still only fires the script once all ammo is expended.... not after every magazine... maybe because it's a static weapon its having problems working it out?

Share this post


Link to post
Share on other sites

How are the gun and magazines defined in the config?

Is it listed as (200 | 5) in the top left info box in-game?

You could execute the reloading every 200th bullet using:

?((_unit ammo "gun") mod 200 < 1) : goto "ReloadSection"

Share this post


Link to post
Share on other sites

it is indeed listed as (200|5)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?((_unit ammo "gun") mod 200 < 1) : goto "ReloadSection"

how does that work and where would it go? in place of this?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?(_count == 0) : goto "ReloadLoop"

but i may add that in as a 'and not' because there's no point in reloading a gun with no more ammo available tounge_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×