Jump to content
Sign in to follow this  
hcpookie

Add Eventhanlder to a weapon or magazine?

Recommended Posts

I am working on a water grenade script and I need to figure a way to add an event handler to a certain weapon or magazine. I have the grenades working great as a VEHICLE! The code runs when the grenade (as a Vehicle) will spawn. The grenade falls into the water and detonates after a timed delay. Works great and I intend to equip this on some patrol boats to allow ships to have a "hedgehog" style depth charge / grenade launcher countermeasure to combat those nasty divers that Feint is making :) Yes I said depth charges :)

The problem is that I need to do the same thing for a WEAPON. The weapon I'm modeling is the real-world "anti-scuba" grenade launcher that is apparently used by Russian forces protecting boat/submarine/pier assets. The only thing I can do with it as-is with an event handler is to make it a static weapon or a mounted weapon on a vehicle.

As far as I can tell, there is no way to add an eventhandler to a weapon/magazine/ammo type. Is there? Perhaps a way to trigger something on weapon INIT to assign an event handler to the unit that picked it up? If I don't add the event handler then the grenade launcher is going to be a scripted-only implementation. I would like to make it easy to add to weapon crates, etc. for more broad use.

Thoughts?

Share this post


Link to post
Share on other sites

Config a certain unit to have the weapon and add your event handler to the unit that what I do .

Obviously still vote above for the best outcome :)

I think there is a way to add a script to the ammo but it concerns using a trick of latching onto muzzle / missile effects and needs a deep inheritance so you can trigger it .

Share this post


Link to post
Share on other sites

Thanks Myke, I voted! :) It looks like I'm going to make a patrol vehicle w/ scuba grenades after all.

Share this post


Link to post
Share on other sites

for clarification i mean to create your own of this , which is a script that runs from the Ammo not the man

class B_23mm_AA_H

muzzleEffect = "BIS_Effects_HeavyCaliber";

Share this post


Link to post
Share on other sites
for clarification i mean to create your own of this , which is a script that runs from the Ammo not the man

That is indeed a excellent idea. A quick test showed me the following:

Any man-portable weapon (rifle, grenades, AT-weapons) seems not to trigger anything, probably because muzzleEffect wasn't defined on those few weapons i've quickly tested (M14, AK-74, RPG-7, SMAW).

In a M1A1, the script fired with each round from the main cannon aswell from the Gunners MG and Commanders MG.

On a A-10, everything but the GBU-12 fired the testscript.

So, i guess chances are extremely good to (ab)use muzzleEffect as weapon/ammo based fired EH. It also seems to pass the same data like the fired EH, including projectile object as _this select 6.

Extremely nice find, Thromp.

Share this post


Link to post
Share on other sites

from my firt look (some time ago so with patches might change probably around OA 1.52 patch)

i found

class BulletBase

muzzleEffect = "BIS_Effects_Rifle";

class FlareBase : FlareCore

{

muzzleEffect = "BIS_Effects_Rifle";

class B_127x99_Ball_noTracer

muzzleEffect = "BIS_Effects_HeavySniper";

class ShellBase

muzzleEffect = "BIS_Effects_Cannon";

class RocketBase : RocketCore

{

muzzleEffect = "BIS_Effects_Rocket";

effectsMissile = "missile1"; /// maybe additional hook ?

class MissileBase : MissileCore

{

muzzleEffect = "BIS_Effects_Rocket";

effectsMissile = "missile4"; // possible additional hook as above but might be particle effects hard to redefine from Bin folder

class SmokeLauncherAmmo : BulletBase

{

muzzleEffect = "BIS_Effects_SmokeLauncher";

class FlareLauncherAmmo : SmokeLauncherAmmo

{

muzzleEffect = "BIS_Effects_Flares";

};

they are triggered by amongst others

class StaticCannon : StaticWeapon

{

class Eventhandlers

{

init = "_scr = _this execVM ""\ca\Data\ParticleEffects\SCRIPTS\init.sqf"";";

fired = "_this call BIS_Effects_EH_Fired;";// here

};

private ["_amm"];

_amm=_this select 4;

_this call (call compile GetText (configFile >> "CfgAmmo" >> _amm >> "muzzleEffect"));

like you found i think A10 and tabks and static cannons have trigger in config i think .

Edited by Thromp

Share this post


Link to post
Share on other sites

Thanks for providing this info! I've done a bit of research and examining other mods that use new muzzle effects. I haven't tested anything yet. It seems I can use a muzzle effect to fire off a script. If I'm understanding correctly then all of the muzzle effects are "basic" run-of-the-mill SQF scripts.

Therefore, I should be able to define a new muzzle effect by following those examples. I'm a little fuzzy as to whether those scripts are limited in what they can/cannot do. Can the script do 'anything' a normal SQF could do or is there some limitation imposed upon them. For example can I have the script produce a hint so I know it works? I'm sure testing will be the only way to know.

In this particular case I'm working on the underwater grenades. My testing of default grenade behavior indicates that grenade ammo will always touch the surface of the water and do not sink. My new underwater grenade (that sinks below the waterline!) is a vehicle. I can spawn them in-game and they work perfectly - they fall to the bottom of the ocean like a miniature depth charge. The problem of course being that you can't fire a vehicle out of a grenade launcher! :)

Therefore my thinking is to have a muzzle effect fire off a script that spawns the new "vehicle" at the grenade launcher's point of surface impact. Essentially scripting the vehicle to be used as ammunition.

So what I need to test is whether these muzzle effect functions get loaded at startup. I think they do, based on observing configs in the few mods with custom muzzle effects. The idea (again I'm guessing) is that at INIT the new muzzle effect gets loaded into memory, and presto every time that muzzle gets fired the script runs. I think. :)

I believe this is done via the preprocessFile command? A little fuzzy on how this gets initialized. My limited understanding expects this to be ran via INIT but I am still educating myself on how this works.

Share this post


Link to post
Share on other sites

there's actually a way to use the fired event handler with a specific weapon. if you look at the parameters in the biki the fired event handler array contains the fired weapon too (select 2). so by checking for the weapon type inside the code you make the event handler run you can limit it to a specific weapon. i use this to play the attack animation for my melee weapon.

like this:

_FiredH = this addEventHandler ["FIRED", { if (_this select 2 != "babe_axe") then {} else {_EHScrtp = [_this select 0] execVM "\EHJ_INF\scripts\melee\axeswing.sqf"; };}];

i haven't been able to run it from the config yet but it works great from the init line of any unit. that way the unit doesn't play the melee animation when holding another weapon than my axe.

EDIT: i now added the event handler to the class CAManBase by overwriting it. like this:

class Man;

class CAManBase : Man

{

class EventHandlers

{

Init = "_this execVM 'babe_melee\Scripts\init_player.sqf'";

Respawn = "_this execVM 'babe_melee\Scripts\init_player.sqf'";

};

};

this workaround works really great so far. i just use addeventhandler like described before inside init_player.sqf to add it to all units.

Edited by Bad Benson

Share this post


Link to post
Share on other sites

BB I think you are right, that is the only way I can figure how to get it to work. Hate to do anything to the "base" but I don't see any alternative.

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  

×