import es
import random

import wcs
from wcs import wcs

itemName = 'Dust of Appearance'

wcs.Item(itemName).registerItem('attack', 3000, "Your bullets reveal a hidden enemy.", True)
        
def player_hurt(ev):
    if ev['attacker'] != '0' and ev['userid'] != ev['attacker']:
        count  = wcs.Command(ev['attacker']).GetItemCount(itemName)
        chance = count * 50
        if random.randint(1, 100) <= chance:
            amount = 20 * count
            command = wcs.Command(ev['userid'])
            amount  = int(command['Alpha'] + amount)
            if amount > 255:
                amount = 255
            wcs.Command(ev['userid']).Color(alpha = amount)
            es.tell(ev['attacker'], '#multi', '#greenDust of Appearance #default- #lightgreenYou have revealed#green%s' % ev['es_username'] )
            es.tell(ev['userid'], '#multi', '#greenDust of Appearance #default- #lightgreenYou have been revealed by#green%s' % ev['es_attackername'] )
        
def player_death(ev):
    wcs.Command(ev['userid']).RemoveItem(itemName)
