Potion effect to scoreboard value

Discussion in 'CommandHelper' started by Zombiebrine, May 8, 2014.

  1. Zombiebrine

    Zombiebrine New Member

    Final request (for now most likely :p) I need a script that simply scans people for effect 13 (water breathing), sets their cure score to 1, and clears the effect.
  2. PseudoKnight

    PseudoKnight Well-Known Member

  3. Zombiebrine

    Zombiebrine New Member

  4. PseudoKnight

    PseudoKnight Well-Known Member

    There is no event for "gets the effect". Will this be for drinking a potion? If so, the player_consume event could be used.
  5. Zombiebrine

    Zombiebrine New Member

    This works, care to code it?
  6. PseudoKnight

    PseudoKnight Well-Known Member

    PHP:
    bind('player_consume', null, array('item': 373), @event) {
        set_timeout(50, closure(){
            foreach(@effect in get_peffect()) {
                if(@effect['id'] == 13) {
                    set_pscore('cure', player(), 1)
                    set_peffect(player(), 13, 0, 0)
                }
            }
        }
    }
    Optionally could detect the item in hand, cancel the event, remove the item, and set the score.
  7. RataRataData

    RataRataData Member

    Potions have data so you can just check that.
    PHP:
    bind(player_consume,null,array('item':373),@e){
        if(@e['item']['data'] == 8237 || @e['item']['data'] == 8269){
            #do stuff
       }
    }
  8. Zombiebrine

    Zombiebrine New Member

    Now can someone give me some instructions as to how to include this in main.ms with a pre existing script.
  9. PseudoKnight

    PseudoKnight Well-Known Member

    I had assumed because it was an item match it was coming in the '373:###' format. If it had said "item array" I would have figured that out, but good to know. Sometimes you just need to test these outputs in events.

    But I could have check this with item in hand, as I described in my post. The reason I didn't was the data value doesn't always match the potion effect. At least, I can't guarantee it from my end. I don't know how his server is setup.
  10. Zombiebrine

    Zombiebrine New Member

    Can you help me install it? I already have something in the main.ms and the new code doesnt seem to work.
  11. PseudoKnight

    PseudoKnight Well-Known Member

    bind() functions will work perfectly fine next to each other in the same file.
  12. Zombiebrine

    Zombiebrine New Member

    Here is my main.ms if you can help figure out why the second part is not working.

    Code (Text):
    set_interval(60000, closure(){ # every 30 seconds
        foreach(@player in all_players()) {
            if(get_pscore('plague', @player) >= 2) {
                if(!rand(3)) { # 33% chance of being 0
                    foreach(@otherplayer in players_in_radius(ploc(@player), 7)) {
                        if(get_pscore('plague', @otherplayer) == 0) {
                            set_pscore('silverkill', @otherplayer, 1)
                        }
                    }
                }
            }
        }
    })
    bind('player_consume', null, array('item': 373), @event) {
        set_timeout(50, closure(){
            foreach(@effect in get_peffect()) {
                if(@effect['id'] == 13) {
                    set_pscore('cure', player(), 1)
                    set_peffect(player(), 13, 0, 0)
                }
            }
        }
    }
    No matter how long i wait after drinking the water breathing potion (with the effect) nothing triggers with the scoreboard.