What's new

Cena przedmiotu

Status
Not open for further replies.

Dantez

Moim sekretem jest ciasto
Joined
May 22, 2008
Messages
1,206
Reaction score
202
Witam! Przy porannej herbacie napisa?em kod, kt?ry jest od dawna na PokeXGames - ceny przedmiot?w w opisie. Na koniec podam ?atwe wykorzystanie tej ceny w NPC.

Author: Dantez
Tested on: TFS 0.3.6pl

PHP:
13:25 You see a club (Atk:7, Def:7).
Price: 50$
It weighs 25.00 oz.


Items.h
Szukamy:
PHP:
		int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
			runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;
I zamieniamy na:
PHP:
		int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
			runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder, price;

Items.cpp:
Pod:
PHP:
allowDistRead = false;
Dodajemy:
PHP:
price = 0;

Pod:
PHP:
			else if(tmpStrValue == "weight")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
					it.weight = intValue / 100.f;
			}
Dodajemy:
PHP:
			else if(tmpStrValue == "price")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
					it.price = intValue;
			}
Teraz item.h
Szukamy tego i KONIECZNIE DODAJEMY MU PRZECINEK NA KO?CU:
PHP:
ATTR_SCRIPTPROTECTED = 42,
I pod nim dodajemy:
PHP:
ATTR_PRICE = 43,

Szukamy:
PHP:
int32_t getAttack() const;
I dodajemy pod nim:
PHP:
int32_t getPrice() const;

Pod:
PHP:
inline int32_t Item::getAttack() const
{
	const int32_t* v = getIntegerAttribute("attack");
	if(v)
		return *v;

	return items[id].attack;
}
Dodajemy:
PHP:
inline int32_t Item::getPrice() const
{
	const int32_t* v = getIntegerAttribute("price");
	if(v)
		return *v;

	return items[id].price;
}

Item.cpp
Szukamy:
PHP:
		case ATTR_ATTACK:
		{
			int32_t attack;
			if(!propStream.GET_ULONG((uint32_t&)attack))
				return ATTR_READ_ERROR;

			setAttribute("attack", attack);
			break;
		}
Dodajemy:
PHP:
		case ATTR_PRICE:
		{
			int32_t price;
			if(!propStream.GET_ULONG((uint32_t&)price))
				return ATTR_READ_ERROR;

			setAttribute("price", price);
			break;
		}

Szukamy:
PHP:
	if(it.showCharges)
		s << " that has " << subType << " charge" << (subType != 1 ? "s" : "") << " left";
Dodajemy:
PHP:
	if(it.price)
		s << std::endl << "Price: " << (it.stackable ? it.price*subType : it.price) << "$";

Luascript.cpp:
Szukamy:
PHP:
setField(L, "attack", item->attack);
Dodajemy:
PHP:
setField(L, "price", item->price);

Jaka nada? cen? przedmiotowi?
Do przedmiotu w items.xml dopisujemy:
PHP:
<attribute key="price" value="20" />

Obiecane wykorzystanie w NPC: // Nie testowane
PHP:
local itemWindow = {
	{id=2160, subType=0, buy=10000, name="Test1"},
	{id=2152, subType=0, buy=100, name="Test2"},
	{id=2148, subType=0, buy=1, name="Test3"},
	{id=2173, subType=0, buy=10000, name="Test4"}
}

local items = {}
for _, item in ipairs(itemWindow) do
	items[item.id] = {buyPrice = item.buy, sellPrice = getItemInfo(item.id).price, subType = item.subType, realName = item.name}
end

By nie pcha? ca?ej tablicy z C++ mo?na wykorzysta? funkcj?: // Nie testowana
PHP:
int32_t LuaScriptInterface::luaGetItemPrice(lua_State* L)
{
	const ItemType* item;
	if(!(item = Item::items.getElement(popNumber(L))))
	{
		lua_pushboolean(L, false);
		return 1;
	}
	
	lua_pushnumber(L, item->price);
	return 1;
}

Wtedy:
PHP:
for _, item in ipairs(itemWindow) do
	items[item.id] = {buyPrice = item.buy, sellPrice = getItemPrice(item.itemid), subType = item.subType, realName = item.name}
end
 

Arkam

Forum friend
Joined
Dec 20, 2008
Messages
1,980
Reaction score
180
Odp: Cena przedmiotu

Jak sie czlowiek narobi to 0 komenta a za jakies zjebane manarunki 500 reputow..
?adnie ladnie :)
 
Status
Not open for further replies.
Top