Zorzin mandando quente eim!
=)
Ótimo code
Chato é compilar :~
=/
Se eu soubesse compilar....
xD
UuhauHAauh
Mais é isso ai cara
Te adimiro
Atenciosamente,
Baracs
Por Zorzin, 08 de jan. de 2007 em Linguagens de Programação
Zorzin mandando quente eim!
=)
Ótimo code
Chato é compilar :~
=/
Se eu soubesse compilar....
xD
UuhauHAauh
Mais é isso ai cara
Te adimiro
Atenciosamente,
Baracs
Pus aqui ta funfando bem ![]()
so n consegui testa o npc pq aki ta de chico ![]()
Muito loco o Code
Puis em todos os meus NPC's já
Flws
info
Grupo: Visconde
Registrado: 20/08/06
Posts: 250
Reputação: +146

Esse code ta muito bom.
Ja coloquei aqui e ta ótimo.
Ele só meio grande.
muito bom zorzin você é muito bom fico perfeito o code so teu fã um dia quero ser um bom programador como você é =]
Ótimo Code...
Gostei do seu Trabalho...
Manu, que rox...
Maneiro mesmo, é muito util e vai ajudar varios!!
Parabens bro, continua ajudando a galera do Xtibia..
Abraços,
RoD,
info
Grupo: Cavaleiro
Registrado: 22/10/05
Posts: 196
Reputação: 0

OMG!!!
oO' nunca vi um code desses tao grandeee e muuuito funcional ;DDDD
cara, amei, amei, amei, amei esse code ^^
muuuito bom mesmo x]
continue assim ;D
Mto bom ^^
cya... :hi:
OMGUE ;O
Zorzin se Manja demais =)
Amei Seu Trabalho. hIAUHIAUhaIU xD
Vlws pelos comments! =D
Se acharem algum bug, ou tiverem alguma sugestão, por favor postem aqui =)
Eu não achei nenhum bug até agora ![]()
Obrigado,
Zorzin
info
Grupo: Campones
Registrado: 23/08/06
Posts: 53
Reputação: 0

meio grande nao
e enorme
mais ta muito bom, tem sistema tipo, pa comprar tem que falar:
hi, mace, YES, bye
tem isso? ou e hi, mace, bye?
meio grande naoe enorme
mais ta muito bom, tem sistema tipo, pa comprar tem que falar:
hi, mace, YES, bye
tem isso? ou e hi, mace, bye?
Não.. é um poco mais complexo... ahseiuhe
Tipo..
Por exemplo:
------------------------
Zorzin: hi
Npc: Hello GM Zorzin! I sell meat, lifefluids. Also, I buy manafluids, ropes and apples.
Zorzin: buy 121 lifefluids
Npc: Do you want to buy 121 lifefluids for 8470 gold?
Zorzin: yes
Npc: Here you are.
------------------------
Outro exemplo:
Zorzin: hi
Npc: Hello GM Zorzin! I sell meat, lifefluids. Also, I buy manafluids, ropes and apples.
Zorzin: sell 2345 apples
Npc: Do you want to sell 2345 apples for 4690 gold?
Zorzin: yes
Npc: Thanks for this item.
------------------------
E por aí vai...
Tem vários exemplos diferentes mas não vou listar todos não pq sao muitos =)
Obrigado,
Zorzin
info
Grupo: Artesão
Registrado: 11/12/05
Posts: 108
Reputação: 0

aew cara oO
putzzzzzzz código animalll =PP
isso é coisa de gente ignorante(no bom sentido, se é que você me entende)
código extremamente bom xD
muito útil, se sairem uns OTs bons 7.9 com certeza usarei esse seu code
você sempre faz uns codes muito úteis
vlwws
flws ae
fuiz!!
info
Grupo: Campones
Registrado: 01/02/06
Posts: 74
Reputação: 0
Oi gente! =)
Criei um buy/sell system que tem um monte de opções e está funcionando perfeitamente...
No meu buy/sell:
* Você pode comprar infinitos items [por exemplo: buy 121 maces, buy 267 apples]
* Você pode vender infinitos items [por exemplo: sell 456 hams, sell 21 ropes]
* Você pode comprar/vender items com Subtype [por exemplo: manafluids, runas]
* LuaScript "haveItem(cid, itemid, count, subtype, iscountable)" [checka se o player tem algum determinado item, funciona pra todos luascripts(npcs,actions,etc)]
* Novas Funções em data/npc/script/lib/npc.lua
* Você pode configurar as mensagems que o npc vai falar no NpcScript [por exemplo: Here you are.]
* Você pode configurar o máximo de items que podem ser comprados no config.lua
* O npc pergunta se você quer comprar/vender o item
* e muito mais!!
Primeiro, você precisa da função getCountNumber(msg) feita pelo Soulblaster:
No final de data/npc/scripts/lib/npc.lua adicione:
------------------------------------------
Vamos começar com o code?? Gogogo
No final de game.cpp adicione:
#ifdef ZORZIN_BUY_SELL uint32_t Game::haveItem(Cylinder* cylinder, uint32_t item_id, uint16_t subtype, uint16_t type) { if(cylinder == NULL){ return 0; } std::list<Container*> listContainer; ItemList::const_iterator it; Container* tmpContainer = NULL; Thing* thing = NULL; Item* item = NULL; unsigned int itemCount = 0; for(int i = cylinder->__getFirstIndex(); i < cylinder->__getLastIndex(); ++i){ if(!(thing = cylinder->__getThing(i))) continue; if(!(item = thing->getItem())) continue; if(tmpContainer = item->getContainer()){ listContainer.push_back(tmpContainer); } else{ if(item->getID() == item_id) { if(type == 0){ if(item->hasSubType() && item->getItemCountOrSubtype() == subtype) ++itemCount; else if(!item->hasSubType()) ++itemCount; } else if(type == 1){ if(item->getItemCount() > 0) itemCount += item->getItemCount(); } } } } while(listContainer.size() > 0){ Container* container = listContainer.front(); listContainer.pop_front(); for(it = container->getItems(); it != container->getEnd(); ++it){ Item* item = *it; if(tmpContainer = item->getContainer()){ listContainer.push_back(tmpContainer); } else if(item->getID() == item_id) { if(type == 0){ if(item->hasSubType() && item->getItemCountOrSubtype() == subtype) ++itemCount; else if(!item->hasSubType()) ++itemCount; } else if(type == 1){ if(item->getItemCount() > 0) itemCount += item->getItemCount(); } } } } return itemCount; } void Game::deleteItemSubType(Cylinder* cylinder, uint32_t item_id, uint16_t subtype, uint32_t how_many) { if(cylinder == NULL){ return; } int xx = 0; std::list<Container*> listContainer; ItemList::const_iterator it; Container* tmpContainer = NULL; Thing* thing = NULL; Item* item = NULL; unsigned int itemCount = 0; for(int i = cylinder->__getFirstIndex(); i < cylinder->__getLastIndex(); ++i){ if(!(thing = cylinder->__getThing(i))) continue; if(!(item = thing->getItem())) continue; if(tmpContainer = item->getContainer()){ listContainer.push_back(tmpContainer); } else{ if(item->getID() == item_id && subtype != 0 && item->hasSubType() && item->getItemCountOrSubtype() == subtype && xx < how_many){ removeItemOfType(cylinder, item_id, 1); ++xx; } } } while(listContainer.size() > 0){ Container* container = listContainer.front(); listContainer.pop_front(); for(it = container->getItems(); it != container->getEnd(); ++it){ Item* item = *it; if(tmpContainer = item->getContainer()){ listContainer.push_back(tmpContainer); } else if(item->getID() == item_id && subtype != 0 && item->hasSubType() && item->getItemCountOrSubtype() == subtype && xx < how_many){ removeItemOfType(cylinder, item_id, 1); ++xx; } } } } #endif------------------------------------------
Em game.h, depois de:
class Game { public: Game(); ~Game();Adicione:
------------------------------------------
Em configmanager.cpp, depois de:
Adicione:
------------------------------------------
Em configmanager.h, depois de:
Adicione:
Em configmanager.h, depois de:
Adicione:
------------------------------------------
Em Luascript.cpp, depois de:
Add:
------------------------------------------
No final de Luascript.cpp adicione:
#ifdef ZORZIN_BUY_SELL int LuaScriptInterface::haveItem(lua_State *L) { uint16_t type = (uint16_t)popNumber(L); uint16_t subtype = (uint16_t)popNumber(L); uint16_t count = (uint16_t)popNumber(L); uint32_t itemId = (uint32_t)popNumber(L); uint32_t cid = (uint32_t)popNumber(L); ScriptEnviroment* env = getScriptEnv(); Player* player = env->getPlayerByUID(cid); if(player){ if(g_game.haveItem(player, itemId, subtype, type) >= count){ lua_pushnumber(L, LUA_TRUE); } else{ lua_pushnumber(L, LUA_FALSE); } } else{ reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnumber(L, LUA_ERROR); } return 1; } #endif------------------------------------------
Em Luascript.h, depois de:
Adicione:
------------------------------------------
Em Npc.cpp, depois de:
Adicione:
------------------------------------------
No final de Npc.cpp, adicione:
#ifdef ZORZIN_BUY_SELL int NpcScriptInterface::luaBuyItem(lua_State* L) { //Buy/Sell System by Zorzin std::string name(popString(L)); short type = (short)popNumber(L); long price = (int)popNumber(L); int how_many = (int)popNumber(L); int count_or_subtype = (short)popNumber(L); int item_id = (int)popNumber(L); int cid = (int)popNumber(L); Player* player = g_game.getPlayerByID(cid); uint32_t getPlayerMoney = g_game.getMoney(player); short add_count = 0; #ifdef USING_OLD_CVS Npc* mynpc = getNpc(); #else ScriptEnviroment* env = getScriptEnv(); Npc* mynpc = env->getNpc(); #endif Tile* ground = player->getTile(); if(type == 1 && count_or_subtype == 0) count_or_subtype = 1; std::stringstream textMsg; if(type == 0 && how_many > g_config.getNumber(ConfigManager::MAX_ITEMS_NOTCOUNTABLE)){ textMsg << g_config.getString(ConfigManager::MAX_ITEMS_MSG) << g_config.getNumber(ConfigManager::MAX_ITEMS_NOTCOUNTABLE) << " " << name << "."; mynpc->doSay(textMsg.str().c_str()); } else if(type == 1 && count_or_subtype > g_config.getNumber(ConfigManager::MAX_ITEMS_COUNTABLE)){ textMsg << g_config.getString(ConfigManager::MAX_ITEMS_MSG) << g_config.getNumber(ConfigManager::MAX_ITEMS_COUNTABLE) << " " << name << "."; mynpc->doSay(textMsg.str().c_str()); } else{ if(getPlayerMoney >= price){ //Checks if the player has the money if(type == 1 && count_or_subtype <= 100) how_many = 1; else if(type == 1 && count_or_subtype > 100){ how_many = count_or_subtype/100; add_count = count_or_subtype% 100; count_or_subtype = 100; } g_game.removeMoney(player, price); for(int cont = 0; cont < how_many; ++cont){ ReturnValue ret = g_game.internalPlayerAddItem(player, Item::CreateItem(item_id, count_or_subtype)); if(ret != RET_NOERROR) ground->__internalAddThing(Item::CreateItem(item_id, count_or_subtype)); if(add_count != 0 && how_many == cont+1){ ret = g_game.internalPlayerAddItem(player, Item::CreateItem(item_id, add_count)); if(ret != RET_NOERROR) ret = g_game.internalAddItem(ground, Item::CreateItem(item_id, add_count), INDEX_WHEREEVER, FLAG_NOLIMIT); } } lua_pushnumber(L, 1); //return 1 on the NpcScript :P } else lua_pushnumber(L, 0); //return 0 on the NpcScript :P } return 1; } int NpcScriptInterface::luaSellItem(lua_State* L) { //Buy/Sell System by Zorzin short type = (short)popNumber(L); long price = (int)popNumber(L); int how_many = (int)popNumber(L); short count_or_subtype = (short)popNumber(L); int item_id = (int)popNumber(L); int cid = (int)popNumber(L); short sub_type = 0; if(type == 0) sub_type = count_or_subtype; Player* player = g_game.getPlayerByID(cid); uint32_t getPlayerItem = g_game.haveItem(player, item_id, sub_type, type); short remove_count = 0; #ifdef USING_OLD_CVS Npc* mynpc = getNpc(); #else ScriptEnviroment* env = getScriptEnv(); Npc* mynpc = env->getNpc(); #endif Tile* ground = player->getTile(); if((type == 0 && getPlayerItem >= how_many) || (type == 1 && getPlayerItem >= count_or_subtype)){ //checks if the players has the items if(type == 1 && count_or_subtype <= 100) how_many = 1; else if(type == 1 && count_or_subtype > 100){ how_many = count_or_subtype/100; remove_count = count_or_subtype% 100; count_or_subtype = 100; } if(type == 0 && count_or_subtype != 0) g_game.deleteItemSubType(player, item_id, count_or_subtype, how_many); else{ if(type == 0 && count_or_subtype == 0) count_or_subtype = 1; for(int cont = 0; cont < how_many; ++cont){ g_game.removeItemOfType(player, item_id, count_or_subtype); if(remove_count != 0 && how_many == cont+1) g_game.removeItemOfType(player, item_id, remove_count); } } if(price > 9999){ ReturnValue ret = g_game.internalPlayerAddItem(player, Item::CreateItem(2160, price/10000)); if(ret != RET_NOERROR) ret = g_game.internalAddItem(ground, Item::CreateItem(2160, price/10000), INDEX_WHEREEVER, FLAG_NOLIMIT); price = price%10000; } if(price > 99){ ReturnValue ret = g_game.internalPlayerAddItem(player, Item::CreateItem(2152, price/100)); if(ret != RET_NOERROR) ret = g_game.internalAddItem(ground, Item::CreateItem(2152, price/100), INDEX_WHEREEVER, FLAG_NOLIMIT); price = price%100; } if(price > 0){ ReturnValue ret = g_game.internalPlayerAddItem(player, Item::CreateItem(2148, price)); if(ret != RET_NOERROR) ret = g_game.internalAddItem(ground, Item::CreateItem(2148, price), INDEX_WHEREEVER, FLAG_NOLIMIT); price = 0; } lua_pushnumber(L, 1); } else lua_pushnumber(L, 0); return 1; } #endif------------------------------------------
Em Npc.h, depois de:
Add:
------------------------------------------
Agora, cria um novo arquivo em data/npc/ named: "test.xml" e adicione nesse arquivo:
------------------------------------------
Agora, cria um novo arquivo em data/npc/scripts/ named: "test.lua" e adicione nesse arquivo:
------------------------------------------
No final de data/npc/scripts/lib/npc.lua Adicione:
function sendMsgBuySell(cid,itemid,count,price,article,name,plural,b_s) price = price*count if b_s ~= 'buy' and b_s ~= 'sell' then b_s = 'sell' end if count == 1 then selfSay('Do you want to '.. b_s ..' '.. article ..' '.. name ..' for '.. price ..' gold?') else name = plural selfSay('Do you want to '.. b_s ..' '.. count ..' '.. name ..' for '.. price ..' gold?') end end function buyItem(cid,itemid,count,subtype,price,type,name,plural,msgerror,msgok,msgno,msg) price = price*count if count > 1 then name = plural end if msgcontains(msg, 'yes') then if type == 0 then buy_status = buy(cid,itemid,subtype,count,price,0,name) else buy_status = buy(cid,itemid,count,subtype,price,1,name) end if buy_status == 1 then selfSay(msgok) elseif buy_status == 0 then selfSay(msgerror) end elseif msgcontains(msg, 'no') then selfSay(msgno) end -- msgcontains end --function function sellItem(cid,itemid,count,subtype,price,type,msgerror,msgok,msgno,msg) price = price*count if msgcontains(msg, 'yes') then if type == 0 then sell_status = sell(cid,itemid,subtype,count,price,0) else sell_status = sell(cid,itemid,count,subtype,price,1) end if sell_status == 1 then selfSay(msgok) else selfSay(msgerror) end talk_state = 0 elseif msgcontains(msg, 'no') then selfSay(msgno) end end------------------------------------------
Em Project Options (Alt+P) > Parameters > C++ Compiler adicione:
------------------------------------------
Adicione no config.lua:
------------------------------------------
Agora dê rebuild all
---------------------------
Se você ta tendo compilers errors no npc.cpp, vai em Project Options (Alt+P) > Parameters > C++ Compiler e adicione:
---------------------------
É isso ai.. Agora vou explicar o meu buy/sell system (em data/npc/scripts/test.lua)...
buy_error e sell_error -> é a mensagem que vai ser mandada para o player quanto ele nao tiver dinheiro ou o item necessário
buy_ok e sell_ok -> é a mensagem que vai ser mandada quando o buy/sell for concluído
buy_no e sell_no, é a mensagem que vai ser mandada quando o player dizer no
'sell' -> o tipo (pode ser sell ou buy)
2006 -> itemID
getCountNumber(msg) -> não mude isso!
7 -> subtype
50 -> preço de 1 item
0 -> iscountable (se o Item é Contável, coloque 1... se o Item não é Contável, coloque 0 [Ex: Manafluid não é Contável.. Para Manafluid coloque 0])
'a' -> o artigo (pode ser a ou an)
'manafluid' -> nome do item no singular
'manafluids' -> nome do item no plural
cid -> não mude isso!
2674 -> itemID
120 -> count
0 -> subtype
1 -> iscountable (se o Item é Contável, coloque 1... se o Item não é Contável, coloque 0 [Ex: Manafluid não é Contável.. Para Manafluid coloque 0])
------------------------------------------
Credits: Zorzin
Espero que vocês tenham gostado.. =)
Comments plz :icon1:
Obrigado,
Zorzin
Editado Janeiro 9 por Zorzin