This forum is locked and will eventually go offline. If you have feedback to share you can find us in our Discord channel "MythoLogic Interactive" https://discord.gg/nECKnbT7gk

Forum rules

Scripting 12 - Listening on player melee action

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.
Locked
User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1887
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 36

Scripting 12 - Listening on player melee action

Post by Gurt » Sun Jul 28, 2019 1:08 pm

Scripting 12 - Listening on player melee action

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

The following code demonstrates how to listen on player melee action events in v.1.3.0.

Code: Select all

public void OnStartup()
{
	Events.PlayerMeleeActionCallback.Start(OnPlayerMeleeAction);
}

 public void OnPlayerMeleeAction(IPlayer player, PlayerMeleeHitArg[] args) {
	// player performed a melee action. args contains all hit objects (if any).
	Game.WriteToConsole(string.Format("Player {0} hit {1} objects during melee {2}", player.UniqueID, args.Length, (player.IsKicking ? "kick" : "attack") ));
	foreach(PlayerMeleeHitArg arg in args) {
		Game.WriteToConsole(string.Format("Player {0} hit object {1} for {2} damage", player.UniqueID, arg.HitObject.UniqueID, arg.HitDamage));
	}
 }

ScriptAPI Implementation for PlayerMeleeActionCallback
► Show Spoiler
2 x
Gurt

Locked