Skip to content

Commit

Permalink
Fix grenades on projectile launchers not having proper owner set
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivory42 authored Nov 2, 2023
1 parent f060c85 commit d6363f0
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions mm_attribute_projectile_weapon.sp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ enum struct FProjectile
}
FProjectile Projectile[2049];

bool ChildBomb[2049] = {false, ...}; // Projectiles fired from projectile launchers, ignore these when spawned.

bool ProjectileLauncher[2049]; // Tags projectile as one that should fire more projectiles
char ProjectileModel[MAXPLAYERS+1][128]; // Model to use for the projectile which will fire itself
char ProjectileFireSound[MAXPLAYERS+1][128]; // Sound to use for projectiles being fired
Expand Down Expand Up @@ -99,6 +101,8 @@ public void OnEntityDestroyed(int entity)
if (IsValidEntity(entity))
{
ProjectileLauncher[entity] = false;

ChildBomb[entity] = false;
}
}

Expand All @@ -110,6 +114,10 @@ void ProjectileSpawned(int projRef)
if (!proj.Valid())
return;

// Ignore projectiles spawned from a launcher already
if (ChildBomb[proj.Get()])
return;

FClient owner;
FObject launcher;
int projId = proj.Get();
Expand Down Expand Up @@ -181,6 +189,13 @@ void OnProjectileTick(FObject entity, FProjectile proj, FClient owner)

child = CreateObjectDeferred(classname);

// Sets the launcher for this child projectile
SetProjectileLauncher(entity, child);

ChildBomb[child.Get()] = true;

child.SetOwner(entity.GetOwner());

// Shift upwards a bit to prevent collisions
spawn.position.z += 2.0;

Expand All @@ -199,18 +214,16 @@ void OnProjectileTick(FObject entity, FProjectile proj, FClient owner)
}
}

// Sets the launcher for this child projectile
SetProjectileLauncher(entity, child);

// Using safer methods for setting properties, also much cleaner than before
SetProjectileProperties(ABaseProjectile(entity), ABaseProjectile(child));

// Now let's set our owner, we do this after spawning to ensure we don't end up spawning an infinite amount of projectiles
DataPack pack = new DataPack();
// DataPack pack = new DataPack();
// No longer need to do this

pack.WriteCellArray(entity, sizeof FObject);
pack.WriteCellArray(child, sizeof FObject);
RequestFrame(OnChildPost, pack);
//pack.WriteCellArray(entity, sizeof FObject);
//pack.WriteCellArray(child, sizeof FObject);
//RequestFrame(OnChildPost, pack);
}
}

Expand Down Expand Up @@ -240,6 +253,7 @@ void SetProjectileLauncher(FObject entity, FObject child)
child.SetPropEnt(Prop_Send, "m_hLauncher", launcher);
}

/*
void OnChildPost(DataPack pack)
{
FObject child, entity;
Expand All @@ -252,3 +266,4 @@ void OnChildPost(DataPack pack)
delete pack;
}
*/

0 comments on commit d6363f0

Please sign in to comment.