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

hasvalue greater than/less than, or equal to #21

Closed
Isaiah-labs opened this issue Jul 14, 2020 · 2 comments
Closed

hasvalue greater than/less than, or equal to #21

Isaiah-labs opened this issue Jul 14, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request feature done The feature is already there or already planned

Comments

@Isaiah-labs
Copy link

Have you checked the wiki page to see if your suggestion is already added?
Yes/No

Have you checked the issue tracker to see if your suggestion was already submitted and denied?
Yes/No

Have you asked if the feature already exists in the Discord Server? (Or got redirected to a Github issue here)
Yes/No

Is your feature request related to a problem? Please describe.
There are no issues related to this feature request

Describe the solution you'd like
I'd like to see hasvalue have a <, <=, >, >= option, I'm trying to have an item display for a range of values, rather than just one.

Describe alternatives you've considered
Creating a separate item for each and every value I'd like, but I'm talking numbers into the thousands so it's just not practical.

Additional context
Add any other context or screenshots about the feature request here.

@Isaiah-labs Isaiah-labs added the enhancement New feature or request label Jul 14, 2020
@fireFerry
Copy link
Collaborator

Rocky, the developer already told me he would be looking into this. He will later reply with new information.

@rockyhawk64
Copy link
Owner

rockyhawk64 commented Jul 15, 2020

This can be done using PlaceholderAPI, I have created an example item to explain.

You will need to use the JavaScript placeholder and hasvalue with CommandPanels combined. The example below will check to see if the placeholder "vault_eco_balance" which is the player's balance, is greater than 20 or not. If it is, it will return true, otherwise, it will return false.
This is why the value: true can be done, because it will not be comparing a number, but only a true/false value. If you need to reverse the outcome, you can always change value: to false, or even change output: to false (they'll do the same thing in this case).

'23':
  material: REDSTONE_BLOCK
  name: 'You NEED $20!'
  lore:
  - '&cYou have $%vault_eco_balance%'
  hasvalue:
    output: true
    value: true
    compare: '%javascript_greater_than_{vault_eco_balance},20%'
    material: EMERALD_BLOCK
    name: 'You HAVE $20!'

To make this placeholder work, you will need to follow the javascript steps with PlaceholderAPI which is here:
https://github.com/PlaceholderAPI/Javascript-Expansion/wiki/Community-Scripts#how-to-use

When you get to the step that requires you to write javascript, I have done this for you, simply copy and paste this script I made into the greater_than.js file:

var placeholder;

function gThan() {
  if (args.length === 2) {
    placeholder = args[0];
  }else{
    return false;
  }
  if (placeholder > args[1]){
    return true;
  }else{
    return false;
  }
}

gThan();

In the code above, you can see the section that says placeholder > args[1]. Simply change the > to any javascript operator if you want it to be different (https://www.w3schools.com/js/js_comparisons.asp). Make sure to do /cpr and /papi reload when making changes to both plugins.

@rockyhawk64 rockyhawk64 added the feature done The feature is already there or already planned label Jul 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature done The feature is already there or already planned
Projects
None yet
Development

No branches or pull requests

3 participants