////////////////////////////////////////
// WCS - Warcraft:Source              //
// ---------------------------------- //
//  by kRypT0n!Te                     //
//      http://wcs.despo-clan.de      //
// ---------------------------------- //
// Content of this subscript          //
// - playerinfo                       //
// - showskills                       //
// - spendskills                      //
// - resetskills                      //
////////////////////////////////////////
// say commands:
// playerinfo, showskills
// spendskills, resetskills
//
// admin commands:
// wcs_spendskills <userid>
// wcs_showplayerinfo <userid>
// wcs_showskills <userid>
// wcs_resetskills <userid>
//
////////////////////////////////////////

block load
{
	es_xexists wcs_exists command playerinfo
  es es_xif (server_var(wcs_exists) = 0) then es_xregsaycmd playerinfo wcs/WCSusers/wcs_showplayerinfo "Shows detail info about the players"
	es_xexists wcs_exists command resetskills
  es es_xif (server_var(wcs_exists) = 0) then es_xregsaycmd resetskills wcs/WCSusers/wcs_resetskills "Reset your skills"
  es_xexists wcs_exists command showskills
  es es_xif (server_var(wcs_exists) = 0) then es_xregsaycmd showskills wcs/WCSusers/wcs_showskills "Shows your skills levels"
  es_xexists wcs_exists command spendskills
  es es_xif (server_var(wcs_exists) = 0) then es_xregsaycmd spendskills wcs/WCSusers/wcs_spendskills "Lets you spend skill points"
  es_xexists wcs_exists command wcs_showskills
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_showskills wcs/WCSusers/wcs_showskills "Shows your skills levels"
  es_xexists wcs_exists command wcs_spendskills
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_spendskills wcs/WCSusers/wcs_spendskills "wcs_spendskills - usage: wcs_spendskills <userid>"
  es_xexists wcs_exists command wcs_resetskills
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_resetskills wcs/WCSusers/wcs_resetskills "Reset your skills"
	es_xexists wcs_exists command wcs_showplayerinfo
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_showplayerinfo wcs/WCSusers/wcs_showplayerinfo "Shows detail info about players"
  es_xexists wcs_exists command showcredits
  es es_xif (server_var(wcs_exists) = 0) then es_xregsaycmd showcredits wcs/WCSusers/wcs_showcredits "Shows your credits (DOD:S only)"
	// load the users (create if load fails)
  es_xkeygroupcreate "WCSusers"
  echo "WCS: trying to load the .txt userdatabase..."
  es es_xif (server_var(wcs_turbomode) != "1") then es_xkeygroupload "WCSusers" "|wcs/WCSusers"
  es es_xif (server_var(wcs_turbomode) = "1") do
  {
  	es_xsetinfo wcs_showtotalplayers 0
    es_xsetinfo wcs_enabletop10 0
  }
  es es_xif (server_var(wcs_showtotalplayers) = "1") do
  {
    es_xsetinfo wcs_totalplayers 0
    es_xforeachkey wcs_key in "WCSusers" "es_xmath wcs_totalplayers + 1"
    es echo "Total players : " server_var(wcs_totalplayers)
  }
	es_xkeygroupcreate "WCSuserdata"
}

block unload
{
	es es_xif (server_var(wcs_turbomode) != "1") then es_xif (server_var(wcs_cfg_enabletxtfile) = "1") then es_xkeygroupsave "WCSusers" "|wcs/WCSusers"
  es_xkeygroupdelete "WCSusers"
  es_xkeygroupdelete "WCSuserdata"
}


event player_disconnect
{
  // and save the latest record
  es es_xexists wcs_exists key "WCSuserdata" event_var(userid)
  es es_xif (server_var(wcs_exists) = "1") do
  {
  es wcs_saveplayer event_var(userid)
  es es_xif (server_var(wcs_cfg_enablesql) = "1") then wcs_sql_setplayer event_var(userid)
  // remove userdata key
    es es_xkeydelete "WCSuserdata" event_var(userid)
  }
}


// >>>>>>>>>>>>>>>>> PLAYERINFO >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
block wcs_showplayerinfo
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_showplayerinfo start
  // first, is it a custom command ?
  es_xsetinfo wcs_userid 0
  es_xgetargv wcs_userid 1
  es es_xexists wcs_exists userid server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = 0) do
  {
    // or a say command
    es_xgetcmduserid wcs_userid
    es es_xexists wcs_exists userid server_var(wcs_userid)
    es wcs_menuzero server_var(wcs_userid)
    //es_xdoblock wcs/WCSusers/wcs_playerinfo
  }
  es es_xif (server_var(wcs_exists) = "1") do
  {
    es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) "menu" "playerinfo"
    es es_xkeygetvalue wcs_page "WCSuserdata" server_var(wcs_userid) "page"
    es_xmath wcs_page + 1
    es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) page server_var(wcs_page)
    //es es_xkeygetvalue wcs_infotext "WCSinfo" "playerinfo" server_var(wcs_page)
    es_xsetinfo wcs_upper 7
    es_xsetinfo wcs_lower 0
    es es_xmath wcs_upper * server_var(wcs_page)
    es_xcopy wcs_lower wcs_upper
    es_xmath wcs_lower - 7
    es_xsetinfo wcs_counter 1
    es_xsetinfo wcs_playercount 0
    es es_xformat wcs_text "%1 %2\n " server_var(wcs_lng_page) server_var(wcs_page)
    es es_xforeachkey wcs_key in WCSuserdata "es es_xif(server_var(wcs_counter) > server_var(wcs_lower)) then es_xif (server_var(wcs_counter) <= server_var(wcs_upper)) then es_xdoblock wcs/WCSusers/wcs_playerinfo;es_xmath wcs_counter + 1"
    es es_xformat wcs_text "%1\n \n" server_var(wcs_text)
    es es_xif (server_var(wcs_page) > 1) then es_xformat wcs_text "%1\n->8. %2" server_var(wcs_text) server_var(wcs_lng_back)
    es es_xif (server_var(wcs_counter) > server_var(wcs_upper)) then es_xformat wcs_text "%1\n->9. %2" server_var(wcs_text) server_var(wcs_lng_next)
    es es_xformat wcs_text "%1\n->0. %2" server_var(wcs_text) server_var(wcs_lng_exit)
    es es_xstrlen wcs_strlen server_var(wcs_text)
    es es_xif (server_var(wcs_strlen) > 1) then es_xmenu 0 server_var(wcs_userid) server_var(wcs_text)
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_showplayerinfo end
}

block wcs_playerinfo
{
  // server_var(wcs_key) = userid !
  es es_xexists wcs_exists userid server_var(wcs_key)
  es es_xif (server_var(wcs_exists) = "1") do
  {
  	es_xmath wcs_playercount + 1
    es es_xgetplayername wcs_name server_var(wcs_key)
    es es_xformat wcs_text "%1\n->%2. %3 " server_var(wcs_text) server_var(wcs_playercount) server_var(wcs_name)
  }
}

