# Scout plugin for Deathrun Mod v 1.5
# Visit our DeathRun Server 188.134.21.171:27015
# Visit our site www.tk-portal.ru

import es, playerlib

scout = 0

deathrun_scoutlimit = es.ServerVar("deathrun_scoutlimit")
deathrun_giveammo = es.ServerVar("deathrun_giveammo")

def load():
    es.server.cmd("es_xmexec ../addons/eventscripts/deathrun/deathrun.cfg")

def es_map_start(event_var): 
    es.server.cmd("es_xmexec ../addons/eventscripts/deathrun/deathrun.cfg")

def round_start(event_var):
    global scout
    scout = 0
    es.msg('#green', 'To get a scout type !scout')

def player_say(event_var):
    global scout
    text = event_var['text']
    userid = int(event_var['userid'])
    if text.lower() == '!scout':
        if not es.getplayerprop(userid, 'CBasePlayer.pl.deadflag'):
            if es.getplayerteam(userid) == 3:   
                if scout < deathrun_scoutlimit:
                    if playerlib.getPlayer(userid).get("primary") == "0":
                        es.tell(userid, '#multi', '#lightgreenYou are get scout!')
                        es.server.queuecmd('es_xgive %s weapon_scout'%userid)
                        if int(deathrun_giveammo) == 0:
                            es.server.queuecmd('es playerset clip event_var(userid) weapon_scout 0')
                            es.server.queuecmd('es playerset ammo event_var(userid) weapon_scout 0')
                        scout += 1
                    else:
                        es.tell(userid, '#multi', '#greenDrop #lightgreenyour #greenold weapon #lightgreenfirst!')
                else:
                    es.tell(userid, '#multi', '#lightgreenSorry,no more scouts left!#green(Max %s scouts)'%str(deathrun_scoutlimit))
            else:
                es.tell(userid, '#multi', '#lightgreenScouts are restricted for terrorists!')