Created
December 15, 2016 17:29
-
-
Save Cyken-Zeraux/3aeb7577411a52f1a212d2cd66c1171e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sandbox.ModAPI; | |
using VRage.ModAPI; | |
using VRage.Game.Components; | |
using VRage.Game; | |
using Sandbox.Game.Entities; | |
using VRage.Utils; | |
namespace czaux.noshrapnel | |
{ | |
[MySessionComponentDescriptor(MyUpdateOrder.BeforeSimulation)] | |
public class NoShrapnel : MySessionComponentBase | |
{ | |
public static bool m_init { get; private set; } | |
//Our hash for the "Scrap" subtype | |
public static MyStringHash m_scraphash = MyStringHash.GetOrCompute("Scrap"); | |
//Just has to sit here and look pretty. | |
public override void Init(MyObjectBuilder_SessionComponent sessionComponent) | |
{ | |
} | |
public void init() | |
{ | |
//Tell our loop below that init has executed. | |
m_init = true; | |
//Only on the server | |
if (MyAPIGateway.Multiplayer.IsServer) | |
{ | |
//Bind function to the 'OnEntityAdd' session event. | |
MyAPIGateway.Entities.OnEntityAdd += Entities_OnEntityAdd; | |
} | |
} | |
//Do our actual removal. | |
void Entities_OnEntityAdd(IMyEntity entity) | |
{ | |
MyFloatingObject floaty = entity as MyFloatingObject; | |
//Make sure its not null | |
if(floaty?.Item != null) | |
{ | |
//Also make sure its not null | |
if (floaty.Item.Content?.SubtypeId != null) | |
{ | |
MyStringHash subtype = floaty.Item.Content.SubtypeId; | |
//Do a 2fast4u comparison | |
if (m_scraphash.Equals(subtype)) | |
{ | |
//Delete the entity | |
entity.Close(); | |
} | |
} | |
} | |
} | |
public override void UpdateBeforeSimulation() | |
{ | |
//We execute this as a 'one-shot', because the topmost | |
//Init doesn't have the information for MyAPIGateway | |
if (!m_init) | |
{ | |
init(); | |
} | |
} | |
protected override void UnloadData() | |
{ | |
//Remove our function | |
MyAPIGateway.Entities.OnEntityAdd -= Entities_OnEntityAdd; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment