//-------------------------------------------------------------------------------------------
// PlayerGetSet v1.01
// by Don
// 9/24/06
//
// Description:
// This script registers 2 commands, playerget and playerset.
//
// Installation:
// Create a directory called playergetset under cstrike/addons/eventscripts.
// Copy this file(es_playergetset.txt) to this directory.
// Put "es_load playergetset" into your autoexec.cfg.
// Restart your server.
//
// Use: playerget <item>
// playerget primary <var> <userid> [var_index] - Get the players Primary weapon
// playerget secondary <var> <userid> [var_index] - Get the players Secondary weapon
// playerget he <var> <userid> [var_index] - 1/0 if the player has an HE Grenade
// playerget sg <var> <userid> [var_index] - 1/0 if the player has a Smoke Grenade
// playerget fb <var> <userid> - 1/0 if the player has a Flashbang
// playerget c4 <var> <userid> [var_index] - 1/0 if the player has a Bomb
// playerget weaponindex <var> <userid> <weapon_name> - Get the index of the player's weapon
// playerget ammo <var> <userid> <weapon / slot> - Get the amount of ammo in the player's reserve
// playerget clip <var> <userid> <weapon / slot> - Get the amount of ammo in the player's clip
// playerget viewangle <userid> <return pitch> <return yaw> <return roll> - Get the angle the player is looking
// playerget health <var> <userid> - Get the player's health
// playerget armor <var> <userid> - Get the player's armor
// playerget speed <var> <userid> - Get the player's speed
// playerget cash <var> <userid> - Get the player's cash
// playerget defuser <var> <userid> - 1/0 if the player has a defuser
//
// Use: playerset <item>
// playerset ammo <userid> <weapon / slot> <amount> - Set the amount of ammo in the player's reserve
// playerset clip <userid> <weapon / slot> <amount> - Set the amount of ammo in the player's clip
// playerset health <userid> <var> - Set the player's health
// playerset armor <userid> <var> - Set the player's armor
// playerset speed <userid> <var> - Set the player's speed
// playerset cash <userid> <var> - Set the player's cash
// playerset defuser <userid> <var> - Give or take the player's defuser
// playerset nightvision <userid> <var> - Give or take the player's nightvision
// playerset nightvisionon <userid> <var> - Set the player's nightvision on or off
//
// [var_index] is optional - will return the index of the weapon.
//
//-------------------------------------------------------------------------------------------
block load
{
  es_xdoblock corelib/playergetset/playergetset_register
}

block playergetset_register
{
  //variables used by playergetset
  es_xsetinfo _playergetset_find 0
  es_xsetinfo _playergetset_owner 0
  es_xsetinfo _playergetset_userid 0
  es_xsetinfo _playergetset_tempid 0
  es_xsetinfo _playergetset_tempvar 0
  es_xsetinfo _playergetset_cmd 0
  es_xsetinfo _playergetset_arg1 0
  es_xsetinfo _playergetset_arg2 0
  es_xsetinfo _playergetset_arg3 0
  es_xsetinfo _playergetset_arg4 0
  es_xsetinfo _playergetset_temparg1 0
  es_xsetinfo _playergetset_temparg2 0
  es_xsetinfo _playergetset_temparg3 0
  es_xsetinfo _playergetset_hasparam 0
  es_xsetinfo _playergetset_block 0
  es_xsetinfo _playergetset_p1x 0
  es_xsetinfo _playergetset_p1y 0
  es_xsetinfo _playergetset_p1z 0
  es_xsetinfo _playergetset_p1x 0
  es_xsetinfo _playergetset_p2x 0
  es_xsetinfo _playergetset_p2y 0
  es_xsetinfo _playergetset_p2z 0
  es_xsetinfo _playergetset_p1vec 0
  es_xsetinfo _playergetset_p2vec 0
  es_xsetinfo _playergetset_p12vec 0
  es_xsetinfo _playergetset_atan 0
  es_xsetinfo _playergetset_tempx 0
  es_xsetinfo _playergetset_tempy 0
  es_xsetinfo _playergetset_xangle 0
  es_xsetinfo _playergetset_yangle 0
  es_xsetinfo _playergetset_divpi 57.295779524
  es_xsetinfo _playergetset_realangle 0
  es_xdoblock corelib/playergetset/createprimary
  es_xdoblock corelib/playergetset/createsecondary
  //check to see if playergetset exists
  es_xexists _exists command playerget
  if (server_var(_exists) = 0) do
  {
    es_xregcmd playerget corelib/playergetset/_playerget "Get various user items"
  }
  es_xexists _exists command playerset
  if (server_var(_exists) = 0) do
  {
    es_xregcmd playerset corelib/playergetset/_playerset "Set various user items"
  }
}

block unload
{
  es_xkeygroupdelete _primaryweapons
  es_xkeygroupdelete _secondaryweapons
}

block _playerget
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 1) do
  {
    es_xgetargv _playergetset_cmd 1
    es es_xif (server_var(_playergetset_cmd) == viewangle) do
    {
      es_xgetargv _playergetset_userid 2
    }
    else do
    {
      es_xgetargv _playergetset_userid 3
    }
    es es_xformat _playergetset_block "corelib/playergetset/get%1" server_var(_playergetset_cmd)
    es es_xif (server_var(_playergetset_arg1) > 2) do
    {
      es es_xgetuserid _playergetset_userid server_var(_playergetset_userid)
      es es_xif (server_var(_playergetset_userid) = 0) do
      {
        es_xdbgmsg 0 Player not found!
      }
      else do
      {
        es es_xdoblock server_var(_playergetset_block)
      }
    }
    else do
    {
      es es_xdoblock server_var(_playergetset_block)
    }
  }
  else do
  {
    es_xdbgmsg 0 Type playerget primary|secondary|he|sg|fb|c4|ammo|clip|weaponindex|viewangle|health|armor|speed|defuser
  }
}

block _playerset
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 1) do
  {
    es_xgetargv _playergetset_cmd 1
    es es_xformat _playergetset_block "corelib/playergetset/set%1" server_var(_playergetset_cmd)
    es es_xif (server_var(_playergetset_arg1) > 2) do
    {
      es_xgetargv _playergetset_userid 2
      es es_xgetuserid _playergetset_userid server_var(_playergetset_userid)
      es es_xif (server_var(_playergetset_userid) = 0) do
      {
        es_xdbgmsg 0 Player not found!
      }
      else do
      {
        es es_xdoblock server_var(_playergetset_block)
      }
    }
    else do
    {
      es es_xdoblock server_var(_playergetset_block)
    }
  }
  else do
  {
    es_xdbgmsg 0 Type playerset ammo|clip|health|armor|speed|cash|defuser|nightvision|nightvisionon|viewplayer
  }
}

block setviewplayer
{
  es_xgetargc _playergetset_temparg1
  if (server_var(_playergetset_temparg1) > 2) do
  {
    es_xgetargv _playergetset_temparg1 2
    es_xgetargv _playergetset_temparg2 3
    es es_xgetplayerlocation _playergetset_p1x _playergetset_p1y _playergetset_p1z server_var(_playergetset_temparg1)
    es es_xgetplayerlocation _playergetset_p2x _playergetset_p2y _playergetset_p2z server_var(_playergetset_temparg2)
    es es_xcreatevectorstring _playergetset_p1vec server_var(_playergetset_p1x) server_var(_playergetset_p1y) server_var(_playergetset_p1z)
    es es_xcreatevectorstring _playergetset_p2vec server_var(_playergetset_p2x) server_var(_playergetset_p2y) server_var(_playergetset_p2z)
    es es_xcreatevectorfrompoints _playergetset_p12vec server_var(_playergetset_p1vec) server_var(_playergetset_p2vec)
    es es_xsplitvectorstring _playergetset_p1x _playergetset_p1y _playergetset_p1z server_var(_playergetset_p12vec)
    es playerget viewangle server_var(_playergetset_temparg1) _playergetset_p2x _playergetset_p2y _playergetset_p2z 
    es es_xsetinfo _playergetset_tempy server_var(_playergetset_p1y)
    es es_xsetinfo _playergetset_tempx server_var(_playergetset_p1x)
    es es_xsetinfo _playergetset_atan server_var(_playergetset_tempy)
    es es_xmath _playergetset_atan / server_var(_playergetset_tempx)
    es es_xmath _playergetset_atan atan
    es es_xmath _playergetset_atan * server_var(_playergetset_divpi)
    es_xsetinfo _playergetset_realangle 180
    if (server_var(_playergetset_tempx) < 0) do
    {
      es es_xmath _playergetset_realangle + server_var(_playergetset_atan)
    }
    else do
    {
      if (server_var(_playergetset_tempy) < 0) do
      {
        es_xsetinfo _playergetset_realangle 360
        es es_xmath _playergetset_realangle + server_var(_playergetset_atan)
      }
      else do
      {
        es es_xsetinfo _playergetset_realangle server_var(_playergetset_atan)
      }
    }
    es es_xsetinfo _playergetset_yangle server_var(_playergetset_realangle)
    es es_xsetinfo _playergetset_tempy server_var(_playergetset_p1y)
    es es_xsetinfo _playergetset_tempx server_var(_playergetset_p1x)
    es_xmath _playergetset_p1x power 2
    es_xmath _playergetset_p1y power 2
    es es_xmath _playergetset_p1x + server_var(_playergetset_p1y)
    es_xmath _playergetset_p1x root 2
    es es_xmath _playergetset_p1z / server_var(_playergetset_p1x)
    es_xmath _playergetset_p1z atan
    es es_xmath _playergetset_p1z * server_var(_playergetset_divpi)
    es_xsetinfo _playergetset_xangle 0
    es es_xmath _playergetset_xangle - server_var(_playergetset_p1z)
    es es_xsetang server_var(_playergetset_temparg1) server_var(_playergetset_xangle) server_var(_playergetset_yangle) server_var(_playergetset_p2z)
  }
  else do
  {
    es_dbgmsg 0 Syntax : playerset viewplayer <userid1> <userid2>
  }
}

block getweaponindex
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 3) do
  {
    es_xgetargv _playergetset_arg2 2
    es_xgetargv _playergetset_arg3 4
    es es_xif (weapon_ notin server_var(_playergetset_arg3)) do
    {
      es_format _playergetset_arg3 "weapon_%1" server_var(_playergetset_arg3)
    }
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es_xsetinfo _playergetset_find 0
    es es_xgetplayerhandle _playergetset_owner server_var(_playergetset_userid)
    es es_xcreateentitylist _playergetset_weapons server_var(_playergetset_arg3)
    es es_xkeygroupfilter _playergetset_weapons only m_Howner server_var(_playergetset_owner)
    es_xforeachkey _playergetset_tempid in _playergetset_weapons "es_xdoblock corelib/playergetset/getindex"
    es_xkeygroupdelete _playergetset_weapons
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget weaponindex <var> <userid> <weapon_name>
  }
}

block getprimary
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 3) do
  {
    es_xgetargv _playergetset_arg2 2
    es_xgetargv _playergetset_arg3 4
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es es_xsetinfo server_var(_playergetset_arg3) 0
    es_xsetinfo _playergetset_find 0
    es es_xgetplayerhandle _playergetset_owner server_var(_playergetset_userid)
    es_xforeachkey wep in _primaryweapons "es_xdoblock corelib/playergetset/checkall"
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget primary <var> <userid> [var_index]
  }
}

block getsecondary
{
  es_getargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 3) do
  {
    es_xgetargv _playergetset_arg2 2
    es_xgetargv _playergetset_arg3 4
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es es_xsetinfo server_var(_playergetset_arg3) 0
    es_xsetinfo _playergetset_find 0
    es es_xgetplayerhandle _playergetset_owner server_var(_playergetset_userid)
    es_xforeachkey wep in _secondaryweapons "es_xdoblock corelib/playergetset/checkall"
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget secondary <var> <userid> [var_index]
  }
}

block gethe
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 3) do
  {
    es_xgetargv _playergetset_arg2 2
    es_xgetargv _playergetset_arg3 4
    es_setinfo server_var(_playergetset_arg2) 0
    es_setinfo server_var(_playergetset_arg3) 0
    es_xsetinfo _playergetset_find 0
    es es_xgetplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) "CBasePlayer.localdata.m_iAmmo.011"
    es es_xgetplayerhandle _playergetset_owner server_var(_playergetset_userid)
    es_xcreateentitylist _playergetset_weapons weapon_hegrenade
    es es_xkeygroupfilter _playergetset_weapons only m_Howner server_var(_playergetset_owner)
    es_xforeachkey _playergetset_tempid in _playergetset_weapons "es_xdoblock corelib/playergetset/weapon_list"
    es_xkeygroupdelete _playergetset_weapons
    es es_xif (server_var(_playergetset_find) == weapon_hegrenade) do
    {
      es es_xsetinfo server_var(_playergetset_arg2) 1
      es es_xsetinfo server_var(_playergetset_arg3) server_var(_playergetset_tempid)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget he <var> <userid> [var_index]
  }
}

block getfb
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 3) do
  {
    es_xgetargv _playergetset_arg2 2
    es_xgetargv _playergetset_arg3 4
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es es_xsetinfo server_var(_playergetset_arg3) 0
    es_xsetinfo _playergetset_find 0
    es es_xgetplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) "CBasePlayer.localdata.m_iAmmo.012"
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget fb <var> <userid>
  }
}

block getsg
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 3) do
  {
    es_xgetargv _playergetset_arg2 2
    es_xgetargv _playergetset_arg3 4
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es es_xsetinfo server_var(_playergetset_arg3) 0
    es_xsetinfo _playergetset_find 0
    es es_xgetplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) "CBasePlayer.localdata.m_iAmmo.013"
    es_xcreateentitylist _playergetset_weapons weapon_smokegrenade
    es es_xkeygroupfilter _playergetset_weapons only m_Howner server_var(_playergetset_owner)
    es_xforeachkey _playergetset_tempid in _playergetset_weapons "es_xdoblock corelib/playergetset/weapon_list"
    es_xkeygroupdelete _playergetset_weapons
    es es_xif (server_var(_playergetset_find) == weapon_smokegrenade) do
    {
      es es_xsetinfo server_var(_playergetset_arg2) 1
      es es_xsetinfo server_var(_playergetset_arg3) server_var(_playergetset_tempid)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget sg <var> <userid> [var_index]
  }
}

block getc4
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 3) do
  {
    es_xgetargv _playergetset_arg2 2
    es_xgetargv _playergetset_arg3 4
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es es_xsetinfo server_var(_playergetset_arg3) 0
    es_xsetinfo _playergetset_find 0
    es es_xgetplayerhandle _playergetset_owner server_var(_playergetset_userid)
    es_xcreateentitylist _playergetset_weapons weapon_c4
    es es_xkeygroupfilter _playergetset_weapons only m_Howner server_var(_playergetset_owner)
    es_xforeachkey _playergetset_tempid in _playergetset_weapons "es_xdoblock corelib/playergetset/weapon_list"
    es_xkeygroupdelete _playergetset_weapons
    es es_xif (server_var(_playergetset_find) == weapon_c4) do
    {
      es es_xsetinfo server_var(_playergetset_arg2) 1
      es es_xsetinfo server_var(_playergetset_arg3) server_var(_playergetset_tempid)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget c4 <var> <userid> [var_index]
  }
}

block getammo
{
  es_xgetargc _playergetset_temparg1
  es es_xif (server_var(_playergetset_temparg1) > 2) do
  {
    es_xgetargv _playergetset_temparg2 2
    es_xgetargv _playergetset_temparg3 4
    es es_xsetinfo server_var(_playergetset_temparg2) 0
    es es_xif (server_var(_playergetset_temparg3) != 1) do
    {
      es es_xif (server_var(_playergetset_temparg3) != 2) do
      {
        es es_xif (weapon_ notin server_var(_playergetset_temparg3)) do
        {
          es_format _playergetset_temparg3 "weapon_%1" server_var(_playergetset_temparg3)
        }
        es_xsetinfo _weapon_slot 1
        es es_xforeachkey _playergetset_tempid in _primaryweapons "es_xdoblock corelib/playergetset/findslot"
        es_xsetinfo _weapon_slot 2
        es es_xforeachkey _playergetset_tempid in _secondaryweapons "es_xdoblock corelib/playergetset/findslot"
      }
    }
    es es_xif (server_var(_playergetset_temparg3) == 1) do
    {
      es playerget primary _playergetset_temparg3 server_var(_playergetset_userid)
      es es_xif (server_var(_playergetset_temparg3) != 0) do
      {
        es es_xkeygetvalue _playergetset_tempvar _primaryweapons server_var(_playergetset_temparg3) ammo 
        es getplayerinfo _playergetset_tempid server_var(_playergetset_userid) index
        es es_xgetindexprop server_var(_playergetset_temparg2) server_var(_playergetset_tempid) server_var(_playergetset_tempvar)
      }
    }
    es es_xif (server_var(_playergetset_temparg3) == 2) do
    {
      es es_xif (server_var(_playergetset_temparg3) != 0) do
      {
        es playerget secondary _playergetset_temparg3 server_var(_playergetset_userid)
        es es_xkeygetvalue _playergetset_tempvar _secondaryweapons server_var(_playergetset_temparg3) ammo 
        es getplayerinfo _playergetset_tempid server_var(_playergetset_userid) index
        es es_xgetindexprop server_var(_playergetset_temparg2) server_var(_playergetset_tempid) server_var(_playergetset_tempvar)
      }
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget ammo <var> <userid> <weapon / slot>
  }
}

block getclip
{
  es_xgetargc _playergetset_temparg1
  es es_xif (server_var(_playergetset_temparg1) > 3) do
  {
    es_xsetinfo _playergetset_temparg3 0
    es_xgetargv _playergetset_temparg2 2
    es_xgetargv _playergetset_temparg3 4
    es es_xsetinfo server_var(_playergetset_temparg2) 0
    es es_xif (server_var(_playergetset_temparg3) != 1) do
    {
      es es_xif (server_var(_playergetset_temparg3) != 2) do
      {
        es es_xif (weapon_ notin server_var(_playergetset_temparg3)) do
        {
          es_format _playergetset_temparg3 "weapon_%1" server_var(_playergetset_temparg3)
        }
        es_xsetinfo _weapon_slot 1
        es es_xforeachkey _playergetset_tempid in _primaryweapons "es_xdoblock corelib/playergetset/findslot"
        es_xsetinfo _weapon_slot 2
        es es_xforeachkey _playergetset_tempid in _secondaryweapons "es_xdoblock corelib/playergetset/findslot"
      }
    }
    es es_xif (server_var(_playergetset_temparg3) == 1) do
    {
      es playerget primary _playergetset_temparg3 server_var(_playergetset_userid) server_var(_playergetset_tempid)
      es es_xif (server_var(_playergetset_temparg3) != 0) do
      {
        es es_xkeygetvalue _playergetset_tempvar _primaryweapons server_var(_playergetset_temparg3) clip
        es es_xgetindexprop server_var(_playergetset_temparg2) server_var(_playergetset_tempid) server_var(_playergetset_tempvar)
      }
    }
    es es_xif (server_var(_playergetset_temparg3) == 2) do
    {
      es playerget secondary _playergetset_temparg3 server_var(_playergetset_userid) server_var(_playergetset_tempid)
      es es_xif (server_var(_playergetset_temparg3) != 0) do
      {
        es es_xkeygetvalue _playergetset_tempvar _secondaryweapons server_var(_playergetset_temparg3) clip
        es es_xgetindexprop server_var(_playergetset_temparg2) server_var(_playergetset_tempid) server_var(_playergetset_tempvar)
      }
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget clip <var> <userid> <weapon / slot>
  }
}

block getcash
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 2
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es_getplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) CCSPlayer.m_iAccount
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget cash <var>  <userid>
  }
}

block getdefuser
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 2
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es_getplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) CCSPlayer.m_bHasDefuser
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget defuser <var>  <userid>
  }
}

block getspeed
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 2
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es_getplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) CCSPlayer.baseclass.localdata.m_flLaggedMovementValue
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget speed <var>  <userid>
  }
}

block getarmor
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 2
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es_getplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) CCSPlayer.m_ArmorValue
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget armor <var>  <userid>
  }
}

block gethealth
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 2
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es_getplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) CCSPlayer.baseclass.m_iHealth
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget health <var>  <userid>
  }
}

block getviewangle
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 4) do
  {
    es_xgetargv _playergetset_arg2 3
    es_xgetargv _playergetset_arg3 4
    es_xgetargv _playergetset_arg4 5
    es es_xsetinfo server_var(_playergetset_arg2) 0
    es es_xsetinfo server_var(_playergetset_arg3) 0
    es es_xsetinfo server_var(_playergetset_arg4) 0
    es_getplayerprop _playergetset_arg1 server_var(_playergetset_userid) CCSPlayer.baseclass.baseclass.baseclass.baseclass.baseclass.baseclass.m_angRotation
    es es_xsplitvectorstring server_var(_playergetset_arg2) server_var(_playergetset_arg3) server_var(_playergetset_arg4) server_var(_playergetset_arg1)
    es es_xgetplayerprop server_var(_playergetset_arg2) server_var(_playergetset_userid) CCSPlayer.m_angEyeAngles[0]
    es es_xgetplayerprop server_var(_playergetset_arg3) server_var(_playergetset_userid) CCSPlayer.m_angEyeAngles[1]
    es es_xif (server_var(server_var(_playergetset_arg3)) < 0) then es_xmath server_var(_playergetset_arg3) + 360
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerget viewangle  <userid> <return pitch> <return yaw> <return roll>
  }

}

block setnightvisionon
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 3
    es es_xif (server_var(_playergetset_arg2) >= 0) do
    {
      es es_xif (server_var(_playergetset_arg2) <= 1) do
      {
        es_setplayerprop server_var(_playergetset_userid) CCSPlayer.m_bNightVisionOn server_var(_playergetset_arg2)
      }
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset nightvisionon <userid> 1/0
  }
}

