What's new

-Tibia 7.60 !buyhouse

Status
Not open for further replies.

Pastel

User
Joined
Feb 5, 2014
Messages
33
Reaction score
0
w game cpp pod
Code:
#ifdef TLM_HOUSE_SYSTEM
dodaj;

Code:
else if (text == "!buyhouse" || text == "!buyhome")
 {
  unsigned long money = player->getMoney(); 
  bool last = false;
  for (int x = player->pos.x-1; x <= player->pos.x+1 && !last; x++)
  {
   for(int y = player->pos.y-1; y <= player->pos.y+1 && !last; y++)
   {
    Position doorPos(x, y, player->pos.z);
    Tile* tile = getTile(doorPos);
    House* house = tile? tile->getHouse() : NULL;
    
    if (house && house->getPlayerRights(player->getName()) == HOUSE_OWNER){
              player->sendTextMessage(MSG_ADVANCE, "To twoj dom.");
              return;
    }

    if (house && house->isBought()){
              player->sendTextMessage(MSG_ADVANCE, "Ten dom ma juz wlasciciela.");
              return;
    }
    if(house && house->checkHouseCount(player) >= g_config.getGlobalNumber("maxhouses", 0)){
              std::stringstream textmsg;
              textmsg << " Nie mozesz posiadac wiecej niz " << g_config.getGlobalNumber("maxhouses", 1) << " domkow ";
              player->sendTextMessage(MSG_ADVANCE, textmsg.str().c_str());
              return;
    }
    if (house && house->getPlayerRights(doorPos, player->getName()) == HOUSE_NONE && !house->isBought() && house->checkHouseCount(player) < g_config.getGlobalNumber("maxhouses", 1))
    {
     Item *item = dynamic_cast<Item*>(tile->getThingByStackPos(tile->getThingCount()-1));
     long price = g_config.getGlobalNumber("priceforsqm", 0) * house->getHouseSQM(house->getName());
     if (item && Item::items[item->getID()].isDoor && price <= money)
     {
      player->substractMoney(price);
      house->setOwner(player->getName());
      house->save();
      player->sendTextMessage(MSG_ADVANCE, "Wlasnie kupiles ten domek.");
      last = true;
     }
     else
     {
     player->sendMagicEffect(player->pos, NM_ME_PUFF);
     player->sendTextMessage(MSG_SMALLINFO, "Masz za malo pieniedzy , aby kupic ten dom.");
   }
        }
  }
 }
}
w confing lua dodaj
-- house price for 1 sqm
priceforsqm = 500000
testowane na yurku :)
 

Zielony Pixel

Senior User
Joined
Feb 8, 2010
Messages
544
Reaction score
39
Odp: !buyhouse

po co robi? otsy dla cebulii jak wszyscy poszli na Lola? tutaj po angielsku, ?eby ka?dy gracz rozumia?:
Code:
else if (text == "!buyhouse" || text == "!buyhome")
 {
  unsigned long money = player->getMoney(); 
  bool last = false;
  for (int x = player->pos.x-1; x <= player->pos.x+1 && !last; x++)
  {
   for(int y = player->pos.y-1; y <= player->pos.y+1 && !last; y++)
   {
    Position doorPos(x, y, player->pos.z);
    Tile* tile = getTile(doorPos);
    House* house = tile? tile->getHouse() : NULL;
    
    if (house && house->getPlayerRights(player->getName()) == HOUSE_OWNER){
              player->sendTextMessage(MSG_ADVANCE, "You own this house!");
              return;
    }

    if (house && house->isBought()){
              player->sendTextMessage(MSG_ADVANCE, "This house already has a owner!");
              return;
    }
    if(house && house->checkHouseCount(player) >= g_config.getGlobalNumber("maxhouses", 0)){
              std::stringstream textmsg;
              textmsg << " You cant have more than " << g_config.getGlobalNumber("maxhouses", 1) << " house!";
              player->sendTextMessage(MSG_ADVANCE, textmsg.str().c_str());
              return;
    }
    if (house && house->getPlayerRights(doorPos, player->getName()) == HOUSE_NONE && !house->isBought() && house->checkHouseCount(player) < g_config.getGlobalNumber("maxhouses", 1))
    {
     Item *item = dynamic_cast<Item*>(tile->getThingByStackPos(tile->getThingCount()-1));
     long price = g_config.getGlobalNumber("priceforsqm", 0) * house->getHouseSQM(house->getName());
     if (item && Item::items[item->getID()].isDoor && price <= money)
     {
      player->substractMoney(price);
      house->setOwner(player->getName());
      house->save();
      player->sendTextMessage(MSG_ADVANCE, "Congratulations! You bought a house!");
      last = true;
     }
     else
     {
     player->sendMagicEffect(player->pos, NM_ME_PUFF);
     player->sendTextMessage(MSG_SMALLINFO, "You dont have enough money to buy this house!");
   }
        }
  }
 }
}

