// PriZe [ world-source.ru - by schmidt]

block load
{
   es_xmexec ../addons/eventscripts/world-source.ru/prize/prize.cfg
   if (server_var(eventscripts_currentmap) in server_var(p_map)) then es_xunload world-source.ru/prize
   else do
   {
      es_xset p_baz "world-source.ru_p_baz"
      es_xset p_t 0
      es_token p_t server_var(p_baz) 1 _
      es_xset p_f 0
      es_xformatv p_f "%1_p_baz" p_t

      es keygroupremove server_var(p_f)
      es_keygroupload server_var(p_f) "|world-source.ru/prize"
      es_xset p_k 0
      es_foreachkey k in server_var(p_f) "es_keygetvalue p_k server_var(p_f) server_var(k) p_vkl;if (server_var(p_k) = 1) then es_xset p_on 1"
      if (server_var(p_on) != 1) do
      {
         es_xunload world-source.ru/prize
         echo "Все призы отключены.."
      }
      else do
      {
         es_xset e 0
         es_xexists e script popup
         ifx false(e) do
         {
            es_xload popup
         }
         es_xexists e saycommand !cash
         ifx false(e) do
         {
            es_xregsaycmd !cash world-source.ru/prize/cash_menu
         }
         es_xset p_knife_req 0
         es_xset p_heads_req 0
         es_xset p_deflt_req 0
         es_keygetvalue p_knife_req server_var(p_f) kills_req knife
         es_keygetvalue p_heads_req server_var(p_f) kills_req heads
         es_keygetvalue p_deflt_req server_var(p_f) kills_req deflt

         es_xset p_val_cash 0
         es_xset p_val_hp 0
         es_xset p_val_jump 0
         es_xset p_val_invis 0
         es_xset p_val_skin 0
         es_xset p_val_speed 0
         es_keygetvalue p_val_cash server_var(p_f) 1 p_val
         es_keygetvalue p_val_hp server_var(p_f) 2 p_val
         es_keygetvalue p_val_jump server_var(p_f) 3 p_val
         es_keygetvalue p_val_invis server_var(p_f) 5 p_val
         es_keygetvalue p_val_skin server_var(p_f) 6 p_val
         es_keygetvalue p_val_speed server_var(p_f) 7 p_val

         keygroupremove stats_baz
         es_xkeygroupload stats_baz "|world-source.ru/prize"
         es_xmexec ../addons/eventscripts/world-source.ru/prize/downloads.cfg

         es_xmsg #green "Мод PriZe Активирован! Перезагрузка карты.. 5 сек.."
         es_xmsg #green "Мод PriZe Активирован! Перезагрузка карты.. 5 сек.."
         es_xmsg #green "Мод PriZe Активирован! Перезагрузка карты.. 5 сек.."
         es_xmsg #green "Мод PriZe Активирован! Перезагрузка карты.. 5 сек.."
         es_xmsg #green "Мод PriZe Активирован! Перезагрузка карты.. 5 сек.."
         es_delayed 5 changelevel server_var(eventscripts_currentmap)

         es_xset p_var 0
         es_xset p_nam 0
         es_xset p_get 0
         es_xset p_r 0
         es_xset p_id 0
         es_xset p_steam 0
      }
   }
}

block unload
{
   es_xkeygroupsave stats_baz "|world-source.ru/prize"
   es_xkeygroupdelete stats_baz
   es_keygroupdelete server_var(p_baz)
   es_xunregsaycmd !cash
   popup exists cashMneu e
   if (server_var(e) = 1) then popup delete cashMneu
}

block cash_menu
{
   es_xgetcmduserid p_id
   es_getplayersteamid p_steam server_var(p_id)
   es_keygetvalue p_var stats_baz server_var(p_steam) p_cash
   ifx true(p_var) do
   {
      popup exists cashMneu e
      if (server_var(e) = 1) then popup delete cashMneu
      popup create cashMneu
      popup addlinef cashMneu "Ваш баланс: $%1" p_var
      popup addline cashMneu "- - - - - - - - - - - -"
      popup addline cashMneu " "
      popup addline cashMneu "->1. Снять $100"
      popup addline cashMneu "->2. Снять $1000"
      popup addline cashMneu " "
      popup addline cashMneu "Меню: !cash"
      popup addline cashMneu "- - - - - - - - - - - -"
      popup addline cashMneu " "
      popup addline cashMneu "World-Source.Ru"
      popup menuselect cashMneu world-source.ru/prize/cash_menu_select
      es_sexec server_var(p_id) menuselect 0
      es_delayed 0.1 popup send cashMneu server_var(p_id)
   }
   else es_xtell server_var(p_id) #multi "#lightgreenНа вашем счету нет денег.."
}

