Forum Discussion

Tiitouaan's avatar
Tiitouaan
MHCP Member
24 days ago
Solved

Is buying from the shop with in-game tokens different than using Meta credits?

Hello

I set up the shop gizmo in my world so players can buy perk upgrades (auto-consumed items). My problem is that when I change the price from Meta credits to in-game tokens, it suddenly stops working correctly. I wanted to know if the event triggered is different when buying items with tokens versus Meta credits.

Thank you for you help

8 Replies

  • You might try listening to the code block onConsumptionStarted, if it fires then use the consumeItemForPlayer(player, sku, quantity)

  • Here my script attached to the shop guizmo :

    class ShopScript extends hz.Component<typeof ShopScript> {
      static propsDefinition = {};
    
      start() {
    
        this.connectCodeBlockEvent(this.entity, CodeBlockEvents.OnItemConsumeComplete, (player, item, success) => {
          if (success) {
          console.log(`${player.name.get()} successfully consumed the item: ${item}`);
          if(item === "+1_knockback_multiplier_2dfd2123")
          {
            // Ajouter +1 knockback multiplier
            const knockbackMultiplier = this.world.persistentStorage.getPlayerVariable(player, PersistentVariables_Data.playerPersistentVariables.number.knockbackMultiplier);
            this.world.persistentStorage.setPlayerVariable(player, PersistentVariables_Data.playerPersistentVariables.number.knockbackMultiplier, knockbackMultiplier + 1);
            console.log(`Increased knockback multiplier for ${player.name.get()} to ${knockbackMultiplier + 1}`);
          }else if(item === "+1_recoil_multiplier_0ec76b29")
          {
            // Ajouter +1 recoil multiplier
            const recoilMultiplier = this.world.persistentStorage.getPlayerVariable(player, PersistentVariables_Data.playerPersistentVariables.number.recoilMultiplier);
            this.world.persistentStorage.setPlayerVariable(player, PersistentVariables_Data.playerPersistentVariables.number.recoilMultiplier, recoilMultiplier + 1);
            console.log(`Increased recoil multiplier for ${player.name.get()} to ${recoilMultiplier + 1}`);
          }else if(item === "+1_resistance_multiplier_6517be99"){
            // Ajouter +1 resistance multiplier
            const resistanceMultiplier = this.world.persistentStorage.getPlayerVariable(player, PersistentVariables_Data.playerPersistentVariables.number.resistanceMultiplier);
            this.world.persistentStorage.setPlayerVariable(player, PersistentVariables_Data.playerPersistentVariables.number.resistanceMultiplier, resistanceMultiplier + 1);
            console.log(`Increased resistance multiplier for ${player.name.get()} to ${resistanceMultiplier + 1}`);
          }  
        }
        });
      }
    
    }

    All items are set to auto-consume. It seems to work fine when purchasing with meta-credits, as the console output and PPV are updated. However, when purchasing with Flouz, there is no console output and the PPV does not update.

  • Yes that's what I'm talking about. Here is my property panel.

    Flouz are the in-game tokens; the first item can be purchased with meta credits, but the second and third cannot.

     

    • SeeingBlue's avatar
      SeeingBlue
      MHCP Mentor

      Okay, looks correct. I would expect this to work. What are you seeing instead? Player tries to purchase and nothing happens? What event are you listening for?

  • You're talking about this right?

    What does the Item settings in the property panel to the right look like for this item?