block setnightvision
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 3
    es es_xif (server_var(_playergetset_arg2) >= 0) do
    {
      es es_xif (server_var(_playergetset_arg2) <= 1) do
      {
        es_setplayerprop server_var(_playergetset_userid) CCSPlayer.m_bHasNightVision server_var(_playergetset_arg2)
      }
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset nightvision <userid> 1/0
  }
}

block setdefuser
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 3
    es es_xif (server_var(_playergetset_arg2) >= 0) do
    {
      es es_xif (server_var(_playergetset_arg2) <= 1) do
      {
        es_setplayerprop server_var(_playergetset_userid) CCSPlayer.m_bHasDefuser server_var(_playergetset_arg2)
      }
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset defuser <userid> 1/0
  }
}

block setcash
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 3
    es es_xif (server_var(_playergetset_arg2) >= 0) do
    {
      es es_xif (server_var(_playergetset_arg2) < 16001) do
      {
        es_setplayerprop server_var(_playergetset_userid) CCSPlayer.m_iAccount server_var(_playergetset_arg2)
      }
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset cash <userid> <var>
  }
}

block setspeed
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 3
    es es_xif (server_var(_playergetset_arg2) >= 0) do
    {
      es_setplayerprop server_var(_playergetset_userid) CCSPlayer.baseclass.localdata.m_flLaggedMovementValue server_var(_playergetset_arg2)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset speed <userid> <var>
  }
}

block setarmor
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 3
    es es_xif (server_var(_playergetset_arg2) >= 0) do
    {
      es_setplayerprop server_var(_playergetset_userid) CCSPlayer.m_ArmorValue server_var(_playergetset_arg2)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset armor <userid> <var>
  }
}

