Ir para conteúdo

[7.9+]algumas Funções Para Scripts


Posts Recomendados

Codigo criado por Lejjo de outro fórum, portanto todos os créditos à ele..

 

Funções que serão adicionadas :

doCreatureChangeMaxHealth(cid, newHealth)

doCreatureChangeMaxMana(cid, newMana)

getPlayerSummonCount(cid)

getCreatureSummonCountByName(cid, name)

 

Explicação de cada :

doCreatureChangeMaxHealth : Muda o life de certo player.

doCreatureChangeMaxMana : Muda a mana de certo player.

getPlayerSummonCount : "checa" o número total de sumons de algum player.

getCreatureSummonCountByName : "checa" o número total dos sumons pelo nome

 

Exemplos de uso :

doCreatureChangeMaxHealth

function onUse(cid, item, frompos, item2, topos)

 

getlife = getPlayerHealth(cid)

 

doSendMagicEffect(topos,2)

doCreatureChangeMaxHealth(cid,getlife+100)

doPlayerSendTextMessage(cid,22,"Parabens, você ganhou um bônus de 100 de life.")

 

end

 

doCreatureChangeMaxMana

function onUse(cid, item, frompos, item2, topos)

 

getmana = getPlayerMana(cid)

 

doSendMagicEffect(topos,2)

doCreatureChangeMaxMana(cid,getmana+100)

doPlayerSendTextMessage(cid,22,"Parabens, você ganhou um bônus de 100 de mana.")

 

end

 

getPlayerSummonCount

function onUse(cid, item, frompos, item2, topos)

 

numsummon = getPlayerSummonCount(cid)

 

if numsummon == 1 then

doPlayerSendTextMessage(cid,22,"Você tem um monstro sumonado.")

 

elseif numsummon == 2 then

doPlayerSendTextMessage(cid,22,"Você tem dois monstros sumonados.")

 

end

end

 

getCreatureSummonCountByName

function onUse(cid, item, frompos, item2, topos)

 

summon = getCreatureSummonCountByName(cid, Minotaur)

 

if summon == 2 then

doPlayerSendTextMessage(cid,22,"Você tem dois minotauros sumonados.")

else

doPlayerSendTextMessage(cid,22,"Você não tem dois minotauros sumonados.")

 

end

end

 

 

Ao codigo :

 

Em luascript.cpp após :

//escapeString(str)
lua_register(m_luaState, "escapeString", LuaScriptInterface::luaEscapeString);

 

Adicione :

//doCreatureChangeMaxHealth(cid, newHealth)
lua_register(m_luaState, "doCreatureChangeMaxHealth", LuaScriptInterface::luaDoCreatureChangeMaxHealth);

//doCreatureChangeMaxMana(cid, newMana)
lua_register(m_luaState, "doCreatureChangeMaxMana", LuaScriptInterface::luaDoCreatureChangeMaxMana);

//getPlayerSummonCount(cid)
lua_register(m_luaState, "getPlayerSummonCount", LuaScriptInterface::luaGetPlayerSummonCount);

//getCreatureSummonCountByName(cid, name)
lua_register(m_luaState, "getCreatureSummonCountByName", LuaScriptInterface::luaGetCreatureSummonCountByNam  e);

 

Após :

int32_t LuaScriptInterface::luaEscapeString(lua_State* L)
{
//escapeString(str)
std::string str = popString(L);
lua_pushstring(L, Database::escapeString(str).c_str());
return 1;
}

 

Adicione :

int32_t LuaScriptInterface::luaDoCreatureChangeMaxHealth(l  ua_State* L)
{
//doCreatureChangeMaxHealth(uid,newHealth)
int32_t healthChange = (int32_t)popNumber(L);
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Creature* creature = env->getCreatureByUID(cid);
if(creature)
{
	 creature->changeMaxHealth(healthChange);
	lua_pushnumber(L, LUA_NO_ERROR);
}
else
{
	reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_  FOUND));
	lua_pushnumber(L, LUA_ERROR);
}
return 1;
}

int32_t LuaScriptInterface::luaDoCreatureChangeMaxMana(lua  _State* L)
{
//doCreatureChangeMaxMana(uid,newMana)
int32_t manaChange = (int32_t)popNumber(L);
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Creature* creature = env->getCreatureByUID(cid);
if(creature)
{
	 creature->changeMaxMana(manaChange);
	lua_pushnumber(L, LUA_NO_ERROR);
}
else
{
	reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_  FOUND));
	lua_pushnumber(L, LUA_ERROR);
}
return 1;
}

int32_t LuaScriptInterface::luaGetPlayerSummonCount(lua_St  ate* L)
{
//getPlayerSummonCount(cid)
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Creature* creature = env->getCreatureByUID(cid);
if(creature)
{
	int32_t summons = creature->getSummonCount();
	lua_pushnumber(L, summons);
}
else
{
	reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NO  T_FOUND));
	lua_pushnumber(L, LUA_ERROR);
}
return 1;
}

int LuaScriptInterface::luaGetCreatureSummonCountByNam  e(lua_State *L)
{
std::string name = popString(L);
uint32_t uid = popNumber(L);

ScriptEnviroment* env = getScriptEnv();

Creature* creature = env->getCreatureByUID(uid);
if(creature){
	int count = 0;
	std::list<Creature*>::iterator cit;
	for(cit = creature->summons.begin(); cit != creature->summons.end(); ++cit){
		if((*cit)->getName() == name){
			count = count + 1;
		}
	}
	if(count > 0){
		lua_pushnumber(L, count);
	}
}
else{
	reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NO  T_FOUND));
	lua_pushnumber(L, LUA_ERROR);
}
return 1;
}

 

Agora em luascript.h, após :

static int32_t luaEscapeString(lua_State* L);

 

Adicione :

 static int32_t luaDoCreatureChangeMaxHealth(lua_State* L);
	static int32_t luaDoCreatureChangeMaxMana(lua_State* L);

	static int32_t luaGetPlayerSummonCount(lua_State* L);
	static int luaGetCreatureSummonCountByName(lua_State *L);

 

Agora em creature.cpp, após :

void Creature::changeHealth(int32_t healthChange)
{
if(healthChange > 0)
	health += std::min(healthChange, getMaxHealth() - health);
else
	health = std::max((int32_t)0, health + healthChange);

g_game.addCreatureHealth(this);
}

 

Adicione :

void Creature::changeMaxHealth(int32_t healthChange)
{

healthMax = (int32_t)healthChange;

g_game.addCreatureHealth(this);
}

void Creature::changeMaxMana(int32_t manaChange)
{
	manaMax = (int32_t)manaChange;

}

 

Agora em creature.h,após :

virtual void changeHealth(int32_t healthChange);

 

Adicione :

virtual void changeMaxHealth(int32_t healthChange);
	virtual void changeMaxMana(int32_t manaChange);

 

Agora Recompile tudo (ctrl+F11)..

Explicação + créditos no inicio do tópico..

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...