++ reszta
house.cpp
Code:
int House::checkHouseCount(Player* player)
{
    std::string file = g_config.DATA_DIR + "houses.xml";
    xmlDocPtr doc;
    doc = xmlParseFile(file.c_str());
    int housecount = 0;   
    if (doc)
    {
        xmlNodePtr root, houseNode, tileNode;
        root = xmlDocGetRootElement(doc);
        if (xmlStrcmp(root->name, (const xmlChar*)"houses")) 
        {
            xmlFreeDoc(doc);
        }
 
        houseNode = root->children;
        while (houseNode)
        {
            if (strcmp((char*) houseNode->name, "house") == 0)
            {
                std::string name = (const char*)xmlGetProp(houseNode, (const xmlChar *) "name");
                House* house = new House(name);
                if (!house->load())
                {
                    xmlFreeDoc(doc);
                    return false;
                }
                if(player->getName() == house->getOwner()){
                       housecount++;
                }        
 
            }
            houseNode = houseNode->next;
        }
        xmlFreeDoc(doc);
 
    }
    return housecount;                     
}
 
std::string House::getName() const
{
 return name;
}
bool House::isBought()
{
 if(owner.empty())
    return false;
    else
    return true;
}
int House::getHouseSQM(std::string housename) 
{ 
  std::string file="data/houses.xml";
  xmlDocPtr doc;
  doc = xmlParseFile(file.c_str());
  int sqm = 0;
  if (doc){
   xmlNodePtr root, p, tile;
   root = xmlDocGetRootElement(doc);
   if (xmlStrcmp(root->name, (const xmlChar*)"houses")) {
     xmlFreeDoc(doc);
     return sqm;
   }
    p = root->children; 
    while(p){ 
      if (strcmp((char*) p->name, "house")==0){
       std::string foundname =(const char*)xmlGetProp(p, (const xmlChar *) "name");
        if (housename == foundname){
          tile = p->children;
          while(tile){      
            if (strcmp((const char*) tile->name, "tile")==0){
              sqm++;
            } else if (strcmp((const char*) tile->name, "tiles") == 0)
              {
  int fromx = atoi((const char*) xmlGetProp(tile, (const xmlChar*) "fromx"));
  int fromy = atoi((const char*) xmlGetProp(tile, (const xmlChar*) "fromy"));
  int fromz = atoi((const char*) xmlGetProp(tile, (const xmlChar*) "fromz"));
  int tox = atoi((const char*) xmlGetProp(tile, (const xmlChar*) "tox"));
  int toy = atoi((const char*) xmlGetProp(tile, (const xmlChar*) "toy"));
  int toz = atoi((const char*) xmlGetProp(tile, (const xmlChar*) "toz"));
  if (fromx > tox) std::swap(fromx, tox);
  if (fromy > toy) std::swap(fromy, toy);
  if (fromz > toz) std::swap(fromz, toz);
  for (int x = fromx; x <= tox; x++)
   for (int y = fromy; y <= toy; y++)
    for (int z = fromz; z <= toz; z++)
                   sqm++;
               }
              tile = tile->next;
          }
        }
      }
      p = p->next;
    }
  }
  return sqm;
}

house.h ( pod public)
Code:
std::string getName() const;
 bool isBought();
 static int getHouseSQM(std::string housename);
 int checkHouseCount(Player* player);
 
Last edited:
Status
Not open for further replies.
Top