I wanted to create a device that when you press the button, takes from your 10 gold using a conditional button device and gives you a weapon using the item granted device, and every time you press the button device it gives you a better weapon for 10 gold
var Agent : [agent]int = map{}
@editable
Button : button_device = button_device{}
@editable
ItemGranter : []item_granter_device = array{}
@editable
ItemSeller : []conditional_button_device = array{}
@editable
ItemCost: type{X: int where X >= 0} = 10
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Button.InteractedWithEvent.Subscribe(AssultRifle)
AssultRifle(Player:agent):void=
GranterNumber :int= 0
KeyItemIndex :int= 0
if (ItemCost > 0, ItemSell := ItemSeller[1]):
PlayerGold := ItemSell.GetItemCount(Player, KeyItemIndex)
if (PlayerGold >= ItemCost):
ItemSell.SetItemCountRequired(KeyItemIndex, ItemCost)
ItemSell.Activate(Player)
WeaponGrant(Player, GranterNumber)
else:
Print("Player does not have enough money :(")
else:
WeaponGrant(Player, GranterNumber)
WeaponGrant(Player: agent, GranterNumber : int):void=
if:
var CurrentItemIndex : int = Agent[Player]
ItemGrant := ItemGranter[GranterNumber]
then:
set CurrentItemIndex += 1
ItemGrant.SetNextItem(CurrentItemIndex)
ItemGrant.GrantItem(Player)
if (set Agent[Player] = CurrentItemIndex):
else:
if:
set Agent[Player] = 0
FirstItem := ItemGranter[GranterNumber]
then:
FirstItem.GrantItem(Player)
The code works overall fine but when you have more than 10 gold it drains all your gold with a single button click I used SetItemCountRequired to change the price from 0 to 10 gold. I don’t know if it’s a glitch from a device or there is something wrong with my script
Here is a video:
As you see I gave myself 2500 gold and the price was 10 gold and still conditional button take it all. When I tried to interact with the conditional device itself it took from me 10 gold but with my device all the gold.