What's new

-Tibia 7.60 Parcel System

Status
Not open for further replies.

Thorge D

Advanced User
Joined
Jul 24, 2014
Messages
300
Reaction score
29
1. Autor: SuperGillis
2. Opis: Kod na Parcel System dla silnik?w 7.60. Testowane na Yurots 0.9.4f przeze mnie.

3. Kod:

Na pocz?tek otwieramy plik player.h, to:
[CPP]time_t lastlogin;
time_t lastLoginSaved;[/CPP]
Przenosimy pod linijk? public.
Teraz w pliku protocol76.cpp szukamy:
[CPP]#include "game.h"[/CPP]
ni?ej dodajemy:
[CPP]#include ioplayer.h[/CPP]
Nast?pnie w tym samym pliku szukamy:
[CPP]void Protocol76::parseTextWindow(NetworkMessage &msg)[/CPP]
I zmieniamy na:
[CPP]void Protocol76::parseTextWindow(NetworkMessage &msg)
{
unsigned long id = msg.GetU32();
std::string new_text = msg.GetString();
if(readItem && windowTextID == id)
{
readItem->setText(new_text);
readItem->releaseThing();
readItem = NULL;
}
}[/CPP]
Teraz nadal w tym samym pliku szukamy:
[CPP]if(from_x == to_x && from_y == to_y && from_z == to_z)
return;[/CPP]
I pod tym wklejamy:
[CPP]if(to_x != 0xFFFF && (itemid == ITEM_PARCEL || itemid == ITEM_LETTER))
{
Tile* t = game->getTile(to_x, to_y, to_z);
if(t && t->hasItem(ITEM_MAILBOX))
{
Item* parcel = dynamic_cast<Item*>(game->getThing(Position(from_x, from_y, from_z), from_stack, player));
if(parcel)
{
bool canSend = true;
bool foundLabel = false;
std::string receiver;
unsigned int depotid;
Container* parcel2 = dynamic_cast<Container*>(parcel);
if(parcel2 && itemid == ITEM_PARCEL)
{
for(int x = 0; x < parcel2->size(); x++)
{
Item* label = dynamic_cast<Item*>(parcel2->getItem(x));
if(label && label->getID() == ITEM_LABEL)
{
foundLabel = true;
std::string text = label->getText();
std::istringstream iss(text, std::istringstream::in);
int i = 0;
std::string line[2];
while(std::getline(iss, text,'\n'))
{
line = text;
i++;
if(i == 2)
break;
}
receiver = line[0];
std::transform(line[1].begin(), line[1].end(), line[1].begin(), (int(*)(int))tolower);
if(line[1] == g_config.getGlobalString("city1","city"))
depotid = 1;
else if(line[1] == g_config.getGlobalString("city2","jungle")) // add as much as you want
depotid = 2;
else if(line[1] == g_config.getGlobalString("city3","desert")) // add as much as you want
depotid = 3;
else if(line[1] == g_config.getGlobalString("city4","paris")) // add as much as you want
depotid = 4;
else if(line[1] == g_config.getGlobalString("city5","nose")) // add as much as you want
depotid = 5;
else if(line[1] == g_config.getGlobalString("city6","nose")) // add as much as you want
depotid = 6;
else if(line[1] == g_config.getGlobalString("city7","nose")) // add as much as you want
depotid = 7;
else if(line[1] == g_config.getGlobalString("city8","nose")) // add as much as you want
depotid = 8;
else if(line[1] == g_config.getGlobalString("city9","nose")) // add as much as you want
depotid = 9;
else if(line[1] == g_config.getGlobalString("city10","nose")) // add as much as you want
depotid = 10;
else
canSend = false;
if(!game->isPlayer(receiver))
canSend = false;
if(canSend)
break;
}
}
}
else if(itemid == ITEM_LETTER)
{
foundLabel = true;
std::string text = parcel->getText();
std::istringstream iss(text, std::istringstream::in);
int i = 0;
std::string line[2];
while(std::getline(iss, text,'\n'))
{
line = text;
i++;
if(i == 2)
break;
}
receiver = line[0];
std::transform(line[1].begin(), line[1].end(), line[1].begin(), (int(*)(int))tolower);
if(line[1] == g_config.getGlobalString("city1","city"))
depotid = 1;
else if(line[1] == g_config.getGlobalString("city2","jungle")) // add as much as you want
depotid = 2;
else if(line[1] == g_config.getGlobalString("city3","desert")) // add as much as you want
depotid = 3;
else if(line[1] == g_config.getGlobalString("city4","paris")) // add as much as you want
depotid = 4;
else if(line[1] == g_config.getGlobalString("city5","nose")) // add as much as you want
depotid = 5;
else if(line[1] == g_config.getGlobalString("city6","nose")) // add as much as you want
depotid = 6;
else if(line[1] == g_config.getGlobalString("city7","nose")) // add as much as you want
depotid = 7;
else if(line[1] == g_config.getGlobalString("city8","nose")) // add as much as you want
depotid = 8;
else if(line[1] == g_config.getGlobalString("city9","nose")) // add as much as you want
depotid = 9;
else if(line[1] == g_config.getGlobalString("city10","nose")) // add as much as you want
depotid = 10;
else
canSend = false;
if(!game->isPlayer(receiver))
canSend = false;
}
if(canSend && foundLabel)
{
game->removeThing(player,Position(from_x, from_y, from_z), parcel, true);
Player* player = game->getPlayerByName(receiver);
if(player)
{
parcel->setID((itemid == ITEM_LETTER?ITEM_STLETTER:ITEM_STPARCEL));
Container* depot = player->getDepot(depotid);
if(depot)
depot->addItem(parcel);
std::vector<unsigned char> containerlist;
containerLayout::const_iterator cit;
for(cit = player->getContainers(); cit != player->getEndContainer(); ++cit)
{
Container* c = cit->second;
const char* msg = (itemid == ITEM_PARCEL?"You received a new parcel.":"You received a new letter.");
if(c == depot)
{
player->sendTextMessage(MSG_ADVANCE, msg);
player->onItemAddContainer(depot, parcel);
break;
}
if(c->getParent() == depot)
{
player->sendTextMessage(MSG_ADVANCE, msg);
break;
}
}
}
else
{
Protocol76* prot = new Protocol76(0);
player = new Player(receiver, prot);
parcel->setID((itemid == ITEM_LETTER?ITEM_STLETTER:ITEM_STPARCEL));
IOPlayer::instance()->loadPlayer(player, receiver);
Container* depot = player->getDepot(depotid);
if(depot)
depot->addItem(parcel);
player->lastlogin = player->lastLoginSaved;
IOPlayer::instance()->savePlayer(player);
delete player;
}
return;
}
}
}
}[/CPP]
game.cpp szukamy:
[CPP]#include <iostream>
#include <fstream>[/CPP]
pod dodajemy:
[CPP]#include <ctype.h>[/CPP]
Na ko?cu game.cpp dodaj:
[CPP]#ifdef PARCEL_STSTEM
bool Game::isPlayer(std::string name)
{
extern xmlMutexPtr xmlmutex;
std::string datadir = g_config.getGlobalString("datadir");
std::string filenamecheck = datadir + "players/" + name + ".xml";
std::transform(filenamecheck.begin(),filenamecheck.end(), filenamecheck.begin(), (int(*)(int))tolower);

xmlDocPtr doc;
xmlMutexLock(xmlmutex);
doc = xmlParseFile(filenamecheck.c_str());

if (doc)
{
xmlMutexUnlock(xmlmutex);
xmlFreeDoc(doc);
return true;
}
else
{
xmlMutexUnlock(xmlmutex);
xmlFreeDoc(doc);
return false;
#endif //PARCEL_SYSTEM[/CPP]
game.h pod:
[CPP]~Game();[/CPP]
dodaj:
[CPP]bool isPlayer(const std::string name);[/CPP]
Teraz w const76.h pod:
[CPP]enum item_t {[/CPP]
dodajemy:
[CPP]ITEM_PARCEL = 2595,
ITEM_STPARCEL = 2596,
ITEM_MAILBOX = 2593,
ITEM_MAILBOX2 = 2334,
ITEM_MAILBOX3 = 3981,
ITEM_LABEL = 2599,
ITEM_LETTER = 2597,
ITEM_STLETTER = 2598,[/CPP]
W tile.cpp na ko?cu dodajemy:
[CPP]bool Tile::hasItem(unsigned long id) const
{
ItemVector::const_iterator iit;
for(iit = topItems.begin(); iit != topItems.end(); ++iit)
{
if((*iit)->getID() == id)
return true;
}
for(iit = downItems.begin(); iit != downItems.end(); ++iit)
{
if((*iit)->getID() == id)
return true;
}
return false;
}[/CPP]
W tile.h pod:
[CPP]bool removeThing(Thing *thing);[/CPP]
wklej:
[CPP]bool hasItem(unsigned long id) const;[/CPP]

Kompilacja Ctrl+F11.

Do config.lua dodajemy:
Code:
-- Name city to send parcels & letters (DEPOT ID'S  > 1 to 10 < )
city1 = city1
city2 = city2
city3 = city3
city4 = city4
city5 = city5
city6 = city6
city7 = city7
city8 = city8
city9 = city9
city10 = city10
 
Status
Not open for further replies.
Top