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

Scarpet suggestion: Allow use of Scarpet API to set cooldown timers on items for players #597

Open
James103 opened this issue Dec 1, 2020 · 1 comment · May be fixed by #1789
Open

Scarpet suggestion: Allow use of Scarpet API to set cooldown timers on items for players #597

James103 opened this issue Dec 1, 2020 · 1 comment · May be fixed by #1789
Labels
feature suggestion New feature or request scarpet Issues related to scarpet in some way

Comments

@James103
Copy link
Contributor

James103 commented Dec 1, 2020

Currently, there is no way to interact with the player.getItemCooldownManager().set(item, ticks) method via the Scarpet API. It would be great if there was, as that would allow Scarpet scripts to set cooldowns on items when they are used for custom abilities in similar ways that other Fabric mods such as Identity (example use) do it.

@gnembon gnembon added the feature suggestion New feature or request label Dec 2, 2020
@Ghoulboy78
Copy link
Contributor

Ghoulboy78 commented Dec 8, 2020

put("item_cooldown", (e, v) ->
{
    if (e instanceof ItemEntity)
    {
        if(!(v instanceof ListValue))
            throw new InternalExpressionException("'item_cooldown' expected a list as a second argument");
        ListValue lv = ((ListValue) v);
        Value playersVal = lv.getItems().get(0);
        int duration = ((NumericValue)lv.getItems().get(1)).getInt();
        if(playersVal instanceof ListValue){
            for(Value playerVal:((ListValue) playersVal).getItems()){
                PlayerEntity player = EntityValue.getPlayerByValue(e.getServer(),playerVal);
                player.getItemCooldownManager().set(((ItemEntity)e).getStack().getItem(),duration);
            }
        } else {//if its just 1 player
            PlayerEntity player = EntityValue.getPlayerByValue(e.getServer(),playersVal);
            player.getItemCooldownManager().set(((ItemEntity)e).getStack().getItem(),duration);
        }
    }
});

This is solution, allowing for: modify(item_entity,'cooldown',[player/player_list, duration]) cos its a per-player thing but we want cooldown to be per-item. too lazy to pr rn tho.

@altrisi altrisi added the scarpet Issues related to scarpet in some way label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature suggestion New feature or request scarpet Issues related to scarpet in some way
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants