PGM icon indicating copy to clipboard operation
PGM copied to clipboard

Add take-payment action

Open Pablete1234 opened this issue 1 year ago • 2 comments
trafficstars

As per mentioned https://github.com/PGMDev/PGM/pull/1254#issuecomment-1759728344, this adds a take-payment action, that is able to programatically (via action) trigger the user "paying" with items in their inventory:

<take-payment>
  <!-- This is syntax taken from the shops, you can define multiple items required as payment, but can be simpler for single-item payments -->
  <payment material="diamond" price="5"/>
  <payment material="emerald" price="5"/>
  <payment price="1">
      <!-- Item name is shown under the cost lore instead of the raw material name -->
      <item name="`bEnchanted Diamond" material="diamond">
          <enchantment level="2">sharpness</enchantment>
      </item>
  </payment>
  <success-action>
    <message><text>Success!</text></message>
    <kit>
        <chestplate material="diamond chestplate"/>
    </kit>
  </success-action>
  <fail-action>
    <message><text>You can't afford this!</text></message>
  </fail-action>
</take-payment>

When using attributes and not needing complicated prices (single item cost) it can be simplified:

<take-payment id="buy-chestplate" currency="diamond" price="5" success-action="success" fail-action="too-poor"/>

<action id="success">
  <message><text>Success!</text></message>
  <kit>
      <chestplate material="diamond chestplate"/>
  </kit>
</action>
<message id="too-poor"><text>You can't afford this!</text></message>

Note: has not been tested yet. @CoWinkKeyDinkInc if you want to give this a test and confirm if it solves your use-case that'd be greatly appreciated

Pablete1234 avatar Mar 04 '24 18:03 Pablete1234

I've tested this and it perfectly solves my use case.

<actions>
    <take-payment id="buy-eagle" currency="emerald" price="1" success-action="switch-eagle" fail-action="too-poor"/>
    <action id="switch-eagle" scope="player">
        <kit id="eagle"/>
    </action>
    <message id="too-poor"><text>You can't afford this!</text></message>
    <trigger filter="eagle-portal" action="buy-eagle" scope="player"/>
</actions>
<filters>
    <all id="redeem-eagle">
        <region id="eagle-portal"/>
        <!-- Use items unique to each class -->
        <carrying>
            <item>cooked fish</item>
        </carrying>
    </all>
</filters>
<portals>
    <!-- teleports players after they buy the eagle class (when they have item unique to eagle) -->
    <portal forward="redeem-eagle" destination="invaders-game-spawn" yaw="@-90"/>
</portals>

CoWinkKeyDinkInc avatar Mar 06 '24 19:03 CoWinkKeyDinkInc

glad to hear this works for you, just as a minor thing:

    <action id="switch-eagle" scope="player">
        <kit id="eagle"/>
    </action>

this isn't needed

you can just use eagle as a player-scoped action (because kits are a type of action), so: <take-payment id="buy-eagle" currency="emerald" price="1" success-action="eagle" fail-action="too-poor"/> would do the same in this case

Pablete1234 avatar Mar 07 '24 16:03 Pablete1234