Jump to content
DELTA-13

Dropping bombs on grenade pos

Recommended Posts

Heya anyone and everyone,

struggling here trying to get a script to deploy a bomb above a thrown IR grenade. Anyone got some pointers?


// Function to execute the bomb spawning process
private _deployBomb = { params ["_projectile"];
// Define the bomb type
private _bombType = "Bo_GBU12_LGB";
// Get the position of the grenade and adjust for 300m above
private _grenadePos = getPosASL _projectile; private _spawnPos = [_grenadePos select 0, _grenadePos select 1, (_grenadePos select 2) + 300];
// Spawn the bomb private
_bomb = createVehicle [_bombType, _spawnPos, [], 0, "NONE"];
// Apply gravity to the bomb
_bomb setVelocity [0, 0, -10];
// Add an event handler for when the bomb hits the ground
_bomb addEventHandler ["Hit", { params ["_bomb", "_hitObj", "_damage", "_instigator", "_hitPos", "_hitPart"];
// Explode the bomb
_bomb setDamage 1; }]; };
// Attach the event handler to the player
player addEventHandler ["FiredMan", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile"];
// Check if the fired ammo is the B_IR_Grenade
if (_ammo == "B_IR_Grenade") {

// Call the bomb deployment function with a slight delay to ensure the grenade exists in the world
[_projectile] spawn _deployBomb; }
}]; 

if (isClient) {
// Execute the script for each
player ["deployBombFromGrenade.sqf"] remoteExec ["execVM", 0, true]; }

Share this post


Link to post
Share on other sites

isClient is not a command... anyway, player has sense only on clients (never on dedicated server), so useless. Useless also remote executing such code, if you already run it on every client!

 

So, I suggest you run the following code in initPlayerLocal.sqf (run by every client when player is already defined) :

 

player addEventHandler ["FiredMan", {  
 params ["_unit", "", "", "", "_ammo", "", "_projectile"];  
 if (_ammo in ["B_IRStrobe","O_IRStrobe","I_IRStrobe"]) then {  
  _projectile spawn {
   params ["_projectile"];
   waitUntil {sleep 0.5; velocity _projectile isEqualTo [0,0,0]};
   private _pos = getPos _projectile vectoradd [0,0,300];  
   private _bomb = createVehicle ["Bo_GBU12_LGB", _pos, [], 0, "NONE"];
   _bomb setVectorUp [0,1,0];
  };  
 };  
}];

 

You don't need anything else. The bomb is local to the player but should work everywhere (createVehicle has Global Effect (GE)). Tell me if there is some sync problem in game.

 

 

More complex (with plane):

fn_end = compile "
  params ['_plane'];
  (_plane getVariable 'dataGre') params ['_pos','_proj','_grp','_wp','_unit'];
  deleteVehicle _proj;
  deleteWaypoint _wp;
  _wp = _grp addWaypoint [_pos,0];
  sleep 45;
  deleteVehicleCrew _plane;
  deleteVehicle _plane;
  _unit setVariable ['gre',nil,TRUE];
";

player addEventHandler ["FiredMan", {  
  params ["_unit", "", "", "", "_ammo", "", "_projectile"];  
  if (_ammo in ["B_IRStrobe","O_IRStrobe","I_IRStrobe"]) then {  
    [_projectile,_unit] spawn {
      params ["_projectile","_unit"];
      private _dir = getdir _unit;
      if (isNil {_unit getVariable "gre"}) then {
        _unit setVariable ["gre",TRUE,TRUE];
        waitUntil {sleep 0.5; velocity _projectile isEqualTo [0,0,0]};
        private _tgtPos = getpos _projectile;
        private _pos = _projectile getPos [2000,_dir+180];
        private _plane = createVehicle ["B_Plane_CAS_01_F", _pos, [], 0, "FLY"];
        _plane setDir _dir;
        _plane setVelocityModelSpace [0,100,0];
        private _grp = createVehicleCrew _plane;
        private _wp = _grp addWaypoint [_tgtPos,-1];
        _plane setVariable ["dataGre",[_pos,_projectile,group _plane,_wp,_unit]];
        _wp setWaypointType "destroy";
        _plane addEventHandler ["fired",{
          params ["_plane"];
          _plane spawn fn_end;
        }];
        sleep 60;
        if (!isNull _plane) then {
          _plane call fn_end;
        };
      };  
    };
  };  
}];

 

 

 

 

  • Like 2

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

×