I simply want to run a block of code when the "OnTrade" event is raised from either buying or selling an item. But I don't know how to properly subscribe to this specific event from outside the parent class "DaggerfallTradeWindow", and there are no examples I can find of this being done outside of this class, or in other mods.
The only time I have been able to get this event to work is if I edit the "DaggerfallTradeWindow" script itself, and change:
Code: Select all
// OnTrade event. (value=0:steal, numItems=0:caught)
public delegate void OnTradeHandler(WindowModes mode, int numItems, int value);
public event OnTradeHandler OnTrade; <-------------
protected virtual void RaiseOnTradeHandler(int numItems, int value)
{
if (OnTrade != null)
OnTrade(WindowMode, numItems, value);
}
Code: Select all
// OnTrade event. (value=0:steal, numItems=0:caught)
public delegate void OnTradeHandler(WindowModes mode, int numItems, int value);
public static event OnTradeHandler OnTrade; <----------------
protected virtual void RaiseOnTradeHandler(int numItems, int value)
{
if (OnTrade != null)
OnTrade(WindowMode, numItems, value);
}
Code: Select all
DaggerfallTradeWindow.OnTrade += Testing_OnTrade;
That's not going to work though, since I don't want to edit the code-base just for a quick fix for my problem. So my latest attempt at trying to subscribe to this properly is this:
Code: Select all
void Start()
{
PlayerEnterExit.OnTransitionInterior += Testing_OnTransitionInterior;
GameManager.Instance.PlayerEffectManager.OnNewReadySpell += Testing_OnNewReadySpell;
UserInterfaceManager uiManager = DaggerfallUI.Instance.UserInterfaceManager;
DaggerfallTradeWindow testing = new DaggerfallTradeWindow(uiManager, null, DaggerfallTradeWindow.WindowModes.Buy, null);
testing.OnTrade += Testing_OnTrade;
}
Anyway, hopefully I've done my due diligence here and am not wasting anyone's time with a poorly made question, thanks.
Edit 1: This is what my block of code looks like:
Code: Select all
private static void Testing_OnTrade(DaggerfallTradeWindow.WindowModes mode, int numItems, int value)
{
Debug.Log("You just traded something.");
return;
}