block cash_menu_select
{
   if (server_var(_popup_choice) = 1) do
   {
      es_getmoney p_get server_var(_popup_userid)
      if (server_var(p_get) <= 15900) do
      {
         es_getplayersteamid p_steam server_var(_popup_userid)
         es_keygetvalue p_var stats_baz server_var(p_steam) p_cash
         if (server_var(p_var) >= 100) do
         {
            es keymath stats_baz event_var(es_steamid) p_cash - 100
            es playerset cashadd server_var(_popup_userid) 100
            es_tell server_var(_popup_userid) #multi "#lightgreenДеньги получены!"
            es_sexec server_var(_popup_userid) say !cash
            es_playsound server_var(_popup_userid) "physics/metal/chain_impact_hard1.wav" 1
         }
         else es_xtell server_var(p_id) #multi "#lightgreenУ вас нет $100.."
      }
      else es_xtell server_var(p_id) #multi "#lightgreenСейчас вы в деньгах не нуждаетесь.."
   }
   if (server_var(_popup_choice) = 2) do
   {
      es_getmoney p_get server_var(_popup_userid)
      if (server_var(p_get) <= 15000) do
      {
         es_getplayersteamid p_steam server_var(_popup_userid)
         es_keygetvalue p_var stats_baz server_var(p_steam) p_cash
         if (server_var(p_var) >= 1000) do
         {
            es keymath stats_baz event_var(es_steamid) p_cash - 1000
            es playerset cashadd server_var(_popup_userid) 1000
            es_tell server_var(_popup_userid) #multi "#lightgreenДеньги получены!"
            es_sexec server_var(_popup_userid) say !cash
            es_playsound server_var(_popup_userid) "physics/metal/chain_impact_hard1.wav" 1
         }
         else es_xtell server_var(p_id) #multi "#lightgreenУ вас нет $1000.."
      }
      else es_xtell server_var(p_id) #multi "#lightgreenСейчас вы в деньгах не нуждаетесь.."
   }
}

event player_jump
{
   es_keygetvalue p_get stats_baz event_var(es_steamid) p_jump
   if (server_var(p_get) > 0) then playerset push event_var(userid) server_var(p_val_jump) 0 0
}

// key create 

event player_connect
{
   es_exists e key stats_baz event_var(networkid)
   ifx false(e) do
   {
      es_keycreate stats_baz event_var(networkid)
      es_keysetvalue stats_baz event_var(networkid) p_nick event_var(name)
      es_keysetvalue stats_baz event_var(networkid) p_cash 0
      es_keysetvalue stats_baz event_var(networkid) p_hp 0
      es_keysetvalue stats_baz event_var(networkid) p_jump 0
      es_keysetvalue stats_baz event_var(networkid) p_gren 0
      es_keysetvalue stats_baz event_var(networkid) p_invis 0
      es_keysetvalue stats_baz event_var(networkid) p_skin 0
      es_keysetvalue stats_baz event_var(networkid) p_speed 0
      es_keysetvalue stats_baz event_var(networkid) p_defus 0
      es_keysetvalue stats_baz event_var(networkid) p_k 0
   }
   else es_xkeysetvalue stats_baz event_var(networkid) p_nick event_var(name)
}

event player_changename
{
   es_keysetvalue stats_baz event_var(es_steamid) p_nick event_var(newname)
}

