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.
A smaller forum with a few tutorials how to get started with the ScriptAPI.
-
Gurt
- Lead Programmer

- Posts: 1884
- Joined: Sun Feb 28, 2016 3:22 pm
- Title: Lead programmer
- Started SFD: Made it!
- Location: Sweden
- Gender:
- Age: 35
Post
by Gurt » Sun Aug 11, 2019 1:14 pm
Scripting 16 - Fire
Scripting in SFD assumes you have a fair knowledge of C#.
The following code demonstrates how to read and remove fire. Available in v.1.3.1.
This is a limited instruction set. All you can do is to read a limited set of data from current fire nodes and remove individual fire nodes in the game. The fire system is old and this is what can easily be done in the API without refactoring a huge set of code.
Code: Select all
// Example how to create a "no-fire zone" around the middle of the map
public void OnStartup()
{
Events.UpdateCallback.Start(OnUpdate, 0);
}
public void OnUpdate(float ms)
{
// No fire zone
Area area = new Area(new Vector2(-32f, -32f), new Vector2(32f, 32f));
Game.DrawArea(area, Color.Yellow);
FireNode[] fireNodes = Game.GetFireNodes(area);
foreach(FireNode fireNode in fireNodes)
{
if (fireNode.AttachedToObjectID != 0)
{
Game.EndFireNode(fireNode.InstanceID);
}
}
foreach(IObject obj in Game.GetBurningObjects())
{
if (area.Contains(obj.GetWorldPosition()))
{
obj.ClearFire();
}
}
}
ScriptAPI Implementation
► Show Spoiler
IGame interface
Code: Select all
/// <summary>
/// Gets all current objects on fire (where IObject.IsBurning is true).
/// Note: The returned result is NOT ordered as burning objects get updated.
/// </summary>
public abstract IObject[] GetBurningObjects();
/// <summary>
/// Gets all current objects on fire (where IObject.IsBurning is true).
/// Note: The returned result is NOT ordered as burning objects get updated.
/// </summary>
public abstract T[] GetBurningObjects<T>() where T : IObject;
/// <summary>
/// Gets all current active fire nodes in the world.
/// </summary>
/// <returns>FireNode[]</returns>
public abstract FireNode[] GetFireNodes();
/// <summary>
/// Gets all current active fire nodes in the world in the specified area.
/// </summary>
/// <param name="area">If the area is empty, all fire nodes in the world will be included.</param>
/// <returns>FireNode[]</returns>
public abstract FireNode[] GetFireNodes(Area area);
/// <summary>
/// Ends the life of the specified fire node in the next fire update cycle.
/// </summary>
/// <param name="instanceID">Fire node's instanceID</param>
public abstract void EndFireNode(int instanceID);
FireNode structure
Code: Select all
/// <summary>
/// FireNode, a burning node in the world causing fire damage.
/// </summary>
[Serializable()]
public struct FireNode
{
/// <summary>
/// The fire node's instance ID.
/// </summary>
public readonly int InstanceID;
/// <summary>
/// The fire node's world position.
/// </summary>
public readonly Vector2 Position;
/// <summary>
/// The fire node's velocity while in the air.
/// </summary>
public readonly Vector2 Velocity;
/// <summary>
/// How long this fire node has lived in ms.
/// </summary>
public readonly float Lifetime;
/// <summary>
/// Gets the object on which this fire node is attached to. 0 if the fire node is still in the air.
/// </summary>
public readonly int AttachedToObjectID;
}
2 x
Gurt
-
NearHuscarl
- Superfighter

- Posts: 97
- Joined: Thu Feb 07, 2019 4:36 am
Post
by NearHuscarl » Mon Aug 12, 2019 2:38 am
Since you add FireNode. IGame.SpawnFireNode() and IGame.SpawnFireNodes() should return FireNode and FireNode[] respectively instead of void
2 x
-
Gurt
- Lead Programmer

- Posts: 1884
- Joined: Sun Feb 28, 2016 3:22 pm
- Title: Lead programmer
- Started SFD: Made it!
- Location: Sweden
- Gender:
- Age: 35
Post
by Gurt » Mon Aug 12, 2019 12:10 pm
NearHuscarl wrote: ↑Mon Aug 12, 2019 2:38 am
Since you add FireNode. IGame.SpawnFireNode() and IGame.SpawnFireNodes() should return FireNode and FireNode[] respectively instead of void
Good idea! Adding it to the next update.
1 x
Gurt