Tópico movido.
Se é um tutorial, deve ser postado na seção de aprovação de tutoriais, ok?
Abraços.
Por Flaah, 14 de ago. de 2012 em Linguagens de Programação
info
Grupo: Infante
Registrado: 13/10/08
Posts: 1.6k
Reputação: +420
Char no Tibia: Demonbholder

Tópico movido.
Se é um tutorial, deve ser postado na seção de aprovação de tutoriais, ok?
Abraços.
info
Grupo: Barão
Registrado: 26/12/11
Posts: 201
Reputação: +18
Char no Tibia: Flaah

KKKKKK' Ok's
Abraços amigo ![]()
Editado Agosto 14 por Flaah
info
Grupo: Conde
Registrado: 10/12/11
Posts: 962
Reputação: +99
Gênero: Masculino

muito bom rep+...
so funciona em 0.3.6 ??
info
Grupo: Barão
Registrado: 26/12/11
Posts: 201
Reputação: +18
Char no Tibia: Flaah

Po cara, só testei na versão 0.3.6, talvez de certo, nas versões acima... só ver. ![]()
info
Grupo: Conde
Registrado: 03/01/12
Posts: 884
Reputação: +233
Char no Tibia: Segredo

muito bom vai ajuda muitas pessoas que ta fazendo narutibia ![]()
info
Grupo: Herói
Registrado: 05/11/07
Posts: 544
Reputação: +70

Parabéns seu tutorial foi aprovado, estará sendo movido para seção correta neste instante.
Atenciosamente, Critical.
info
Grupo: Conde
Registrado: 10/12/11
Posts: 962
Reputação: +99
Gênero: Masculino

muito bom vai ajuda muitas pessoas que ta fazendo narutibia
vai ser bom pro meu wodbo bleach naruto tbm
info
Grupo: Barão
Registrado: 26/12/11
Posts: 201
Reputação: +18
Char no Tibia: Flaah

Po, valeu gente, obrigado XTibia por tudo, abraços
Editado Agosto 18 por Flaah
Eu fiz tudo como vc disse e quando vou compilar dá o seguinte erro .
4656 C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\luascript.cpp `LuaInterface' has not been declared C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\luascript.cpp In function `int32_t luaDoCreateCustomMonster(lua_State*)': 4666 C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\luascript.cpp `popNumber' was not declared in this scope 4669 C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\luascript.cpp `popString' was not declared in this scope 4671 C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\luascript.cpp `popOutfit' was not declared in this scope 4672 C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\luascript.cpp `popPosition' was not declared in this scope 4732 C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\luascript.cpp `getEnv' was not declared in this scope C:\Documents and Settings\Matt\Meus documentos\Downloads\Source\dev-cpp\Makefile.win [build Error] [obj//luascript.o] Error 1
info
Grupo: Barão
Registrado: 26/12/11
Posts: 201
Reputação: +18
Char no Tibia: Flaah

Qual a versão do seu server?!
É só mudar isso:
LuaInterface::luaDoCreateCustomMonster(lua_State* L)
por isso:
LuaScriptInterface::luaDoCreateCustomMonster(lua_State* L)
lembrando também que o monstro criado não vai poder ser convencido, ou seja, pra scripts de summon, ele não vai funcionar, vai criar um monstro que vai atacar o seu suposto dono, como um monstro normal
para que seja possível usar a função de convencer o monstro nele, é preciso alterar essa parte:
pobranyTyp->isSummonable = pobranyTyp->isIllusionable = pobranyTyp->isConvinceable = pobranyTyp->isWalkable = pobranyTyp->pushable = false;
por essa:
pobranyTyp->isSummonable = pobranyTyp->isIllusionable = pobranyTyp->isWalkable = pobranyTyp->pushable = false; pobranyTyp->isConvinceable = true;
Editado Setembro 21 por brun123
Erro: =o sshuiahushuai
Tfs usado: 0.3.5
erro:
monsters.h: In static member function 'static int32_t LuaScriptInterface::luaDoCreateCustomMonster(lua_State*)': monsters.h:145: error: 'bool Monsters::deserializeSpell(xmlNode*, spellBlock_t&, const std::string&)' is private luascript.cpp:4717: error: within this context make[1]: *** [luascript.o] Error 1 make[1]: Leaving directory `/home/src' make: *** [all] Error 2
S.O= Linux Debian 64 bits
info
Grupo: Barão
Registrado: 26/12/11
Posts: 201
Reputação: +18
Char no Tibia: Flaah

