Example #1
0
void giveItemsName(std::string userIn, int id, int count, int health)
{
  if (isValidItem(id))
  {
    int itemCount = 1, itemStacks = 1;

    if(count != 1)
    {
      itemCount = count;
      if(itemCount>1024) itemCount=1024;
      // If multiple stacks
      itemStacks = roundUpTo(itemCount, 64) / 64;
      itemCount  -= (itemStacks-1) * 64;
    }
    int amount = 64;
    for(int i = 0; i < itemStacks; i++)
    {
      // if last stack
      if(i == itemStacks - 1)
      {
        amount = itemCount;
      }
      mineserver->user.addItem(userIn.c_str(), id, amount, health);
    }
  }
  else
  {
    mineserver->chat.sendmsgTo(userIn.c_str(),  "Not a valid item");
  }
}
Example #2
0
void giveItems(User *user, std::string command, std::deque<std::string> args)
{
  User *tUser = NULL;
  int itemId = 0, itemCount = 1, itemStacks = 1;

  if(args.size() > 1)
  {
    tUser = getUserByNick(args[0]);

    //First check if item is a number
    itemId = atoi(args[1].c_str());

    //If item was not a number, search the name from config
    if(itemId == 0)
      itemId = Conf::get().iValue(args[1]);

    // Check item validity
    if(!isValidItem(itemId))
    {
      reportError(user, "Item " + args[1] + " not found.");
      return;
    }

    if(args.size() > 2)
    {
      itemCount = atoi(args[2].c_str());
      // If multiple stacks
      itemStacks = roundUpTo(itemCount, 64) / 64; 
      itemCount  -= (itemStacks-1) * 64; 
    }
  }
  else
  {
    reportError(user, "Too few parameters.");
	  return;
  }

  if(tUser)
  {
    int amount = 64;
    for(int i = 0; i < itemStacks; i++)
    {
      // if last stack
      if(i == itemStacks - 1)
        amount = itemCount;

      spawnedItem item;
      item.EID     = generateEID();
      item.item    = itemId;
      item.health  = 0;
      item.count   = amount;
      item.pos.x() = static_cast<int>(tUser->pos.x * 32);
      item.pos.y() = static_cast<int>(tUser->pos.y * 32);
      item.pos.z() = static_cast<int>(tUser->pos.z * 32);

      Map::get().sendPickupSpawn(item);
    }

    Chat::get().sendMsg(user, COLOR_RED + user->nick + " spawned " + args[1], Chat::ADMINS);
  }
  else
    reportError(user, "User " + args[0] + " not found (see /players)");
}
Example #3
0
bool PinMapDocument::isValidItem( Item * item )
{
	return isValidItem( item->type() );
}