block wcs_playerinfo_details
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_playerinfo_details start
  // server_var(wcs_key) !!
  es es_xexists wcs_exists userid server_var(wcs_key)
  es es_xif (server_var(wcs_exists) = 1) do
  {
    es es_xkeygetvalue wcs_race "WCSuserdata" server_var(wcs_key) "race"
    es es_xkeygetvalue wcs_level "WCSuserdata" server_var(wcs_key) "level"
    es es_xgetplayername wcs_name server_var(wcs_key)
    es es_xkeygetvalue wcs_racename "WCSraces" server_var(wcs_race) "name"
    es es_xkeygetvalue wcs_total_level WCSuserdata server_var(wcs_key) total_level
    es es_xkeygetvalue wcs_numberofskills "WCSraces" server_var(wcs_race) "numberofskills"
    wcs_getlanguage "wcs_lng" "wcs_lng_level"
    wcs_getlanguage "wcs_lng2" "wcs_lng_total"
    es es_xformat wcs_text "\n->1. %1\n -----------------------\n o %2 %3 %4 \n -----------------------\n o %5 : %6 %7" server_var(wcs_name) server_var(wcs_lng2) server_var(wcs_lng) server_var(wcs_total_level) server_var(wcs_racename) server_var(wcs_lng) server_var(wcs_level)
    // get skills
    es es_xkeygetvalue wcs_skillname "WCSraces" server_var(wcs_race) "skillnames"
    es_xsetinfo wcs_counter 1
    es_xsetinfo wcs_tmp "%1\n  - %2 : %3"
   	es es_xif (server_var(wcs_numberofskills) > 0) then while "server_var(wcs_counter) <= server_var(wcs_numberofskills)" "es es_xformat wcs_skill skill_%1 server_var(wcs_counter);es es_xkeygetvalue wcs_skilllevel WCSuserdata server_var(wcs_key) server_var(wcs_skill);es es_xtoken wcs_name server_var(wcs_skillname) server_var(wcs_counter) |;es es_xformat wcs_text server_var(wcs_tmp) server_var(wcs_text) server_var(wcs_name) server_var(wcs_skilllevel);es_xmath wcs_counter + 1"
   	es es_xformat wcs_text "%1\n -----------------------\n" server_var(wcs_text)
   	// get credits
   	es es_xkeygetvalue wcs_tmp1 WCSuserdata server_var(wcs_key) "credits"
   	wcs_getlanguage "wcs_lng" "wcs_lng_credits"
   	es es_xif (server_var(wcs_tmp1) != "0") then es_xformat wcs_text "%1 o %2 : $ %3\n" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_tmp1)
   	// get skulls
   	es es_xkeygetvalue wcs_tmp1 WCSuserdata server_var(wcs_key) "skulls"
   	wcs_getlanguage "wcs_lng" "wcs_lng_skulls"
   	es es_xif (server_var(wcs_tmp1) != "0") then es_xformat wcs_text "%1 o %2 : %3\n" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_tmp1)
   	// get speed
   	es es_xkeygetvalue wcs_tmp1 WCSuserdata server_var(wcs_key) "speed"
   	wcs_getlanguage "wcs_lng" "wcs_lng_speed"
   	es es_xif (server_var(wcs_tmp1) != "0") then es_xif (server_var(wcs_tmp1) != 1) then es_xmath wcs_tmp1 * 100
   	es es_xif (server_var(wcs_tmp1) != "0") then est_RoundDecimal wcs_tmp1 server_var(wcs_tmp1) 0
   	es es_xif (server_var(wcs_tmp1) != "0") then es_xif (server_var(wcs_tmp1) != 1) then es_xformat wcs_text "%1 o %2 : %3 %\n" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_tmp1)
   	// get gravity
   	es es_xkeygetvalue wcs_tmp1 WCSuserdata server_var(wcs_key) "gravity"
   	wcs_getlanguage "wcs_lng" "wcs_lng_gravity"
   	es es_xif (server_var(wcs_tmp1) != "0") then es_xmath wcs_tmp1 * 100
   	es es_xif (server_var(wcs_tmp1) != "0") then est_RoundDecimal wcs_tmp1 server_var(wcs_tmp1) 0
   	es es_xif (server_var(wcs_tmp1) != "0") then es_xformat wcs_text "%1 o %2 : %3 %\n" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_tmp1)
   	// get invisibility
   	es es_xkeygetvalue wcs_tmp1 WCSuserdata server_var(wcs_key) "invisp"
   	wcs_getlanguage "wcs_lng" "wcs_lng_invisibility"
   	es es_xif (server_var(wcs_tmp1) != "0") then est_RoundDecimal wcs_tmp1 server_var(wcs_tmp1) 0
   	es es_xif (server_var(wcs_tmp1) != "0") then es_xformat wcs_text "%1 o %2 : %3 %\n" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_tmp1)
    // get health
    es es_xgetplayerprop wcs_dead server_var(wcs_key) "CCSPlayer.baseclass.pl.deadflag"
   	es es_xif (server_var(wcs_dead) = "0") do
   	{
   	  es est_GetHealth wcs_tmp1 server_var(wcs_key)
   	  wcs_getlanguage "wcs_lng" "wcs_lng_health"
   	  es es_xif (server_var(wcs_tmp1) != "100") then es_xformat wcs_text "%1 o %2 : %3 %\n" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_tmp1)
   	}
    es es_xformat wcs_text "%1\n \n->8. %2" server_var(wcs_text) server_var(wcs_lng_back)
    es es_xmenu 0 event_var(userid) server_var(wcs_text)
    es_xmath wcs_page + 1
    es es_xkeysetvalue "WCSuserdata" event_var(userid) "page" server_var(wcs_page)
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_playerinfo_details end
}
// <<<<<<<<<<<<<<<<< END PLAYERINFO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


