// damage corelib command, v0.5
//  by GODJonez
// usage:
//   damage <target userid> <damage> <damage type> <damage radius> <source userid>
//     target userid = the player to be hurt
//     damage = the amount of damage to do to player
//     damage type = (OPTIONAL) the type of the damage (number or "explosion")
//     damage radius = (OPTIONAL) the radius around the target the damage applies to
//     source userid = (OPTIONAL) the player that causes the damage
//
// DAMAGE TYPES (if not "explosion")
// 0 		GENERIC 
// 1 		CRUSH 
// 2 		BULLET 
// 4 		SLASH 
// 8 		BURN 
// 16 		FREEZE 
// 32 		FALL 
// 64 		BLAST 
// 128 		CLUB 
// 256 		SHOCK 
// 512 		SONIC 
// 1024 	ENERGYBEAM 
// 16384 	DROWN 
// 32768 	PARALYSE 
// 65536 	NERVEGAS 
// 131072 	POISON 
// 262144 	RADIATION 
// 524288 	DROWNRECOVER 
// 1048576 	CHEMICAL 
// 2097152 	SLOWBURN 
// 4194304 	SLOWFREEZE
//
block load
{
  es_xdoblock corelib/damage/damage_register
}

block damage_register
{
  // damage variables
  es_xsetinfo _core_dmg_args 0
  es_xsetinfo _core_dmg_exists 0
  es_xsetinfo _core_dmg_output 0
  es_xexists _core_dmg_exists command damage
  if (server_var(_core_dmg_exists) == 0) do
  {
    es_xregcmd damage corelib/damage/command "Cause damage to a player."
  }
} 

block command
{
  es_xgetargc _core_dmg_args
  es es_xif (server_var(_core_dmg_args) < 3) do
  {
    es_xdbgmsg 0 "usage:"
    es_xdbgmsg 0 " damage <userid> <damage> [<type> [<radius> [<source>]]]"
  }
  else do
  {
    es_xsetinfo _core_dmg_target 0
    es_xsetinfo _core_dmg_damage 0
    es_xsetinfo _core_dmg_damagetype 1
    es_xsetinfo _core_dmg_damagedelay 0.1
    es_xsetinfo _core_dmg_damageradius 1
    es_xgetargv _core_dmg_damage 2
    es_xgetargv _core_dmg_target 1
    es_setinfo _core_dmg_source server_var(_core_dmg_target)
    es es_xif (server_var(_core_dmg_args) >= 6) do
    {
      es_xgetargv _core_dmg_source 5
    }
    es es_xif (server_var(_core_dmg_args) >= 5) do
    {
      es_xgetargv _core_dmg_damageradius 4
    }
    es es_xif (server_var(_core_dmg_args) >= 4) do
    {
      es_xgetargv _core_dmg_damagetype 3
    }
    es es_xisbot _core_dmg_exists server_var(_core_dmg_target)
    es es_xif (server_var(_core_dmg_exists) == 1) do
    {
      // bots take half damage by the game engine, so we will double the damage to compensate!
      es_xmath _core_dmg_damage * 2
    }
    es_xdoblock corelib/damage/dodamage
  }
}

block dodamage 
{ 
  es es_xgive server_var(_dmg_target) point_hurt 
  es es_xfire server_var(_dmg_target) !self addoutput "targetname mrdamage" 
  es es_xfire server_var(_dmg_target) point_hurt addoutput "targetname corelib_damage" 
  es es_xformat _dmg_output "Damage %1" server_var(_dmg_damage) 
  es es_xfire server_var(_dmg_target) corelib_damage addoutput server_var(_dmg_output) 
  es es_xformat _dmg_output "DamageType %1" server_var(_dmg_damagetype) 
  es es_xfire server_var(_dmg_target) corelib_damage addoutput server_var(_dmg_output) 
  es es_xformat _dmg_output "DamageRadius %1" server_var(_dmg_damageradius) 
  es es_xfire server_var(_dmg_target) corelib_damage addoutput server_var(_dmg_output) 
  es es_xfire server_var(_dmg_source) corelib_damage addoutput "DamageTarget mrdamage" 
  es es_xfire server_var(_dmg_target) corelib_damage TurnOn 
  es es_xfire server_var(_dmg_source) corelib_damage Hurt
  es es_xfire server_var(_dmg_target) corelib_damage kill 
  es es_xfire server_var(_dmg_target) !self addoutput "targetname mrhuman"
}
