Is it possible to add a custom UnitOperation or UnitCommand?

aioli

Chieftain
Joined
Dec 20, 2022
Messages
2
I would like to add a custom UnitOperation or UnitCommand to avoid using the
ExposedMembers.GameEvents to pass events between gameplay and ui.

I added the operations to the database, and the hashes are created etc.
I <GameInfo> <Types> <Row Type="UNITOPERATION_MY_OP" Kind="KIND_UNITOPERATION"/> </Types> <UnitOperations> <Row OperationType="UNITOPERATION_MY_OP" VisibleInUI="true" HoldCycling="true" CategoryInUI="SPECIFIC" Icon="ICON_MY_OP" Description="LOC_UNITOPERATION_MY_OP" /> </UnitOperations> </GameInfo>

When I then try to Request the command, CanStartOperation returns false
local unit = Players[player]:GetUnits():FindID(unitId); local ops = GameInfo.UnitOperations["UNITOPERATION_MY_OP"] local actionHash = ops.Hash; local canStart = UnitManager.CanStartOperation( unit, ops.OperationType, nil, m_Trader ); print("CanStart: " .. tostring(canStart));

Doesn't matter if the unit has movement points left or not. Anyone who might have a clue on this?
 
I solved it temporally with UI.RequestPlayerOperation( Game.GetLocalPlayer(), PlayerOperations.EXECUTE_SCRIPT, parameters), but it would be nice if one could hook up custom operations. If you know anything about it, please let me now.

The parameters has a key, named "OnStart" with a string-value of the function name, e.g. "InvokeMyFunction". In the GamePlay script one can add events to it like, GameEvents.InvokeMyFunction.Add( OnInvokeMyFunction ).
 
Top Bottom