import es
import playerlib

import wcs
from wcs import wcs

itemName = 'Ankh of Reincarnation'

wcs.Item(itemName).registerItem('special', 2000, "Save your primary / secondary gun information", True)
        
def player_spawn(ev):
    ankh = wcs.Command(ev['userid'])['Ankh of Reincarnation'] 
    if ankh and ankh['active']:
        ankh['active'] = 0
        primary = ankh['primary']
        secondary = ankh['secondary']
        if primary == '0':
            primary = None
        if secondary == '0':
            secondary == None
        es.tell(ev['userid'], '#multi', '#greenAnkh of Reincarnation #default- #lightgreenGiving you weapons (%s <----> %s)' % (primary, secondary) )
        es.server.queuecmd('es_xfire %s player_weaponstrip kill' % ev['userid'])
        es.server.queuecmd('es_xgive %s player_weaponstrip' % ev['userid'])
        es.server.queuecmd('es_xfire %s player_weaponstrip strip' % ev['userid'])
        es.delayed(0.25, 'es_xgive %s weapon_knife' % ev['userid'])
        if primary:
            es.delayed(0.25, 'es_xgive %s weapon_%s' % (ev['userid'], primary) )
        if secondary:
            es.delayed(0.25, 'es_xgive %s weapon_%s' % (ev['userid'], secondary) )
        
def item_bought(ev):
    if ev['item'] == itemName:
        es.tell(ev['userid'], '#multi', '#greenAnkh of Reincarnation #default- #lightgreenPrimary / Secondary gun saved for when you die.')
        wcs.Command(ev['userid'])['Ankh of Reincarnation'] = {'primary' : playerlib.getPlayer(ev['userid']).get("primary"), 'secondary' : playerlib.getPlayer(ev['userid']).get("primary"), 'active' : 0}
        
def player_death(ev):
    if wcs.Command(ev['userid']).GetItemCount(itemName):
        wcs.Command(ev['userid']).RemoveItem(itemName)
        wcs.Command(ev['userid'])['Ankh of Reincarnation']['active'] = 1
