Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Scripting 10 - Listening on explosions

A smaller forum with a few tutorials how to get started with the ScriptAPI.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Scripting 10 - Listening on explosions

Post by Gurt » Sat Jul 27, 2019 2:06 pm

Scripting 10 - Listening on explosions

Scripting in SFD assumes you have a fair knowledge of C#.

The following code demonstrates how to listen on triggered explosions in v.1.3.0.

Code: Select all

Events.ExplosionHitCallback m_explosionHitEvent = null;
         
 public void OnStartup() {
	m_explosionHitEvent = Events.ExplosionHitCallback.Start(OnExplosionHit);
 }
 public void OnExplosionHit(ExplosionData explosion, ExplosionHitArg[] args) {
	// explosion triggered
	for(int i = 0; i < args.Length; i ++) {
	   switch (args[i].HitType) {
		case ExplosionHitType.Damage:
			Game.WriteToConsole(string.Format("Explosion {0} hit {1} {2} for {3} damage", explosion.InstanceID, (args[i].IsPlayer ? "player" : "object"), args[i].ObjectID, args[i].Damage));
			break;
		case ExplosionHitType.Shockwave:
			Game.WriteToConsole(string.Format("Explosion {0} pushed {1} {2}", explosion.InstanceID, (args[i].IsPlayer ? "player" : "object"), args[i].ObjectID));
			break;
		case ExplosionHitType.None:
			Game.WriteToConsole(string.Format("Explosion {0} overlapped {1} {2}", explosion.InstanceID, (args[i].IsPlayer ? "player" : "object"), args[i].ObjectID));
			break;
	   }
	}
 }
 

Note: If you only want to listen on player damage you could use the PlayerDamageCallback event instead. See viewtopic.php?f=22&t=3771

ScriptAPI Implementation
► Show Spoiler
Last edited by Gurt on Sun Jul 28, 2019 1:04 pm, edited 1 time in total.
Reason: Updated implementation details
4 x
Gurt

Post Reply