// >>>>>>>>>>>>>>>>> SHOW/SPEND/RESET SKILLS BLOCKS >>>>>>>>>>>>>>>>>>>>>>>>>>>>
block wcs_showskills
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_showskills start
  // first, is it a custom command ?
  es_xsetinfo wcs_userid 0
  es_xgetargv wcs_userid 1
  es es_xexists wcs_exists userid server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = 0) do
  {
    // or a say command
    es_xgetcmduserid wcs_userid
    es es_xexists wcs_exists userid server_var(wcs_userid)
  }
  // clean up
  es wcs_menuzero server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = 1) do
  {
    es es_xexists wcs_exists key "WCSuserdata" server_var(wcs_userid)
    es es_xif (server_var(wcs_exists) = 1) do
    {
      es es_xkeygetvalue wcs_race "WCSuserdata" server_var(wcs_userid) "race"
      es es_xkeygetvalue wcs_racename "WCSraces" server_var(wcs_race) "name"
      es es_xkeygetvalue wcs_numberofskills "WCSraces" server_var(wcs_race) "numberofskills"
      es es_xkeygetvalue wcs_unused "WCSuserdata" server_var(wcs_userid) "unused"
      wcs_getlanguage "wcs_lng" "wcs_lng_your"
      wcs_getlanguage "wcs_lng2" "wcs_lng_skills"
      es es_xformat wcs_text "%1 %2 %3:" server_var(wcs_lng) server_var(wcs_racename) server_var(wcs_lng2)
      es_xsetinfo wcs_counter 1
      es es_xif (server_var(wcs_numberofskills) > 0) then while "server_var(wcs_counter) <= server_var(wcs_numberofskills)" "es es_xformat wcs_val skill_%1 server_var(wcs_counter);es_xdoblock wcs/WCSusers/wcs_showskills_init;es_xmath wcs_counter + 1"
      wcs_getlanguage "wcs_lng" "wcs_lng_unusedpoints"
      es es_xformat wcs_text "%1\n \n %2 : %3\n" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_unused)
      es es_xstrlen wcs_strlen server_var(wcs_text)
      es es_xif (server_var(wcs_strlen) > 1) then es_xmenu 0 server_var(wcs_userid) server_var(wcs_text)
    }
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_showskills end
}

block wcs_showskills_init
{
  // get the name, level
  es es_xkeygetvalue wcs_skillname "WCSraces" server_var(wcs_race) "skillnames"
  es es_xtoken wcs_skillname server_var(wcs_skillname) server_var(wcs_counter) "|"
  es es_xkeygetvalue wcs_skilllevel "WCSuserdata" server_var(wcs_userid) server_var(wcs_val)
  // get details
  es es_xif (server_var(wcs_showskills_details) = "1") do
  {
    es es_xkeygetvalue wcs_skilldescr "WCSraces" server_var(wcs_race) "skilldescr"
    es es_xtoken wcs_skilldescr server_var(wcs_skilldescr) server_var(wcsc_counter) "|"
    es es_xformat wcs_text "%1\n->%2. %3 : %4 (%5)" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_skillname) server_var(wcs_skilllevel) server_var(wcs_skilldescr)
  }
  es_xelse do
  {
    es es_xformat wcs_text "%1\n->%2. %3 : %4" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_skillname) server_var(wcs_skilllevel)
  }
}

