PGM
PGM copied to clipboard
Add take-payment action
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
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>
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