Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add take-payment action #1305

Merged
merged 1 commit into from
Apr 12, 2024
Merged

Add take-payment action #1305

merged 1 commit into from
Apr 12, 2024

Conversation

Pablete1234
Copy link
Member

As per mentioned #1254 (comment), 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

Signed-off-by: Pablo Herrera <[email protected]>
@Pablete1234 Pablete1234 added the feature New feature or request label Mar 4, 2024
@CoWinkKeyDinkInc
Copy link
Contributor

CoWinkKeyDinkInc commented Mar 6, 2024

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>

@Pablete1234
Copy link
Member Author

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 Pablete1234 marked this pull request as ready for review March 7, 2024 23:28
@Pablete1234 Pablete1234 added the ready PR is ready to merge label Apr 1, 2024
@Electroid Electroid merged commit ac539d2 into dev Apr 12, 2024
2 checks passed
@Electroid Electroid deleted the take-payment-action branch April 12, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request ready PR is ready to merge
Development

Successfully merging this pull request may close these issues.

4 participants