event player_death
{
   if (event_var(es_attackerteam) > 1) do
   {
      if (event_var(es_attackerteam) != event_var(es_userteam)) do
      {
         ifx true(p_start) do
         {
            es_keygetvalue p_var stats_baz event_var(es_steamid) p_hp
            if (server_var(p_var) > 0) then keymath stats_baz event_var(es_steamid) p_hp - 1
            else do
            {
               es_keygetvalue p_var stats_baz event_var(es_steamid) p_jump
               if (server_var(p_var) > 0) then keymath stats_baz event_var(es_steamid) p_jump - 1
               else do
               {
                  es_keygetvalue p_var stats_baz event_var(es_steamid) p_invis
                  if (server_var(p_var) > 0) then keymath stats_baz event_var(es_steamid) p_invis - 1
                  else do
                  {
                     es_keygetvalue p_var stats_baz event_var(es_steamid) p_skin
                     if (server_var(p_var) > 0) then keymath stats_baz event_var(es_steamid) p_skin - 1
                     else do
                     {
                        es_keygetvalue p_var stats_baz event_var(es_steamid) p_speed
                        if (server_var(p_var) > 0) then keymath stats_baz event_var(es_steamid) p_speed - 1  
                     }
                  }
               }
            }
            if (server_var(p_rweap) = 3) do
            {
               es keymath stats_baz event_var(es_attackersteamid) p_k + 1
               es_keygetvalue p_var stats_baz event_var(es_attackersteamid) p_k
               if (server_var(p_var) = server_var(p_deflt_req)) do
               {
                  if (server_var(p_r) = 1) then keymath stats_baz event_var(es_attackersteamid) p_cash + server_var(p_val_cash)
                  if (server_var(p_r) = 2) then keymath stats_baz event_var(es_attackersteamid) p_hp + 1
                  if (server_var(p_r) = 3) then keymath stats_baz event_var(es_attackersteamid) p_jump + 1
                  if (server_var(p_r) = 4) then keymath stats_baz event_var(es_attackersteamid) p_gren + 1
                  if (server_var(p_r) = 5) then keymath stats_baz event_var(es_attackersteamid) p_invis + 1
                  if (server_var(p_r) = 6) then keymath stats_baz event_var(es_attackersteamid) p_skin + 1
                  if (server_var(p_r) = 7) then keymath stats_baz event_var(es_attackersteamid) p_speed + 1
                  if (server_var(p_r) = 8) then keymath stats_baz event_var(es_attackersteamid) p_defus + 1
                  es_format p_f "#lightgreenПобедитель конкурса: #green%1! #lightgreenВыиграл: #green%2!" event_var(es_attackername) server_var(p_nam)
                  es_msg #multi server_var(p_f)
                  if (server_var(p_sound) != 0) then es_xcexec_all play server_var(p_sound)
                  es_sexec event_var(attacker) say server_var(p_t)
                  es_xset p_start -1
               }
            }
            else do
            {
               if (server_var(p_rweap) = 1) do 
               {
                  if (event_var(weapon) = knife) do
                  {
                     es keymath stats_baz event_var(es_attackersteamid) p_k + 1
                     es_keygetvalue p_var stats_baz event_var(es_attackersteamid) p_k
                     if (server_var(p_var) = server_var(p_knife_req)) do
                     {
                        if (server_var(p_r) = 1) then keymath stats_baz event_var(es_attackersteamid) p_cash + server_var(p_val_cash)
                        if (server_var(p_r) = 2) then keymath stats_baz event_var(es_attackersteamid) p_hp + 1
                        if (server_var(p_r) = 3) then keymath stats_baz event_var(es_attackersteamid) p_jump + 1
                        if (server_var(p_r) = 4) then keymath stats_baz event_var(es_attackersteamid) p_gren + 1
                        if (server_var(p_r) = 5) then keymath stats_baz event_var(es_attackersteamid) p_invis + 1
                        if (server_var(p_r) = 6) then keymath stats_baz event_var(es_attackersteamid) p_skin + 1
                        if (server_var(p_r) = 7) then keymath stats_baz event_var(es_attackersteamid) p_speed + 1
                        if (server_var(p_r) = 8) then keymath stats_baz event_var(es_attackersteamid) p_defus + 1
                        es_format p_f "#lightgreenПобедитель конкурса: #green%1! #lightgreenВыиграл: #green%2!" event_var(es_attackername) server_var(p_nam)
                        es_msg #multi server_var(p_f)
                        if (server_var(p_sound) != 0) then es_xcexec_all play server_var(p_sound)
                        es_sexec event_var(attacker) say server_var(p_t)
                        es_xset p_start -1
                     }
                  }
               }
               else do
               {
                  if (server_var(p_rweap) = 2) do
                  {
                     if (event_var(headshot) = 1) do
                     {
                        es keymath stats_baz event_var(es_attackersteamid) p_k + 1
                        es_keygetvalue p_var stats_baz event_var(es_attackersteamid) p_k
                        if (server_var(p_var) = server_var(p_heads_req)) do
                        {
                           if (server_var(p_r) = 1) then keymath stats_baz event_var(es_attackersteamid) p_cash + server_var(p_val_cash)
                           if (server_var(p_r) = 2) then keymath stats_baz event_var(es_attackersteamid) p_hp + 1
                           if (server_var(p_r) = 3) then keymath stats_baz event_var(es_attackersteamid) p_jump + 1
                           if (server_var(p_r) = 4) then keymath stats_baz event_var(es_attackersteamid) p_gren + 1
                           if (server_var(p_r) = 5) then keymath stats_baz event_var(es_attackersteamid) p_invis + 1
                           if (server_var(p_r) = 6) then keymath stats_baz event_var(es_attackersteamid) p_skin + 1
                           if (server_var(p_r) = 7) then keymath stats_baz event_var(es_attackersteamid) p_speed + 1
                           if (server_var(p_r) = 8) then keymath stats_baz event_var(es_attackersteamid) p_defus + 1
                           es_format p_f "#lightgreenПобедитель конкурса: #green%1! #lightgreenВыиграл: #green%2!" event_var(es_attackername) server_var(p_nam)
                           es_msg #multi server_var(p_f)
                           if (server_var(p_sound) != 0) then es_xcexec_all play server_var(p_sound)
                           es_sexec event_var(attacker) say server_var(p_t)
                           es_xset p_start -1
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

event player_spawn
{
   es playerset color event_var(userid) 255 255 255 255
   es_keygetvalue p_var stats_baz event_var(es_steamid) p_invis
   if (server_var(p_var) > 0) then playerset color event_var(userid) 255 255 255 server_var(p_val_invis)
   es_keygetvalue p_var stats_baz event_var(es_steamid) p_skin
   ifx true(p_var) do
   {
      es playerset model event_var(userid) server_var(p_val_skin)
      if (event_var(es_userteam) = 2) then playerset color event_var(userid) 255 0 0 255
      if (event_var(es_userteam) = 3) then playerset color event_var(userid) 0 0 255 255
   }
   es_keygetvalue p_var stats_baz event_var(es_steamid) p_hp
   if (server_var(p_var) > 0) then playerset health event_var(userid) server_var(p_val_hp)
   es_keygetvalue p_var stats_baz event_var(es_steamid) p_speed
   if (server_var(p_var) > 0) then playerset speed event_var(userid) server_var(p_val_speed)
   es_keygetvalue p_var stats_baz event_var(es_steamid) p_cash
   if (server_var(p_var) > 0) do
   {
      es_getmoney p_get event_var(userid)
      if (server_var(p_get) < 5000) then es_xsexec event_var(userid) say !cash
   }
}

event hegrenade_detonate
{
   es_keygetvalue p_var stats_baz event_var(es_steamid) p_gren
   if (server_var(p_var) > 0) then es_xdelayed 1 keymath stats_baz event_var(es_steamid) p_gren - 1
}

event player_hurt
{
   if (event_var(weapon) = hegrenade) do
   {
      if (event_var(es_attackerteam) != event_var(es_userteam)) do
      {
         es_keygetvalue p_var stats_baz event_var(es_attackersteamid) p_gren
         if (server_var(p_var) > 0) do
         {
            es damage event_var(userid) 100 32 event_var(attacker)
            es_xmsg #green "Критическая граната!!!"
         }
      }
   }
}

event bomb_begindefuse
{
   es_keygetvalue p_var stats_baz event_var(es_steamid) p_defus
   if (server_var(p_var) > 0) do
   {
      es_xset index 0
      es_xgetentityindex index planted_c4
      es_setindexprop server_var(index) "CPlantedC4.m_flDefuseCountDown" 1.0
      es_xmsg #green "Моментальное обезвреживание!!!"
      es keymath stats_baz event_var(es_steamid) p_defus - 1
   }
}

///////////////////////////////

event round_end
{
   if (server_var(p_start) = -1) then es_xforeachkey k in stats_baz "es_keysetvalue stats_baz server_var(k) p_k 0"
   es_xdelayed 3 es_xkeygroupsave stats_baz "|world-source.ru/prize"
}

event round_start
{
   if (server_var(p_start) != 1) do
   {
      es_xgetplayercount p_var
      if (server_var(p_var) >= server_var(p_slots)) then es_xdoblock world-source.ru/prize/start
   }
}

block start
{
   es_xmath p_r + 1
   if (server_var(p_r) <= 8) do
   {
      es_keygetvalue p_var server_var(p_baz) server_var(p_r) p_vkl
      if (server_var(p_var) != 1) then es_xdoblock world-source.ru/prize/start
      else do
      {
         es_keygetvalue p_nam server_var(p_baz) server_var(p_r) p_nam
         es_xformatv p_f "#lightgreenЗапущен конкурс! #greenПриз: #default%1" p_nam
         es_xmsg #green > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
         es_msg #multi server_var(p_f)
         es_xset p_rweap 0
         es_xrand p_rweap 1 3
         if (server_var(p_rweap) = 1) do
         {
            es_xformatv p_f "#greenПолучит тот, кто первым сделает #lightgreen[ %1 ] убийств(а) ножом" p_knife_req
         }
         if (server_var(p_rweap) = 2) do
         {
            es_xformatv p_f "#greenПолучит тот, кто первым сделает #lightgreen[ %1 ] хедошот(а/ов)" p_heads_req
         }
         if (server_var(p_rweap) = 3) do
         {
            es_xformatv p_f "#greenПолучит тот, кто первым сделает #lightgreen[ %1 ] убийств(а)" p_deflt_req
         }
         es_msg #multi server_var(p_f)
         es_xmsg #green > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
         es_xset p_start 1
      }
   }
   else do
   {
      es_xset p_r 0
      es_xdoblock world-source.ru/prize/start
   }
}