block wcs_spendskills
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_spendskills start
  // first, is it a custom command ?
  es_xgetargv wcs_userid 1
  es wcs_menuzero server_var(wcs_userid)
  es es_xexists wcs_exists userid server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = 0) do
  {
    // or a say command
    es_xgetcmduserid wcs_userid
    es es_xexists wcs_exists userid server_var(wcs_userid)
  }
  es es_xif (server_var(wcs_exists) = 1) do
  {
    es es_xkeygetvalue wcs_id "WCSuserdata" server_var(wcs_userid) "id"
    es es_xkeygetvalue wcs_race "WCSuserdata" server_var(wcs_userid) "race"
    es es_xkeygetvalue wcs_racename "WCSraces" server_var(wcs_race) "name"
    es es_xkeygetvalue wcs_unused "WCSuserdata" server_var(wcs_userid) "unused"
    es es_xkeygetvalue wcs_level "WCSuserdata" server_var(wcs_userid) "level"
    es es_xkeygetvalue wcs_numberoflevels "WCSraces" server_var(wcs_race) "numberoflevels"
    es es_xkeygetvalue wcs_numberofskills "WCSraces" server_var(wcs_race) "numberofskills"
    es es_xsetinfo wcs_maxlevel server_var(wcs_numberoflevels)
    es es_xmath wcs_maxlevel * server_var(wcs_numberofskills)
    es es_xsetinfo wcs_leveldiff server_var(wcs_level)
    es es_xmath wcs_leveldiff - server_var(wcs_unused)
    // Bot support
    es es_xif ("BOT" in server_var(wcs_id)) do
    {
    	es es_xif (server_var(wcs_maxlevel) > server_var(wcs_leveldiff)) do
      {
      	// spend skillpoints on a random skill (ignore required level !)
      	es_xsetinfo wcs_counter 1
      	es es_xif (server_var(wcs_numberofskills) > 0) then while "server_var(wcs_counter) < server_var(wcs_maxlevel)" "es_xdoblock wcs/WCSusers/wcs_spendskills_bot;es_xmath wcs_counter + 1"
        es es_xkeysetvalue WCSuserdata server_var(wcs_userid) unused server_var(wcs_unused)
      }
    	es_xsetinfo wcs_exists 0
    }
    // for human spendskills
    es es_xif (server_var(wcs_exists) = 1) do
    {
      es es_xif (server_var(wcs_maxlevel) > server_var(wcs_leveldiff)) do
      {
      	wcs_getlanguage "wcs_lng" "wcs_lng_spendskills_1"
      	wcs_getlanguage "wcs_lng2" "wcs_lng_skills"
        es es_xformat wcs_text "%1 %2 %3:" server_var(wcs_lng) server_var(wcs_racename) server_var(wcs_lng2)
        es_xsetinfo wcs_counter 1
        es es_xif (server_var(wcs_numberofskills) > 0) then while "server_var(wcs_counter) <= server_var(wcs_numberofskills)" "es es_xformat wcs_val skill_%1 server_var(wcs_counter);es_xdoblock wcs/WCSusers/wcs_spendskills_init;es_xmath wcs_counter + 1"
        wcs_getlanguage "wcs_lng" "wcs_lng_unusedpoints"
        es es_xformat wcs_text "%1\n \n %2 : %3\n \n 0. %4" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_unused) server_var(wcs_lng_exit)
        es es_xstrlen wcs_strlen server_var(wcs_text)
        es es_xif (server_var(wcs_strlen) > 1) then es_xmenu 0 server_var(wcs_userid) server_var(wcs_text)
        es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) "menu" "level"
      }
      es_xelse do
      {
      	wcs_getlanguage "wcs_lng" "wcs_lng_maxlvlreached"
        es es_xtell server_var(wcs_userid) #multi server_var(wcs_lng)
      }
    }
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_spendskills end
}

