ShowOff:OnPreProjectileExplode
An event handler added by the ShowOff NVSE Plugin version 1.70.
Description
This event runs whenever a projectile is about to explode.
If the function returns false (0) via SetFunctionValue, then detonation for that projectile is prevented. The projectile reference will not be destroyed and will remain in the game world, until eliminated by other means.
- Since multiple handlers can be set for the event, it only takes a minimum of 1 handler to return false for detonation to be prevented.
- If SetFunctionValue is NOT called, or if it is set with a non-zero value, then the handler will not prevent detonation.
The event is flushed every time the game is loaded. Use a GetGameLoaded check or other method to re-register a handler.
Dispatched Args
GetSelf / GetSelfAlt will return the projectile reference that is about to detonate.
The 1st UDF arg is the projectile's source Actor reference, if any.
The 2nd arg, bIsDetonationNotPrevented, informs if detonation would already be prevented by a handler that ran just before.
Syntax
Use SetEventHandler / SetEventHandlerAlt with the event name "ShowOff:OnPreProjectileExplode".
Handler Script
A skeleton handler script for this event:
scn OnPreProjectileExplodeUDF begin Function { ref rProjOwner, int bIsDetonationNotPrevented } ref rProjRef = GetSelfAlt ;* GetSelf would do the same thing ref rProjWeapon = GetProjectileRefWeapon printvar rProjRef printvar rProjWeapon printvar rProjOwner printvar bIsDetonationNotPrevented SetFunctionValue 0 ;prevent the projectile from detonating. print "OnPreProjectileExplodeUDF >> RAN!" end
Example
SetEventHandlerAlt "ShowOff:OnPreProjectileExplode" OnPreProjectileExplodeUDF
Will run whenever any projectile is about to explode.
- Due to using SetEventHandlerAlt, the above handler will be flushed on load.
SetEventHandlerAlt "ShowOff:OnPreProjectileExplode" OnPreProjectileExplodeUDF 0::GrenadeFragProjectile
Will run whenever a thrown Frag Grenade is about to explode.
SetEventHandlerAlt "ShowOff:OnPreProjectileExplode" OnPreProjectileExplodeUDF "priority"::2 SetEventHandlerAlt "ShowOff:OnPreProjectileExplode" OnPreProjectileExplodeUDF "priority"::1 2::1
The first handler will run before the second, because it has a higher priority. When the first handler runs, it will prevent detonation. After that, the second handler tries to get dispatched, but the 3rd filter, bIsDetonationNotPrevented, is not equal to 1 due to the effects of the first handler, so it doesn't get dispatched.
Notes
- For grenade-type exploding projectiles, preventing their explosion will delay it for a frame before the game checks again if it can be destroyed. This repeats over and over until either the event handler decides to allow the dynamite to destroy, or the projectile is destroyed manually. The projectile will still disappear normally if the player moves far away and unloads the cell the projectile is in.
- One should consider either replacing the grenade with an inert version, explodin it with a delay, or just deleting it with a delay, in order to prevent the event handler from constantly running as the projectile tries to explode itself, which could cause lag with multiple explosions being prevented this way.
- For lobber-type exploding projectiles, such as the 40mm grenades launched from a grenade launcher, the projectile is automatically cleaned up if its explosion is prevented.