block load
{
	es_xregcmd wcs_setfx wcs/WCSfunctions/wcs_setfx "wcs_setfx <userid> <type> [<time>]- Gives an effect for a player (type: freeze, speed, god)"
}
block wcs_setfx
{
  // types: freeze speed god invis(0-255) invisp(in %) health armor gravity disguiser 1stclip 2ndclip longjump
  es_xgetargv wcs_fxtype 1
  es_xgetargv wcs_uid 2
  es_xgetargv wcs_op 3
  if (server_var(wcs_op) notin "=-+") then es_xset wcs_op "="
  es_xgetargv wcs_params 4
  es_xgetargv wcs_time 5
  es_exists ex key WCSuserdata server_var(wcs_uid)
  es_xset wcs_dead 1
  if (server_var(ex) = 1) then es_xgetplayerprop wcs_dead server_var(wcs_uid) "CCSPlayer.baseclass.pl.deadflag"
  if (server_var(wcs_dead) = 1) then es_xset ex 0
  if (server_var(wcs_fxtype) notin "freeze|speed|god|invis|invisp|health|armor|gravity|disguiser|1stclip|2ndclip|longjump") then es_xset ex 0
  ifx true(ex) do
  {
    if (server_var(wcs_fxtype) = "freeze") do
    {
      ifx true(wcs_params) do
      {
        es est_freeze server_var(wcs_uid) 1
        if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = 0 0
      }
      else do
      {
        es est_freeze server_var(wcs_uid) 0
        es_setplayerprop server_var(wcs_uid) CBasePlayer.m_fFlags 1
        if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = 1 0
      }
    }
    if (server_var(wcs_fxtype) = "speed") do
    {
      // get saved value, watch out for FLOAT and es_math!!
      es_xset wcs_effectdata 1.0
      es wcs returndict wcs_effectdata server_var(wcs_uid) speed
      es_xmath wcs_effectdata float
      if (server_var(wcs_effectdata) = 0) then es_xset wcs_effectdata 1.0
      // reset to old value if timed effect
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_effectdata) 0
      // check the operators
      if (server_var(wcs_op) = "=") do
      {
        es est_speed server_var(wcs_uid) server_var(wcs_params)
        es wcs updatedict server_var(wcs_uid) speed server_var(wcs_params)
      }
      if (server_var(wcs_op) = "-") do
      {
        es_math wcs_effectdata - server_var(wcs_params)
        if (server_var(wcs_effectdata) <= 0) then es_xset wcs_effectdata 0
        es est_speed server_var(wcs_uid) server_var(wcs_effectdata)
        es wcs updatedict server_var(wcs_uid) speed server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "+") do
      {
        es_math wcs_effectdata + server_var(wcs_params)
        es est_speed server_var(wcs_uid) server_var(wcs_effectdata)
        es wcs updatedict server_var(wcs_uid) speed server_var(wcs_effectdata)
      }
    }
    if (server_var(wcs_fxtype) = "god") do
    {
      ifx true(wcs_params) do
      {
        es est_god server_var(wcs_uid) 1
        if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = 0 0
      }
      else do
      {
        es est_god server_var(wcs_uid) 0
        if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = 1 0
      }
    }
    if (server_var(wcs_fxtype) = "invis") do
    {
      alias wcs_invischeck "if (server_var(wcs_effectdata) > 100) then es_xset wcs_effectdata 100.0;if (server_var(wcs_effectdata) <= 0) then es_xset wcs_effectdata 0.0;if (server_var(wcs_invis) > 255) then es_xset wcs_invis 255;if (server_var(wcs_invis) <= 0) then es_xset wcs_invis 0;es_xmath wcs_effectdata float;es_xmath wcs_invis float"
      // get saved value, watch out for FLOAT and es_math!! EFFECTDATA = PERCENT, INVIS = ABSOLUTE
      es_xset wcs_effectdata 0.0
      es wcs returndict wcs_effectdata server_var(wcs_uid) invisp
      if (server_var(wcs_effectdata) = 0) then es_xset wcs_effectdata 0
      // calculate percentage and absolute value
      es_xmathparse wcs_invis "(wcs_effectdata - 100.0) * -2.55"
      wcs_invischeck
      // reset to old value if timed effect
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_invis) 0
      // check the operators
      if (server_var(wcs_op) = "=") do
      {
        es_xmathparse wcs_effectdata "(wcs_params / -2.55) + 100"
        wcs_invischeck
        es est_setplayercolor server_var(wcs_uid) 255 255 255 server_var(wcs_params) 1
        es wcs updatedict server_var(wcs_uid) invisp server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "-") do
      {
        es_math wcs_invis - server_var(wcs_params)
        es_xmathparse wcs_effectdata "(wcs_invis / -2.55) + 100"
        wcs_invischeck
        es est_setplayercolor server_var(wcs_uid) 255 255 255 server_var(wcs_invis) 1
        es wcs updatedict server_var(wcs_uid) invisp server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "+") do
      {
        es_math wcs_invis + server_var(wcs_params)
        es_xmathparse wcs_effectdata "(wcs_invis / -2.55) + 100"
        wcs_invischeck
        es est_setplayercolor server_var(wcs_uid) 255 255 255 server_var(wcs_invis) 1
        es wcs updatedict server_var(wcs_uid) invisp server_var(wcs_effectdata)
      }
    }
    if (server_var(wcs_fxtype) = "invisp") do
    {
      alias wcs_invischeck "if (server_var(wcs_effectdata) > 100) then es_xset wcs_effectdata 100.0;if (server_var(wcs_effectdata) <= 0) then es_xset wcs_effectdata 0.0;if (server_var(wcs_invis) > 255) then es_xset wcs_invis 255;if (server_var(wcs_invis) <= 0) then es_xset wcs_invis 0;es_xmath wcs_effectdata float;es_xmath wcs_invis float"
      // get saved value, watch out for FLOAT and es_math!! EFFECTDATA = PERCENT, INVIS = ABSOLUTE
      es_xset wcs_effectdata 0.0
      es wcs returndict wcs_effectdata server_var(wcs_uid) invisp
      if (server_var(wcs_effectdata) = 0) then es_xset wcs_effectdata 0
      // calculate percentage and absolute value
      es_xmathparse wcs_invis "(wcs_effectdata - 100.0) * -2.55"
      wcs_invischeck
      // reset to old value if timed effect
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_effectdata) 0
      // check the operators
      if (server_var(wcs_op) = "=") do
      {
        es_xmathparse wcs_invis "(wcs_params - 100.0) * -2.55"
        wcs_invischeck
        es est_setplayercolor server_var(wcs_uid) 255 255 255 server_var(wcs_invis) 1
        es wcs updatedict server_var(wcs_uid) invisp server_var(wcs_params)
      }
      if (server_var(wcs_op) = "-") do
      {
        es_math wcs_effectdata - server_var(wcs_params)
        es_xmathparse wcs_invis "(wcs_effectdata - 100.0) * -2.55"
        wcs_invischeck
        es est_setplayercolor server_var(wcs_uid) 255 255 255 server_var(wcs_invis) 1
        es wcs updatedict server_var(wcs_uid) invisp server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "+") do
      {
        es_math wcs_effectdata + server_var(wcs_params)
        es_xmathparse wcs_invis "(wcs_effectdata - 100.0) * -2.55"
        wcs_invischeck
        es est_setplayercolor server_var(wcs_uid) 255 255 255 server_var(wcs_invis) 1
        es wcs updatedict server_var(wcs_uid) invisp server_var(wcs_effectdata)
      }
    }
    if (server_var(wcs_fxtype) = "health") do
    {
      es est_gethealth wcs_health server_var(wcs_uid)
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_health) 0
      es_math wcs_health server_var(wcs_op) server_var(wcs_params)
      if (server_var(wcs_health) > 0) then est_health server_var(wcs_uid) = server_var(wcs_health)
      if (server_var(wcs_health) <= 0) then est_slay server_var(wcs_uid)
    }
    if (server_var(wcs_fxtype) = "armor") do
    {
      es est_getarmor wcs_armor server_var(wcs_uid)
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_armor) 0
      es_math wcs_armor server_var(wcs_op) server_var(wcs_params)
      if (server_var(wcs_armor) > 0) then est_armor server_var(wcs_uid) server_var(wcs_op) server_var(wcs_armor)
      if (server_var(wcs_armor) <= 0) then est_armor server_var(wcs_uid) = 0
    }
    if (server_var(wcs_fxtype) = "gravity") do
    {
      // get saved value, watch out for FLOAT and es_math!!
      es_xset wcs_effectdata 1.0
      es wcs returndict wcs_effectdata server_var(wcs_uid) gravity
      es_xmath wcs_effectdata float
      if (server_var(wcs_effectdata) = 0) then es_xset wcs_effectdata 1.0
      // reset to old value if timed effect
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_effectdata) 0
      // check the operators
      if (server_var(wcs_op) = "=") do
      {
        es est_setgravity server_var(wcs_uid) server_var(wcs_params)
        es wcs updatedict server_var(wcs_uid) gravity server_var(wcs_params)
      }
      if (server_var(wcs_op) = "-") do
      {
        es_math wcs_effectdata - server_var(wcs_params)
        if (server_var(wcs_effectdata) <= 0) then es_xset wcs_effectdata 0
        es est_setgravity server_var(wcs_uid) server_var(wcs_effectdata)
        es wcs updatedict server_var(wcs_uid) gravity server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "+") do
      {
        es_math wcs_effectdata + server_var(wcs_params)
        es est_setgravity server_var(wcs_uid) server_var(wcs_effectdata)
        es wcs updatedict server_var(wcs_uid) gravity server_var(wcs_effectdata)
      }
    }
    if (server_var(wcs_fxtype) = "disguiser") do
    {
      es_xset wcs_model_a 0 "Foreign model"
      es_xset wcs_model_b 0 "Team model"
      es_getplayerteam wcs_team server_var(wcs_uid)
      if (server_var(wcs_team) = 3) then es_xset wcs_model_a player/t_phoenix
      if (server_var(wcs_team) = 2) then es_xset wcs_model_a player/ct_urban
      if (server_var(wcs_team) = 3) then es_xset wcs_model_b player/ct_urban
      if (server_var(wcs_team) = 2) then es_xset wcs_model_b player/t_phoenix
      ifx true(wcs_params) do
      {
        es est_setmodel server_var(wcs_uid) server_var(wcs_model_a)
        if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = 0 0
      }
      else do
      {
        es est_setmodel server_var(wcs_uid) server_var(wcs_model_b)
        if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = 1 0
      }
    }
    if (server_var(wcs_fxtype) = "longjump") do
    {
      es_xset wcs_effectdata 0
      es wcs returndict wcs_effectdata server_var(wcs_uid) longjump
      es_xmath wcs_effectdata float
      if (server_var(wcs_effectdata) = 0) then es_xset wcs_effectdata 0
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_effectdata) 0
      if (server_var(wcs_op) = "=") do
      {
        es wcs updatedict server_var(wcs_uid) longjump server_var(wcs_params)
      }
      if (server_var(wcs_op) = "-") do
      {
        es_math wcs_effectdata - server_var(wcs_params)
        if (server_var(wcs_effectdata) <= 0) then es_xset wcs_effectdata 0
        es wcs updatedict server_var(wcs_uid) longjump server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "+") do
      {
        es_math wcs_effectdata + server_var(wcs_params)
        es wcs updatedict server_var(wcs_uid) longjump server_var(wcs_effectdata)
      }
    }
    if (server_var(wcs_fxtype) = "1stclip") do
    {
      es_xset wcs_effectdata 0
      es wcs returndict wcs_effectdata server_var(wcs_uid) 1stclip
      es_xmath wcs_effectdata float
      if (server_var(wcs_effectdata) = 0) then est_getclipammo wcs_effectdata server_var(wcs_uid) 1
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_effectdata) 0
      if (server_var(wcs_op) = "=") do
      {
        es wcs updatedict server_var(wcs_uid) 1stclip server_var(wcs_params)
        es est_setclipammo server_var(wcs_uid) 1 server_var(wcs_params)
      }
      if (server_var(wcs_op) = "-") do
      {
        es_math wcs_effectdata - server_var(wcs_params)
        if (server_var(wcs_effectdata) <= 0) then es_xset wcs_effectdata 0
        es wcs updatedict server_var(wcs_uid) 1stclip server_var(wcs_effectdata)
        es est_setclipammo server_var(wcs_uid) 1 server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "+") do
      {
        es_math wcs_effectdata + server_var(wcs_params)
        es wcs updatedict server_var(wcs_uid) 1stclip server_var(wcs_effectdata)
        es est_setclipammo server_var(wcs_uid) 1 server_var(wcs_effectdata)
      }
    }
    if (server_var(wcs_fxtype) = "2ndclip") do
    {
      es_xset wcs_effectdata 0
      es wcs returndict wcs_effectdata server_var(wcs_uid) 2ndclip
      es_xmath wcs_effectdata float
      if (server_var(wcs_effectdata) = 0) then est_getclipammo wcs_effectdata server_var(wcs_uid) 2
      if (server_var(wcs_time) > 0) then es_xdelayed server_var(wcs_time) wcs_setfx server_var(wcs_fxtype) server_var(wcs_uid) = server_var(wcs_effectdata) 0
      if (server_var(wcs_op) = "=") do
      {
        es wcs updatedict server_var(wcs_uid) 2ndclip server_var(wcs_params)
        es est_setclipammo server_var(wcs_uid) 2 server_var(wcs_params)
      }
      if (server_var(wcs_op) = "-") do
      {
        es_math wcs_effectdata - server_var(wcs_params)
        if (server_var(wcs_effectdata) <= 0) then es_xset wcs_effectdata 0
        es wcs updatedict server_var(wcs_uid) 2ndclip server_var(wcs_effectdata)
        es est_setclipammo server_var(wcs_uid) 2 server_var(wcs_effectdata)
      }
      if (server_var(wcs_op) = "+") do
      {
        es_math wcs_effectdata + server_var(wcs_params)
        es wcs updatedict server_var(wcs_uid) 2ndclip server_var(wcs_effectdata)
        es est_setclipammo server_var(wcs_uid) 2 server_var(wcs_effectdata)
      }
    }
  }
}