block wcs_spendskills_bot
{
	es es_xrand wcs_skill 1 server_var(wcs_numberofskills)
	es es_xif (server_var(wcs_level) < server_var(wcs_ultimatelevel)) then es_xif (server_var(wcs_skill) = server_var(wcs_numberofskills)) then es_xsetinfo wcs_skill "1"
	es es_xformat wcs_val "skill_%1" server_var(wcs_skill)
	es es_xkeygetvalue wcs_tmp WCSuserdata server_var(wcs_userid) server_var(wcs_val)
	es_xcopy wcs_tmp1 wcs_tmp
	es es_xif (server_var(wcs_tmp1) < server_var(wcs_numberoflevels)) then es_xif (server_var(wcs_unused) >= 1) then es_xmath wcs_tmp + 1
	es es_xif (server_var(wcs_tmp1) < server_var(wcs_numberoflevels)) then es_xif (server_var(wcs_unused) >= 1) then es_xmath wcs_unused - 1
	es es_xkeysetvalue WCSuserdata server_var(wcs_userid) server_var(wcs_val) server_var(wcs_tmp)
	es es_xif (server_var(wcs_unused) <= 0) then es_xsetinfo wcs_counter server_var(wcs_maxlevel)
}

block wcs_spendskills_init
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_spendskills_init start
  es es_xif (server_var(wcs_val) != "0") do
  {
    // get the name
    es es_xkeygetvalue wcs_skillname "WCSraces" server_var(wcs_race) "skillnames"
    es es_xtoken wcs_skillname server_var(wcs_skillname) server_var(wcs_counter) "|"
    // get the level
    es es_xkeygetvalue wcs_skilllevel "WCSuserdata" server_var(wcs_userid) server_var(wcs_val)
    es es_xif (server_var(wcs_skilllevel) < server_var(wcs_numberoflevels)) do
    {
      // check if its not an ultimate
      es es_xif (server_var(wcs_counter) != server_var(wcs_numberofskills)) do
      {
        es es_xsetinfo wcs_skilllevel2 server_var(wcs_skilllevel)
        es_xmath wcs_skilllevel2 + 1
        es es_xformat wcs_text "%1\n->%2. %3 : %4 > %5" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_skillname) server_var(wcs_skilllevel) server_var(wcs_skilllevel2)
      }
      es_xelse do
      {
        // ultimate (level check)
        es es_xif (server_var(wcs_level) >= server_var(wcs_ultimatelevel)) do
        {
          // level ultimate
          es es_xsetinfo wcs_skilllevel2 server_var(wcs_skilllevel)
          es_xmath wcs_skilllevel2 + 1
          es es_xformat wcs_text "%1\n->%2. %3 (ultimate) : %4 > %5" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_skillname) server_var(wcs_skilllevel) server_var(wcs_skilllevel2)
        }
        es_xelse do
        {
          es es_xformat wcs_text "%1\n%2. %3 (ultimate) : %4" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_skillname) server_var(wcs_skilllevel)
        }
      }
    }
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_spendskills_init end
}

