/*******************************************************************************

  misc.inc v0.1

  Some misc stocks.

*******************************************************************************/

#if defined _misc_stocks_included
  #endinput
#endif
#define _misc_stocks_included

#include <amxmod>
#include <Vexd_Utilities>
#include <VexdUM_stock>

stock bool:check_player(id, const msg[])
{
  if((id < 1) || (id > get_maxplayers())) {
    report_error("%s: Player %d invalid", msg, id)
    return true
  }
  if(!is_user_connected(id)) {
    report_error("%s: Player %d not in-game", msg, id)
    return true
  }
  return false
}

stock bool:check_entity(ent, const msg[])
{
  if((ent < 1) || (ent > get_maxentities())) {
    report_error("%s: Entity %d out of range", msg, ent)
    return true
  }
  if(!is_entity(ent)) {
    report_error("%s: Entity %d invalid", msg, ent)
    return true
  }
  return false
}

/* Strips user's weapons. */
stock strip_user_weapons(id)
{
  if(check_player(id, "strip_user_weapons")) return 0

  new ent = create_entity("trigger_once")
  if(ent > 0)
  {
    DispatchKeyValue(ent, "classname", "trigger_once")
    DispatchKeyValue(ent, "target", "stripper")
    DispatchSpawn(ent)
    new ent2 = create_entity("player_weaponstrip")
    if(ent2 > 0)
    {
      DispatchKeyValue(ent2, "classname", "player_weaponstrip")
      DispatchKeyValue(ent2, "targetname", "stripper")
      DispatchSpawn(ent2)
      new Float:origin[3]
      entity_get_vector(id, EV_VEC_origin, origin)
      entity_set_vector(ent, EV_VEC_origin, origin)
      fake_touch(ent, id)
      remove_entity(ent)
      remove_entity(ent2)
      entity_set_int(id, EV_INT_weapons, 0)
      return 1
    }
    remove_entity(ent)
  }

  return 0
}
