Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Commit 1736063

Browse files
Merge pull request #134 from econoraptor/EntityDestroyedEvent
Entity destroyed event
2 parents c2c75e5 + fdfbdc9 commit 1736063

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

DemoInfo/DP/Handler/PacketEntitesHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ public static void Apply(PacketEntities packetEntities, IBitStream reader, DemoP
4343
e.ApplyUpdate(reader);
4444
}
4545
} else {
46+
Entity e = parser.Entities[currentEntity];
47+
e.ServerClass.AnnounceDestroyedEntity(e);
48+
4649
// leave / destroy
47-
parser.Entities [currentEntity].Leave ();
50+
e.Leave ();
4851
parser.Entities[currentEntity] = null;
4952

50-
//dunno, but you gotta read this.
53+
//dunno, but you gotta read this.
5154
if (reader.ReadBit()) {
5255
}
5356
}

DemoInfo/DT/ServerClass.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ internal void AnnounceNewEntity(Entity e)
2727
OnNewEntity(this, new EntityCreatedEventArgs(this, e));
2828
}
2929

30+
public event EventHandler<EntityDestroyedEventArgs> OnDestroyEntity;
31+
32+
internal void AnnounceDestroyedEntity(Entity e)
33+
{
34+
if (OnDestroyEntity != null)
35+
OnDestroyEntity(this, new EntityDestroyedEventArgs(this, e));
36+
}
37+
3038
public override string ToString()
3139
{
3240
return Name + " | " + DTName;
@@ -36,6 +44,7 @@ public override string ToString()
3644
public void Dispose ()
3745
{
3846
this.OnNewEntity = null;
47+
this.OnDestroyEntity = null;
3948
}
4049
}
4150

@@ -86,4 +95,11 @@ public EntityCreatedEventArgs(ServerClass c, Entity e)
8695
}
8796
}
8897

98+
class EntityDestroyedEventArgs : EntityCreatedEventArgs
99+
{
100+
public EntityDestroyedEventArgs(ServerClass c, Entity e) : base(c, e)
101+
{
102+
103+
}
104+
}
89105
}

0 commit comments

Comments
 (0)