block wcs_spendskills_handle
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_spendskills_handle begin
  es es_xexists wcs_exists key "WCSuserdata" event_var(userid)
  es es_xif (server_var(wcs_exists) = 1) do
  {
    // get skill details
    es es_xkeygetvalue wcs_race "WCSuserdata" event_var(userid) "race"
    es es_xkeygetvalue wcs_unused "WCSuserdata" event_var(userid) "unused"
    es es_xkeygetvalue wcs_level "WCSuserdata" event_var(userid) "level"
    es es_xkeygetvalue wcs_numberoflevels "WCSraces" server_var(wcs_race) "numberoflevels"
    es es_xkeygetvalue wcs_numberofskills "WCSraces" server_var(wcs_race) "numberofskills"
    es es_xif (event_var(commandstring) != "10") do
    {
      // user must have free skill points
      es es_xif (server_var(wcs_unused) > 0) do
      {
        // check number of skills and levels
        es es_xif (event_var(commandstring) <= server_var(wcs_numberofskills)) do
        {
          es es_xformat wcs_skill "skill_%1" event_var(commandstring)
          es es_xkeygetvalue wcs_skilllevel "WCSuserdata" event_var(userid) server_var(wcs_skill)
          es es_xif (server_var(wcs_skilllevel) < server_var(wcs_numberoflevels)) do
          {
          	es_xsetinfo wcs_tmp2 0
            es es_xif (event_var(commandstring) != server_var(wcs_numberofskills)) do
            {
              // do the spendskills
              es_xsetinfo wcs_tmp2 1
            }
            es_xelse do
            {
              // ultimate - check level
              es es_xif (server_var(wcs_level) >= server_var(wcs_ultimatelevel)) do
              {
              	// do the spendskills
                es_xsetinfo wcs_tmp2 1
              }
              es_xelse do
              {
              	wcs_getlanguage "wcs_lng" "wcs_lng_lowlevel"
                es es_xformat wcs_text server_var(wcs_lng) server_var(wcs_ultimatelevel)
                es es_xtell event_var(userid) #multi server_var(wcs_text)
                es es_xkeysetvalue "WCSuserdata" event_var(userid) "menu" "0"
              }
            }
            es es_xif (server_var(wcs_tmp2) = 1) do
            {
            	// no ultimate
              es_xmath wcs_skilllevel + 1
              es_xmath wcs_unused - 1
              // store values
              es es_xkeysetvalue WCSuserdata event_var(userid) server_var(wcs_skill) server_var(wcs_skilllevel)
              es es_xkeysetvalue WCSuserdata event_var(userid) "unused" server_var(wcs_unused)
              es es_xkeygetvalue wcs_skillname "WCSraces" server_var(wcs_race) "skillnames"
              es es_xtoken wcs_skillname server_var(wcs_skillname) event_var(commandstring) "|"
              wcs_getlanguage "wcs_lng" "wcs_lng_yourskill"
              wcs_getlanguage "wcs_lng2" "wcs_lng_nowonlevel"
              es es_xformat wcs_text "#lightgreen%1 #green'%2' #lightgreen%3 #green%4." server_var(wcs_lng) server_var(wcs_skillname) server_var(wcs_lng2) server_var(wcs_skilllevel)
              wcs_getlanguage "wcs_lng" "wcs_lng_yournewskill"
              wcs_getlanguage "wcs_lng3" "wcs_lng_spendskillshint"
              es es_xif (server_var(wcs_skilllevel) = 1) then es_xformat wcs_text "#lightgreen%1 #green'%2' #lightgreen%3 #green%4#lightgreen, %5." server_var(wcs_lng) server_var(wcs_skillname) server_var(wcs_lng2) server_var(wcs_skilllevel) server_var(wcs_lng3)
              es es_xtell event_var(userid) #multi server_var(wcs_text)
            }
            // refresh the skills
            es es_xkeysetvalue "WCSuserdata" event_var(userid) "skillcheck" "1"
          }
        }
      }
      es_xelse do
      {
      	wcs_getlanguage "wcs_lng" "wcs_lng_nofreepoints"
        es es_xtell event_var(userid) #multi server_var(wcs_lng)
        es es_xkeysetvalue "WCSuserdata" event_var(userid) menu "0"
      }
      // user should spend more skills
      es es_xif (server_var(wcs_unused) >= 1) then wcs_spendskills event_var(userid)
    }
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_spendskills_handle end
}

