• Studio

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • InventoryTransaction

    Inherits from: Object

    InventoryTransaction contains a list of actions that will be performed when the transaction is passed to Inventory.CommitTransaction. Because each function returns the InventoryTransaction, they can be chained to quickly add all the actions to the object.

    Methods

    Adds the given quantity of the given item to the holder's inventory.

    Parameters

    holderId

    string

    itemId

    string

    quantity

    number

    This is the equivalent of calling Give(player.user.id, itemId, quantity).

      --!SerializeField
      local itemId: string = "Money"
    
      --!SerializeField
      local amountPerPickup: number = 1
    
      local collectPickupRequest = Event.new("CollectPickupRequest")
    
      function self:ClientStart()
        function self:OnTriggerEnter(other : Collider)
          self.gameObject:SetActive(false)
          collectPickupRequest:FireServer()
        end
      end
    
      function self:ServerStart()
        collectPickupRequest:Connect(function(player: Player)
          local transaction = InventoryTransaction.new()
            :GivePlayer(player, itemId, amountPerPickup)
          Inventory.CommitTransaction(transaction)
        end)
      end
    

    Parameters

    player
    Player
    itemId

    string

    quantity

    number

    Removes the given quantity of the given item from the holder's inventory.

    Parameters

    holderId

    string

    itemId

    string

    quantity

    number

    This is the equivalent of calling Take(player.user.id, itemId, quantity).

      function Purchase(player: Player, itemId: string, currencyId: string, cost: number)
        local transaction = InventoryTransaction.new()
          :GivePlayer(player, itemId, 1)
          :TakePlayer(player, currencyId, cost)
        Inventory.CommitTransaction(transaction)
      end
    

    Parameters

    player
    Player
    itemId

    string

    quantity

    number

    Removes the given quantity of the given item from the from holder's inventory and adds the same quantity of that item to the to holder's inventory.

    Parameters

    fromHolderId

    string

    toHolderId

    string

    itemId

    string

    quantity

    number

    This is the equivalent of calling Move(fromPlayer.user.id, toPlayer.user.id, itemId, quantity).

      function FinalizeTrade(playerA: Player, playerAItems: {string}, playerB: Player, playerBItems: {string})
        local transaction = InventoryTransaction.new()
        for index, itemId in playerAItems do
          transaction:MovePlayers(playerA, playerB, itemId, 1)
        end
        for index, itemId in playerBItems do
          transaction:MovePlayers(playerB, playerA, itemId, 1)
        end
    
        Inventory.CommitTransaction(transaction)
      end
    

    Parameters

    fromPlayer
    Player
    toPlayer
    Player
    itemId

    string

    quantity

    number

    Adds the given quantity of the given item to the holder's reserved items. Items that are reserved cannot be added or removed with Give, Take or Move. Use Release to remove the items from the reserved items.

    Parameters

    holderId

    string

    itemId

    string

    reservedFor

    string

    quantity

    number

    This is the equivalent of calling Reserve(player.user.id, itemId, reservedFor, quantity).

    Parameters

    player
    Player
    itemId

    string

    reservedFor

    string

    quantity

    number

    Removes the given quantity of the given item from the player's reserved items.

    Parameters

    player
    Player
    itemId

    string

    reservedFor

    string

    quantity

    number

    This is the equivalent of calling Release(player.user.id, itemId, reservedFor, quantity).

    Parameters

    holderId

    string

    itemId

    string

    reservedFor

    string

    quantity

    number

    Updated 22 days ago

    PocketWorlds Icon

    © 2024 Pocket Worlds. All rights reserved.