Ir para conteúdo
Entre para seguir isso  
iuniX

doCreatureCastSpell

Recommended Posts

iuniX    4
iuniX

Introdução:

divisor.png

Bom eu vi que aqui no fórum tem o doPlayerCastSpell. E como isso as vezes pode não ser o que precisam. Vamos ao código.

Explicação:

divisor.png

 

Testado em: TFS 0.4 rev 3777

Autor: iuniX (with Kydrai's help)

Function name: doCreatureCastSpell(cid, spellname)

 

Basicamente é uma função que força uma criatura a usar uma spell. Ignorando mana, vocação, level e tudo mais.

 

 

Instalando:

divisor.png

Abra o teu Arquivo luascript.cpp e procure por:

 

//getCreatureHealth(cid)
lua_register(m_luaState, "getCreatureHealth", LuaInterface::luaGetCreatureHealth);

 

abaixo disso coloque:

    //doCreatureCastSpell(cid, spellname)
lua_register(m_luaState, "doCreatureCastSpell", LuaInterface::luaDoCreatureCastSpell);

 

Agora procure por:

int32_t LuaInterface::luaDoPlayerJoinParty(lua_State* L)
{
//doPlayerJoinParty(cid, lid)
ScriptEnviroment* env = getEnv();

Player* leader = env->getPlayerByUID(popNumber(L));
if(!leader)
{
	errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
	lua_pushboolean(L, false);
}

Player* player = env->getPlayerByUID(popNumber(L));
if(!player)
{
	errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
	lua_pushboolean(L, false);
}

g_game.playerJoinParty(player->getID(), leader->getID());
lua_pushboolean(L, true);
return 1;
}

 

E coloque isso antes (pule umas duas linhas de espaço para não confundir e deixar organizado)

int32_t LuaInterface::luaDoCreatureCastSpell(lua_State * L) 
{ 
//DoCreatureCastSpell (uid, spell) 
std::string spell_name = popString(L); 

ScriptEnviroment* env = getEnv();
Creature * creature = env-> getCreatureByUID (popNumber (L)); 
if (! creature) 
	{ 
		errorEx (getError (LUA_ERROR_CREATURE_NOT_FOUND)); 
		lua_pushboolean (L, false); 
		return 1; 
	} 
	InstantSpell* spell = g_spells->getInstantSpellByName (spell_name);
	if(spell)
	{ 
		if (spell-> castSpell(creature)) 
			{ 
				lua_pushboolean (L, true); 
				return 1; 
		} 
	} 
lua_pushboolean (L, false); 
return 1; 
}

 

Agora vá em luascript.h e procure por:

static int32_t luaDoPlayerAddMoney(lua_State* L);

 

e coloque isso abaixo:

static int32_t luaDoCreatureCastSpell(lua_State* L);

 

 

Utilização:

divisor.png

 

function onSay(cid, words, param, channel)
local su = getCreatureSummons(cid)[1]
doCreatureCastSpell(su, param)
doPlayerSay(cid, getCreatureName(su) .. ", use " .. param .. "!")
doSendAnimatedText(getCreaturePosition(su), param, math.random(255))
return true
end

 

 

Agradecimentos:

divisor.png

 

Obrigado ao Kydrai pela ajuda com alguns erros. E ao vyctor17 pela base que ele me deu.

Editado por iuniX

Compartilhar este post


Link para o post
Black Ice    2
Black Ice

Obrigado por sua contribuição, continue ajudando a seção crescer.

Aprovado

 

Tópico remunerado: Códigos para OpenTibia - 80 V$

Compartilhar este post


Link para o post
c4rlos    0
c4rlos

eu tentei compilar com a versão 0.3b1 e dá muitos erros

 

teria alguma forma de adaptar esse código pra essa versão ?

Compartilhar este post


Link para o post
iuniX    4
iuniX
eu tentei compilar com a versão 0.3b1 e dá muitos erros

 

teria alguma forma de adaptar esse código pra essa versão ?

 

Eu fiz para 0.4

Sinceramente, não to nem com um pouco de vontade de baixar um TFS 0.3.6 só para ver como é as sources e editar. :x

Compartilhar este post


Link para o post
dalvorsn    46
dalvorsn

Minha nega codando em c++ ._.

Vai ter que me ensinar :hehe:

Parabéns pelo código, ao meu ver está muito bom :D

 

eu tentei compilar com a versão 0.3b1 e dá muitos erros

 

teria alguma forma de adaptar esse código pra essa versão ?

Tente assim:

//doCreatureCastSpell(cid, spellname)
lua_register(m_luaState, "doCreatureCastSpell", LuaScriptInterface::luaDoCreatureCastSpell);

 

int32_t LuaScriptInterface::luaDoCreatureCastSpell(lua_State * L) 
{ 
//DoCreatureCastSpell (uid, spell) 
std::string spell_name = popString(L); 

ScriptEnviroment* env = getEnv();
Creature * creature = env-> getCreatureByUID (popNumber (L)); 
if (! creature) 
	{ 
		errorEx (getError (LUA_ERROR_CREATURE_NOT_FOUND)); 
		lua_pushboolean (L, false); 
		return 1; 
	} 
	InstantSpell* spell = g_spells->getInstantSpellByName (spell_name);
	if(spell)
	{ 
		if (spell-> castSpell(creature)) 
			{ 
				lua_pushboolean (L, true); 
				return 1; 
		} 
	} 
lua_pushboolean (L, false); 
return 1; 
}

 

Acredito que seja esse o motivo do erro, se não for não sei como ajudar :/

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×