block wcs_resetskills
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_resetskills start
  // first, is it a custom command ?
  es_xsetinfo wcs_userid 0
  es_xgetargv wcs_userid 1
  es es_xexists wcs_exists userid server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = 0) do
  {
    // or a say command
    es_xgetcmduserid wcs_userid
    es es_xexists wcs_exists userid server_var(wcs_userid)
  }
  // check if its valid
  es es_xif (server_var(wcs_exists) = 1) do
  {
    es_xsetinfo wcs_dead "1"
    es es_xgetplayerprop wcs_dead server_var(wcs_userid) "CCSPlayer.baseclass.pl.deadflag"
    es es_xif (server_var(wcs_dead) = "0") do
    {
      es es_xkeygetvalue wcs_tmp "WCSuserdata" server_var(wcs_userid) "resetskills"
      es es_xif (server_var(wcs_tmp) = "1") do
      {
        es est_slay server_var(wcs_userid)
        es_xsetinfo wcs_dead "1"
        es es_xkeysetvalue WCSuserdata server_var(wcs_userid) "resetskills" "0"
      }
    }
    es es_xif (server_var(wcs_dead) = "1") do
    {
      // get user race
      es es_xkeygetvalue wcs_race "WCSuserdata" server_var(wcs_userid) "race"
      // reset any skill to 0
      es es_xforeachval wcs_val in "WCSuserdata" server_var(wcs_userid) "es es_xif (skill_ in server_var(wcs_val)) then es_xkeysetvalue WCSuserdata server_var(wcs_userid) server_var(wcs_val) 0"
      // all skills are unused now
      es es_xkeygetvalue wcs_level "WCSuserdata" server_var(wcs_userid) "level"
      es es_xkeysetvalue WCSuserdata server_var(wcs_userid) "unused" server_var(wcs_level)
      wcs_getlanguage "wcs_lng" "wcs_lng_skillsreseted"
      es es_xformat wcs_text server_var(wcs_lng) server_var(wcs_level)
      es es_xtell server_var(wcs_userid) #multi server_var(wcs_text)
      es wcs_saveplayer server_var(wcs_userid)
      // refresh skills
      es es_xkeysetvalue WCSuserdata server_var(wcs_userid) "skillcheck" "1"
      // check if penalty is set
      es es_xif(server_var(wcs_cfg_resetskillspenalty) > 0) do
      {
      	es_xcopy wcs_tmp wcs_level
      	es es_xmath wcs_tmp * server_var(wcs_levelxp)
      	es es_xmath wcs_tmp * server_var(wcs_cfg_resetskillspenalty)
      	es_xmath wcs_tmp / 100
      	es est_RoundDecimal wcs_tmp server_var(wcs_tmp) 0
      	es es_xif (server_var(wcs_tmp) > 0) do
      	{
      		wcs_getlanguage "wcs_lng" "wcs_lng_resetskillspenalty"
      		es es_xformat wcs_lng server_var(wcs_lng) server_var(wcs_cfg_resetskillspenalty)
      		es_xmath wcs_tmp * -1
      		es wcs_givexp server_var(wcs_userid) server_var(wcs_tmp) server_var(wcs_lng)
        }
      }
    }
    es_xelse do
    {
    	wcs_getlanguage "wcs_lng" "wcs_lng_cannotreset"
      es es_xtell server_var(wcs_userid) #multi server_var(wcs_lng)
      es es_xkeysetvalue WCSuserdata server_var(wcs_userid) resetskills "1"
    }
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_resetskills end
}
// <<<<<<<<<<<<<<<<< END SHOW/SPEND/RESET SKILLS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

block wcs_showcredits
{
  es es_xif (server_var(wcs_game) != server_var(wcs_game_css)) do
  {
    // first, is it a custom command ?
    es_xgetargv wcs_userid 1
    es es_xexists wcs_exists userid server_var(wcs_userid)
    es es_xif (server_var(wcs_exists) = 0) do
    {
      // or a say command
      es_xgetcmduserid wcs_userid
      es es_xexists wcs_exists userid server_var(wcs_userid)
    }
    // check if its valid
    es es_xif (server_var(wcs_exists) = 1) do
    {
      es es_xexists wcs_exists key "WCSuserdata" server_var(wcs_userid)
      es es_xif (server_var(wcs_exists) = 1) do
      {
        es_xsetinfo wcs_credits 0
        es es_xkeygetvalue wcs_credits "WCSuserdata" server_var(wcs_userid) "credits"
        wcs_getlanguage "wcs_lng" "wcs_lng_youhave"
        wcs_getlanguage "wcs_lng2" "wcs_lng_credits"
        es es_xformat wcs_text "#lightgreen%1 #green%2 %3." server_var(wcs_lng) server_var(wcs_credits) server_var(wcs_lng2)
        es es_xtell server_var(wcs_userid) #multi server_var(wcs_text)
      }
    }
  }
}
