Jump to content
Sign in to follow this  
Victor_S.

EventHandlers

Recommended Posts

I have a revolver and I want to have the shells fall to the ground when you reload. Is there a was to set an eventhandler to activate a script when I reload?

Share this post


Link to post
Share on other sites

There is no reload eventhandler, but there is a workaround with a little scripting. I wrote this script a little while ago and found that it works beautifully, it will execute "Onreload.sqs" every time you reload a gun that you've emptied the clip on, including rifles, pistols, rpg's, and it even goes off when you throw hand grenades. This will work with both AI and players.

You only need to start the script by adding a FIRED eventhandler to a unit in their init field, or through a config, which has to be '_this exec "reload.sqs"'

Reload.sqs<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;Reload.sqf by Korax of the Unsung Vietnam War mod

;Add this function to any unit by giving them a fired EH like so.- this addeventhandler ["Fired",{_this exec "reload.sqs"}]

_player = _this select 0

_gun = _this select 2

_b = _player ammo _gun

IF (_b != 0) then {Exit}

#wait

~0.15

?! Alive _player : Exit

?! ((_player Ammo _gun >0) OR !(_Player hasweapon _Gun)) : goto "wait"

IF ((_player hasweapon _gun) && (_player ammo _Gun) >0) then {[_player,_gun] exec "OnReload.sqs"} else {Exit}

OnReload.sqs - this is where you can edit and put whatever you want<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_player = _this select 0

_gun = _this select 1

etc...

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  

×