Erro: =o sshuiahushuai
Tfs usado: 0.3.5
erro:
monsters.h: In static member function 'static int32_t LuaScriptInterface::luaDoCreateCustomMonster(lua_State*)': monsters.h:145: error: 'bool Monsters::deserializeSpell(xmlNode*, spellBlock_t&, const std::string&)' is private luascript.cpp:4717: error: within this context make[1]: *** [luascript.o] Error 1 make[1]: Leaving directory `/home/src' make: *** [all] Error 2
S.O= Linux Debian 64 bits
Mano, eu acho que sua Source não é compativel, porq como vc disse, a sua é 0.3.5, e no que eu testei foi The Forgotten Server, version 0.3.6...
Tente com a The Forgotten Server, version 0.3.6, ai vai da certin ![]()
ASS: Flaah
Erro: =o sshuiahushuai
Tfs usado: 0.3.5
erro:
monsters.h: In static member function 'static int32_t LuaScriptInterface::luaDoCreateCustomMonster(lua_State*)': monsters.h:145: error: 'bool Monsters::deserializeSpell(xmlNode*, spellBlock_t&, const std::string&)' is private luascript.cpp:4717: error: within this context make[1]: *** [luascript.o] Error 1 make[1]: Leaving directory `/home/src' make: *** [all] Error 2
S.O= Linux Debian 64 bits
Faltou explicar melhor uma coisa nesse tutorial, também é preciso fazer uma modificação em monsters.h!
Em Class Monsters, vai ter 2 divisões em baixo da função, "public:" e "private:"
bool deserializeSpell(xmlNodePtr node, spellBlock_t& sb, const std::string& description = "");
Essa função de cima vai estar em "private:", tem que remover ela de "private:" e colocar ela em "public:" que é logo em cima.
Editado Dezembro 6 por CabritenhO
info
Grupo: Barão
Registrado: 26/12/11
Posts: 201
Reputação: +18
Char no Tibia: Flaah
Server usado: The Forgotten Server, version 0.3.6
Função usada: doCreateCustomMonster(name, pos, outfit, health, spells, corpse, distance, experience )
Autor: MeNi (OTLand)
Fala ai amigos do XTibia, vim aqui hoje pra trazer uma função muito maneira que é a: doCreateCustomMonster, ela é muito usada para fazer clones do proprio player (Que eu saiba).
Foto como exemplo:
Bom vamos lá:
Abra o arquivo: luascript.cpp
E abaixo do código:
int32_t LuaScriptInterface::luaDoCreateMonster(lua_State* L) { //doCreateMonster(name, pos[, displayError = true]) bool displayError = true; if(lua_gettop(L) > 2) displayError = popNumber(L); PositionEx pos; popPosition(L, pos); std::string name = popString(L); Monster* monster = Monster::createMonster(name.c_str()); if(!monster) { if(displayError) errorEx("Monster with name '" + name + "' not found"); lua_pushboolean(L, false); return 1; } if(!g_game.placeCreature(monster, pos)) { delete monster; if(displayError) errorEx("Cannot create monster: " + name); lua_pushboolean(L, true); return 1; } ScriptEnviroment* env = getEnv(); lua_pushnumber(L, env->addThing((Thing*)monster)); return 1; }Adicione:
int32_t LuaInterface::luaDoCreateCustomMonster(lua_State* L) { //doCreateCustomMonster(name, pos, outfit, health, spells, corpse, distance, experience ) uint64_t health,corpse,distance,experience; Outfit_t outfit; PositionEx pos; MonsterType* pobranyTyp = NULL; pobranyTyp = new MonsterType(); experience = popNumber(L); distance = popNumber(L); corpse = popNumber(L); std::string spells = popString(L); health = popNumber(L); outfit = popOutfit(L); popPosition(L, pos); std::string name = popString(L); Monster* monster; pobranyTyp->spellAttackList.clear(); pobranyTyp->health = health; pobranyTyp->healthMax = health; pobranyTyp->outfit = outfit; pobranyTyp->name = name; pobranyTyp->nameDescription = name; pobranyTyp->lookCorpse = corpse; pobranyTyp->targetDistance = distance; pobranyTyp->experience = experience; pobranyTyp->isSummonable = pobranyTyp->isIllusionable = pobranyTyp->isConvinceable = pobranyTyp->isWalkable = pobranyTyp->pushable = false; pobranyTyp->isAttackable = pobranyTyp->isHostile = pobranyTyp->canPushItems = pobranyTyp->canPushCreatures = true; pobranyTyp->defense = 50; pobranyTyp->armor = 80; pobranyTyp->baseSpeed = 200; pobranyTyp->changeTargetSpeed = pobranyTyp->changeTargetChance = 0; xmlDocPtr doc = xmlParseMemory(spells.c_str(), spells.length()); xmlNodePtr root = xmlDocGetRootElement(doc); xmlNodePtr tmpNode = root->children; while(tmpNode) { if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"attack")) { spellBlock_t sb; if(g_monsters.deserializeSpell(tmpNode, sb, "doCreateCustomMonster")) pobranyTyp->spellAttackList.push_back(sb); } tmpNode = tmpNode->next; } monster = Monster::createMonster(pobranyTyp); if(!g_game.placeCreature(monster, pos, false, false)) { delete monster; lua_pushboolean(L, true); return 1; } ScriptEnviroment* env = getEnv(); lua_pushnumber(L, env->addThing((Thing*)monster)); return 1; }No mesmo arquivo, abaixo do código:
Adicione:
Agora abra o arquivo: luascript.h
Nesse aquivo, abaixo da linha:
Adicione:
E pra finalizar, abra o arquivo: monsters.h
E procure a palavra: private
E coloque ela para: public
ATENÇÃO: Não exclua NENHUM código já existente, só adiciona como ja explicado acima.
OBS: A cada modificação nos arquivos que você editou, você devera salva, se não você corre o risco de perde o que você adicionou.
PS: Qualquer ERRO na hora de compilar, podem ser dos seguinte motivos:
- Você excluiu algo.
- Você copio e colo errado.
- Não soube compilar direito.
- Ou seu server não é compativel com o código.
Exemplo de uso:
1º Crie um arquivo na pasta talkactions/scripts com o nome de clone.lua e coloque em seu conteúdo:
local spells = { [1] = {used = 0, text = '<attack name="melee" interval="2000" chance="100" range="5" radius="1" target="0"><attribute key="areaEffect" value="fire"/></attack>'}, [2] = {used = 0, text = '<attack name="melee" interval="1200" chance="100" range="5" radius="1" target="0"><attribute key="areaEffect" value="energyarea"/></attack>'}, [3] = {used = 0, text = '<attack name="melee" interval="700" chance="100" range="5" radius="1" target="0"><attribute key="areaEffect" value="mortarea"/></attack>'} } local spellsNumber = 2 function randomNum(range) local rand = 0 good = false math.randomseed( os.time() ) math.random() math.random() math.random() while (not good) do rand = math.random(range) if (spells[rand].used == 0) then spells[rand].used = 1 good = true else good = false end end return rand end function onSay(cid, words) local attacks = "<a>" local num for i=1,spellsNumber,1 do num = randomNum(table.getn(spells)) attacks = attacks .. spells[num].text end attacks = attacks .. "</a>" doCreateCustomMonster(getCreatureName(cid), getCreaturePosition(cid), getCreatureOutfit(cid), getCreatureMaxHealth(cid), attacks, 6324, 1, 100) for i=1,table.getn(spells),1 do spells[i].used = 0 end attacks = "" return true endExplicando:
doCreateCustomMonster(nome, posição, outfit, health, attacks, corpo quando morto, distancia do player, experiencia)
2º Abra o arquivo talkactions.xml e adicione em qualquer lugar:
Créditos:
MeNi (OTLand) 95%, pelo script C++.
NogareD 2% (XTibia) pela talkaction.
Eu o Flaah 3% (XTibia) pela pesquisa na net pelo sistema.
Bom é isso ai pessoal, tomara que vocês tenham gostado.
AJUDEI?! +REP
Editado Setembro 15 por Flaah