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:
//doCreateMonster(name, pos) lua_register(m_luaState, "doCreateMonster", LuaScriptInterface::luaDoCreateMonster);
Adicione:
//doCreateCustomMonster(name, pos, outfit, health, spells, corpse, distance, experience ) lua_register(m_luaState, "doCreateCustomMonster", LuaScriptInterface::luaDoCreateCustomMonster);
Agora abra o arquivo: luascript.h
Nesse aquivo, abaixo da linha:
static int32_t luaDoCreateMonster(lua_State* L);
Adicione:
static int32_t luaDoCreateCustomMonster(lua_State* L);
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 end
Explicando:
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:
<talkaction words="!clone" event="script" value="clone.lua"/>
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