Jump to content
garrett

Custom Grenade script implementation

Recommended Posts

Hi everyone. I'm creating a custom EMP grenade mod and I am having trouble with referencing the thrown grenade's location to initiate the script effect.

I'm using nearEntities and nearestObjects arrays so that the grenade will affect lights, (adding 0.9 damage to them), vehicles (by disabling turrets and engines) and player/AI units by removing NVG,radio,GPS etc.

My issue lies in that I can't figure out how to get a variable to reference the location of the thrown grenade when it detonates (_grenade), that the rest of the script can use to determine the above.

I'll post the script, it's based off one that ALIASCartoons created. With his permission I'm modifying the script into a grenade mod.
Any help with this would be very much appreciated. Forgive me if it's something obvious and I'm missing it, I've tried a lot of different very hacky solutions but I don't fully "understand" scripting, I'm fairly new to modding.

Called from class CfgCloudlets as the grenade effect, in the config.cpp of the mod :


 

Spoiler

 

_grenade = "the grenade location";
 

private _near_foc_footmobile = (getPos _grenade) nearEntities [["Car","Motorcycle","Tank","Air","Ship","Civilian","SoldierGB","SoldierEB","SoldierWB"], 10];

private _vik_fly = nearestObjects [getPos _grenade,["Car","Motorcycle","Tank","Air","Ship"],10];

private _lamps = nearestObjects [getPos _grenade,["Land_fs_roof_F","Land_fs_sign_F","Land_TTowerBig_2_F","Land_TTowerBig_1_F","Lamps_base_F","PowerLines_base_F","PowerLines_Small_base_F","Land_LampStreet_small_F"],10];

private _turrets = nearestObjects [getPos _grenade,["B_static_AA_F", "B_static_AT_F","B_T_Static_AA_F","B_T_Static_AT_F","B_T_GMG_01_F","B_T_HMG_01_F","B_T_Mortar_01_F","B_HMG_01_high_F","B_HMG_01_A_F","B_GMG_01_F","B_GMG_01_high_F","B_GMG_01_A_F","B_Mortar_01_F","B_G_Mortar_01_F","B_Static_Designator_01_F","B_AAA_System_01_F","B_SAM_System_01_F","B_SAM_System_02_F","O_HMG_01_F","O_HMG_01_high_F","O_HMG_01_A_F","O_GMG_01_F","O_GMG_01_high_F","O_GMG_01_A_F","O_Mortar_01_F","O_G_Mortar_01_F","O_static_AA_F","O_static_AT_F","O_Static_Designator_02_F","I_HMG_01_F","I_HMG_01_high_F","I_HMG_01_A_F","I_GMG_01_F","I_GMG_01_high_F","I_GMG_01_A_F","I_Mortar_01_F","I_G_Mortar_01_F","I_static_AA_F","I_static_AT_F"],10];
 

if (count _lamps >0) then
{
    [_lamps] spawn 
    {
        _lamps = _this select 0;
        {_x setDamage 0.9;} forEach _lamps
    };
};

if (count _vik_fly >0) then
{
    [_vik_fly] spawn 
    {
        _vik_fly = _this select 0;
        {_x disableTIEquipment true; _x disableNVGEquipment true;_x setHitPointDamage ["hitturret",1]; _x setHitPointDamage ["hitEngine",1]; _x disableTIEquipment true; _x disableNVGEquipment true;} forEach _vik_fly
    };
};

if (count _turrets >0) then
{
    [_turrets] spawn 
    {
        _turrets=_this select 0;
        {_x setDamage 1;} forEach _turrets
    };
};

if (count _near_foc_footmobile >0) then
{
    {
            removeGoggles _x; _x removeWeaponGlobal "Rangefinder"; _x removeWeaponGlobal "Laserdesignator"; _x removeItem "Rangefinder"; _x unassignItem "ItemGPS"; _x removeItem "ItemGPS"; _x unassignItem "ItemRadio"; _x removeItem "ItemRadio";
            _x unassignItem "NVGoggles"; _x removeItem "NVGoggles"; _x unassignItem "NVGoggles_OPFOR"; _x removeItem "NVGoggles_OPFOR"; _x unassignItem "NVGoggles_INDEP"; _x removeItem "NVGoggles_INDEP";
            _x unassignItem "O_NVGoggles_hex_F"; _x removeItem "O_NVGoggles_hex_F"; _x unassignItem "O_NVGoggles_urb_F"; _x removeItem "O_NVGoggles_urb_F"; _x unassignItem "O_NVGoggles_ghex_F"; _x removeItem "O_NVGoggles_ghex_F";
            _x unassignItem "NVGoggles_tna_F"; _x removeItem "NVGoggles_tna_F"; _x unassignItem "NVGogglesB_blk_F"; _x removeItem "NVGogglesB_blk_F"; _x unassignItem "NVGogglesB_grn_F"; _x removeItem "NVGogglesB_grn_F";
            _x unassignItem "NVGogglesB_gry_F"; _x removeItem "NVGogglesB_gry_F"; _x unassignItem "Integrated_NVG_F"; _x removeItem "Integrated_NVG_F"; _x unassignItem "Integrated_NVG_TI_0_F"; _x removeItem "Integrated_NVG_TI_0_F";
            _x unassignItem "Integrated_NVG_TI_1_F"; _x removeItem "Integrated_NVG_TI_1_F"; _x removePrimaryWeaponItem "acc_pointer_IR";         
            if (headgear _x in _special_helmet_emp) then {removeHeadgear _x};
            if (secondaryWeapon _x in _special_launchers_emp) then {_x removeWeaponGlobal (secondaryWeapon _x)};

    } foreach _near_foc_footmobile
};
hideObjectGlobal _grenade;
deleteVehicle _grenade;

 

 

Share this post


Link to post
Share on other sites

On my phone, so can't help much.....

I'd recommend looking into Event Handlers:

 

 

Share this post


Link to post
Share on other sites

Found a fix, and implemented it. Mod is on the workshop now!
Used custom cfgCloudlets classes and referenced the scripts via "beforeDestroyScript", and then called via cfgAmmo with "ExplosionEffects". Works a charm.


 

  • Like 1

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

×