I’m trying to find a way to see who presses a button on the UI and grant them weapons based on that but I don’t know how to find the instigator for the button:
OG_Button.OnClick().Subscribe(OG_Pressed)
OG_Pressed(Message:widget_message):void =
# [Code to find instigator here]
OG_Granter.GrantItem(Instigator)
if (PlayerUI:player_ui = GetPlayerUI[Message.Player], MyUI: overlay = MyMap[Message.Player]?, SelectedButton: text_button_base = text_button_base[Message.Source]):
PlayerUI.RemoveWidget(MyUI)
if (MyMap[Message.Player] = false) {}
return
So you can subscribe to a function that takes a widget message and then define the player who clicked it like this.
SomeFunction(Message:widget_message):void=
Player := Message.Player
DoSomething(Player)
DoSomething(Player:player):void=
ItemGranter.GrantItem(Player)
if you have multiple buttons in your UI Code you can use this nifty function and class to pass extra parameters to tell exactly which button has been pressed as well
you could use the wrapper function SubscribeMessage to pass which button has been clicked like this
button_1.OnClick().SubscribeMessage(SomeFunction, 0)
button_2.OnClick().SubscribeMessage(SomeFunction, 1)
#then SomeFunction can figure out what to do based on the integer passed into it
SomeFunction(Message:widget_message, button_index:int):void=
Player := Message.Player
if(button_index = 0):
Item_Granter_0.GrantItem(Player)
else if(button_index = 1):
Item_Granter_1.GrantItem(Player)
#or you can have an array of item granters and grab them that way
@editable Granter_Array :[]item_granter_device = array{}
SomeFunction(Message:widget_message, button_index:int):void=
Player := Message.Player
if(Granter := Granter_Array[button_index]):
Granter.GrantItem(Player)