block sethealth
{
  es_xgetargc _playergetset_arg1
  es es_xif (server_var(_playergetset_arg1) > 2) do
  {
    es_xgetargv _playergetset_arg2 3
    es es_xif (server_var(_playergetset_arg2) >= 0) do
    {
      es_setplayerprop server_var(_playergetset_userid) CCSPlayer.baseclass.m_iHealth server_var(_playergetset_arg2)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset health <userid> <var>
  }
}

block setclip
{
  es_xgetargc _playergetset_temparg1
  es es_xif (server_var(_playergetset_temparg1) > 3) do
  {
    es_xgetargv _playergetset_temparg2 4
    es_xgetargv _playergetset_temparg3 3
    es es_xif (server_var(_playergetset_temparg3) != 1) do
    {
      es es_xif (server_var(_playergetset_temparg3) != 2) do
      {
        es es_xif (weapon_ notin server_var(_playergetset_temparg3)) do
        {
          es_format _playergetset_temparg3 "weapon_%1" server_var(_playergetset_temparg3)
        }
        es_xsetinfo _weapon_slot 1
        es es_xforeachkey _playergetset_tempid in _primaryweapons "es_xdoblock corelib/playergetset/findslot"
        es_xsetinfo _weapon_slot 2
        es es_xforeachkey _playergetset_tempid in _secondaryweapons "es_xdoblock corelib/playergetset/findslot"
      }
    }
    es es_xif (server_var(_playergetset_temparg3) == 1) do
    {
      es playerget primary _playergetset_temparg3 server_var(_playergetset_userid) server_var(_playergetset_tempid)
      es es_xkeygetvalue _playergetset_tempvar _primaryweapons server_var(_playergetset_temparg3) clip
      es es_xsetindexprop server_var(_playergetset_tempid) server_var(_playergetset_tempvar) server_var(_playergetset_temparg2)
    }
    es es_xif (server_var(_playergetset_temparg3) == 2) do
    {
      es playerget secondary _playergetset_temparg3 server_var(_playergetset_userid) server_var(_playergetset_tempid)
      es es_xkeygetvalue _playergetset_tempvar _secondaryweapons server_var(_playergetset_temparg3) clip
      es es_xsetindexprop server_var(_playergetset_tempid) server_var(_playergetset_tempvar) server_var(_playergetset_temparg2)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset clip <userid> <weapon / slot> <amount>
  }
}

block setammo
{
  es_xgetargc _playergetset_temparg1
  es es_xif (server_var(_playergetset_temparg1) > 3) do
  {
    es_xgetargv _playergetset_temparg2 4
    es_xgetargv _playergetset_temparg3 3
    es es_xif (server_var(_playergetset_temparg3) != 1) do
    {
      es es_xif (server_var(_playergetset_temparg3) != 2) do
      {
        es es_xif (weapon_ notin server_var(_playergetset_temparg3)) do
        {
          es_format _playergetset_temparg3 "weapon_%1" server_var(_playergetset_temparg3)
        }
        es_xsetinfo _weapon_slot 1
        es es_xforeachkey _playergetset_tempid in _primaryweapons "es_xdoblock corelib/playergetset/findslot"
        es_xsetinfo _weapon_slot 2
        es es_xforeachkey _playergetset_tempid in _secondaryweapons "es_xdoblock corelib/playergetset/findslot"
      }
    }
    es es_xif (server_var(_playergetset_temparg3) == 1) do
    {
      es playerget primary _playergetset_temparg3 server_var(_playergetset_userid)
      es es_xkeygetvalue _playergetset_tempvar _primaryweapons server_var(_playergetset_temparg3) ammo 
      es getplayerinfo _playergetset_tempid server_var(_playergetset_userid) index
      es es_xsetindexprop server_var(_playergetset_tempid) server_var(_playergetset_tempvar) server_var(_playergetset_temparg2)
    }
    es es_xif (server_var(_playergetset_temparg3) == 2) do
    {
      es playerget secondary _playergetset_temparg3 server_var(_playergetset_userid)
      es es_xkeygetvalue _playergetset_tempvar _secondaryweapons server_var(_playergetset_temparg3) ammo 
      es getplayerinfo _playergetset_tempid server_var(_playergetset_userid) index
      es es_xsetindexprop server_var(_playergetset_tempid) server_var(_playergetset_tempvar) server_var(_playergetset_temparg2)
    }
  }
  else do
  {
    es_xdbgmsg 0 Syntax : playerset ammo <userid> <weapon / slot> <amount>
  }
}

block findslot
{
  es es_xif (server_var(_playergetset_tempid) == server_var(_playergetset_temparg3)) do
  {
    es es_xsetinfo _playergetset_temparg3 server_var(_weapon_slot)
  }
}

block checkall
{
  es es_xcreateentitylist _playergetset_weapons server_var(wep)
  es es_xkeygroupfilter _playergetset_weapons only m_Howner server_var(_playergetset_owner)
  es_xsetinfo _playergetset_find 0
  es_xforeachkey _playergetset_tempid in _playergetset_weapons "es_xdoblock corelib/playergetset/weapon_list"
  es_xkeygroupdelete _playergetset_weapons
}

block weapon_list
{
  es es_xkeygetvalue _playergetset_find _playergetset_weapons server_var(_playergetset_tempid) Classname
  es es_xif (weapon_ in server_var(_playergetset_find)) do
  {
    es es_xsetinfo server_var(_playergetset_arg2) server_var(_playergetset_find)
    es es_xsetinfo server_var(_playergetset_arg3) server_var(_playergetset_tempid)
  }
}

block getindex
{
  es es_xkeygetvalue _playergetset_find _playergetset_weapons server_var(_playergetset_tempid) Classname
  es es_xif (weapon_ in server_var(_playergetset_find)) do
  {
    es es_xsetinfo server_var(_playergetset_arg2) server_var(_playergetset_tempid)
  }
}

block createprimary
{
  es_xkeygroupcreate _primaryweapons
  es_xkeycreate _primaryweapons weapon_awp
  es_xkeysetvalue _primaryweapons weapon_awp ammo "CCSPlayer.baseclass.localdata.m_iAmmo.005"
  es_xkeysetvalue _primaryweapons weapon_awp clip "CWeaponAWP.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_scout
  es_xkeysetvalue _primaryweapons weapon_scout ammo "CCSPlayer.baseclass.localdata.m_iAmmo.002"
  es_xkeysetvalue _primaryweapons weapon_scout clip "CWeaponScout.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_aug
  es_xkeysetvalue _primaryweapons weapon_aug ammo "CCSPlayer.baseclass.localdata.m_iAmmo.002"
  es_xkeysetvalue _primaryweapons weapon_aug clip "CWeaponAug.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_mac10
  es_xkeysetvalue _primaryweapons weapon_mac10 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.008"
  es_xkeysetvalue _primaryweapons weapon_mac10 clip "CWeaponMAC10.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_tmp
  es_xkeysetvalue _primaryweapons weapon_tmp ammo "CCSPlayer.baseclass.localdata.m_iAmmo.006"
  es_xkeysetvalue _primaryweapons weapon_tmp clip "CWeaponTMP.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_mp5navy
  es_xkeysetvalue _primaryweapons weapon_mp5navy ammo "CCSPlayer.baseclass.localdata.m_iAmmo.006"
  es_xkeysetvalue _primaryweapons weapon_mp5navy clip "CWeaponMP5Navy.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_ump45
  es_xkeysetvalue _primaryweapons weapon_ump45 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.008"
  es_xkeysetvalue _primaryweapons weapon_ump45 clip "CWeaponUMP45.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_p90
  es_xkeysetvalue _primaryweapons weapon_p90 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.010"
  es_xkeysetvalue _primaryweapons weapon_p90 clip "CWeaponP90.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_galil
  es_xkeysetvalue _primaryweapons weapon_galil ammo "CCSPlayer.baseclass.localdata.m_iAmmo.003"
  es_xkeysetvalue _primaryweapons weapon_galil clip "CWeaponGalil.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_famas
  es_xkeysetvalue _primaryweapons weapon_famas ammo "CCSPlayer.baseclass.localdata.m_iAmmo.003"
  es_xkeysetvalue _primaryweapons weapon_famas clip "CWeaponFamas.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_ak47
  es_xkeysetvalue _primaryweapons weapon_ak47 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.002"
  es_xkeysetvalue _primaryweapons weapon_ak47 clip "CAK47.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_sg552
  es_xkeysetvalue _primaryweapons weapon_sg552 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.003"
  es_xkeysetvalue _primaryweapons weapon_sg552 clip "CWeaponSG552.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_sg550
  es_xkeysetvalue _primaryweapons weapon_sg550 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.003"
  es_xkeysetvalue _primaryweapons weapon_sg550 clip "CWeaponSG550.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_g3sg1
  es_xkeysetvalue _primaryweapons weapon_g3sg1 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.002"
  es_xkeysetvalue _primaryweapons weapon_g3sg1 clip "CWeaponG3SG1.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_m249
  es_xkeysetvalue _primaryweapons weapon_m249 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.004"
  es_xkeysetvalue _primaryweapons weapon_m249 clip "CWeaponM249.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_m4a1
  es_xkeysetvalue _primaryweapons weapon_m4a1 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.003"
  es_xkeysetvalue _primaryweapons weapon_m4a1 clip "CWeaponM4A1.baseclass.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_m3
  es_xkeysetvalue _primaryweapons weapon_m3 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.007"
  es_xkeysetvalue _primaryweapons weapon_m3 clip "CWeaponM3.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _primaryweapons weapon_xm1014
  es_xkeysetvalue _primaryweapons weapon_xm1014 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.007"
  es_xkeysetvalue _primaryweapons weapon_xm1014 clip "CWeaponXM1014.baseclass.baseclass.LocalWeaponData.m_iClip1"
}

block createsecondary
{
  es_xkeygroupcreate _secondaryweapons
  es_xkeycreate _secondaryweapons weapon_glock
  es_xkeysetvalue _secondaryweapons weapon_glock ammo "CCSPlayer.baseclass.localdata.m_iAmmo.006"
  es_xkeysetvalue _secondaryweapons weapon_glock clip "CWeaponGlock.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _secondaryweapons weapon_usp
  es_xkeysetvalue _secondaryweapons weapon_usp ammo "CCSPlayer.baseclass.localdata.m_iAmmo.008"
  es_xkeysetvalue _secondaryweapons weapon_usp clip "CWeaponUSP.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _secondaryweapons weapon_p228
  es_xkeysetvalue _secondaryweapons weapon_p228 ammo "CCSPlayer.baseclass.localdata.m_iAmmo.009"
  es_xkeysetvalue _secondaryweapons weapon_p228 clip "CWeaponP228.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _secondaryweapons weapon_deagle
  es_xkeysetvalue _secondaryweapons weapon_deagle ammo "CCSPlayer.baseclass.localdata.m_iAmmo.001"
  es_xkeysetvalue _secondaryweapons weapon_deagle clip "CDEagle.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _secondaryweapons weapon_elite
  es_xkeysetvalue _secondaryweapons weapon_elite ammo "CCSPlayer.baseclass.localdata.m_iAmmo.006"
  es_xkeysetvalue _secondaryweapons weapon_elite clip "CWeaponElite.baseclass.baseclass.LocalWeaponData.m_iClip1"
  es_xkeycreate _secondaryweapons weapon_fiveseven
  es_xkeysetvalue _secondaryweapons weapon_fiveseven ammo "CCSPlayer.baseclass.localdata.m_iAmmo.010"
  es_xkeysetvalue _secondaryweapons weapon_fiveseven clip "CWeaponFiveSeven.baseclass.baseclass.LocalWeaponData.m_iClip1"
}
