Untitled

 avatar
unknown
plain_text
5 months ago
1.2 kB
8
Indexable
// Custom Attribute class for Game Master
[BaseContainerProps(configRoot: true)]
class SCR_UnmovableAttribute : SCR_BaseGameMasterAttribute
{
	// Value shown in GM as checkbox
	[Attribute(defvalue: "0", uiwidget: UIWidgets.CheckBox, desc: "Unit is Unmovable")]
	bool m_bUnmovable;

	override void Apply(IEntity target)
	{
		if (!target) return;
		SCR_AIGroup aiGroup = SCR_AIGroup.Cast(target.FindComponent(SCR_AIGroup));
		SCR_ChimeraCharacter aiChar = SCR_ChimeraCharacter.Cast(target);
		
		if (m_bUnmovable)
		{
			// Disable AI movement
			if (aiGroup) aiGroup.ClearWaypoints();
			if (aiChar)
			{
				AIControlComponent aiComp = AIControlComponent.Cast(aiChar.FindComponent(AIControlComponent));
				if (aiComp) aiComp.DisableMovement(true);
			}
			Print("[UnmovableAttribute] " + target.ToString() + " set to UNMOVABLE");
		}
		else
		{
			// Enable movement again
			if (aiChar)
			{
				AIControlComponent aiComp = AIControlComponent.Cast(aiChar.FindComponent(AIControlComponent));
				if (aiComp) aiComp.DisableMovement(false);
			}
			Print("[UnmovableAttribute] " + target.ToString() + " set to MOVABLE");
		}
	}
}
Editor is loading...
Leave a Comment