Answered Is there a way to track when a grenade detonates?

Cxwh

Veteran
Messages
64
Reaction score
45
Points
568
I know this is pretty random, but I'm trying to remake the decoy grenade from CS:GO (which plays random gunshot sounds). I looked through the gscs and found some things that might be helpful, like the FakeFire from the psychosis bots, but can't really find a proper way to track when a grenade should detonate. It would also be helpful if someone knows how to remove the effects (like the smoke fx for smoke grenades). I know I'm asking for alot, but I'm really kind of lost right now.
 

God

Skiddy
Messages
339
Reaction score
237
Points
593
self waittill("grenade_fire"); //idk if this is when you throw a grenade or when it explodes
 

Cxwh

Veteran
Messages
64
Reaction score
45
Points
568
This is how far I could get today
Code:
function __init__()
{
    callback::on_start_gametype( &init );
    callback::on_connect( &on_player_connect );
    callback::on_spawned( &on_player_spawned );
}

function init()
{
    level.decoyWeapons = strTok("ar_standard ar_accurate ar_fastburst ar_cqb ar_damage ar_longburst ar_marksman ar_garand ar_famas ar_peacekeeper smg_standard smg_versatile smg_fastfire smg_longrange smg_burst smg_capacity smg_mp40 lmg_light lmg_heavy lmg_cqb lmg_slowfire lmg_infinite", " ");
}

function on_player_connect()
{
    //dunno if i need it yet
}

function on_player_spawned()
{
    self endon("disconnect");
    self thread watchDecoyGrenade();
}

function watchDecoyGrenade()
{
    self endon("death");
    self endon("disconnect");

    weapon_decoy = GetWeapon("willy_pete"); //smoke grenade
    for(;;)
    {
        self waittill("grenade_fire", grenade, weapon, cookTime);
        if(weapon.rootWeapon == weapon_decoy) //checks if its the smoke grenade
        {
            grenade thread watchDecoyGrenadeDetonation(self, weapon_decoy, 4);
        }
    }
}

function watchDecoyGrenadeDetonation(owner, statWeapon, shotsFired)
{
    //owner AddWeaponStat(statWeapon, "used", 1);
    self waittill("explode", position, surface);
    self decoyDetonate(owner, position, shotsFired);
}

function decoyDetonate(owner, position, shotsFired)
{
    decWeaps = level.decoyWeapons.size - 1;
    i = RandomIntRange(0, decWeaps);

    fakeFireWeapon = level.decoyWeapons[i];
    self decoyFakeFire(owner, position, fakeFireWeapon, shotsFired);
}


function decoyFakeFire(owner, position, fakeFireWeapon, shotsFired)
{
    max_range = (750*750);
    while(true)
    {
        if(isDefined(fakeFireWeapon))
        {
            players = GetPlayers();
            foreach(player in players)
            {
                if(isDefined(player) && isAlive(player))
                {
                    if(DistanceSquared(player.origin, position) < max_range)
                    {
                        self FakeFire(owner, position, fakeFireWeapon, shotsFired);
                        break;
                    }
                }
            }
        }
        wait(shotsFired / 2);
        self SetFakeFire(false);
    }
}
 
Top