Ir para conteúdo

doPlayerRemoveSkillTry(cid, skillid, n[useMultiplier])


Posts Recomendados

---º BY: OROCHIELF º----

 

Olá galera, hoje eu vou postar uma funçao de C++, que serve para remover SKILLS. em tempo real , sem precisar "RELOGAR" para atualizar SQL.

Então vamos começar as instalaçoes.

 

Função testada na versao

TFS 0.3.6pl1

 

 

1º Passo.

Vá em LUASCRIPT.CPP, procure por

 


//doPlayerAddSkillTry(cid, skillid, n[, useMultiplier])
lua_register(m_luaState, "doPlayerAddSkillTry", LuaScriptInterface::luaDoPlayerAddSkillTry);

 

Adicione abaixo

 


//doPlayerRemoveSkillTry(cid, skillid, n[, useMultiplier])
lua_register(m_luaState, "doPlayerRemoveSkillTry", LuaScriptInterface::luaDoPlayerRemoveSkillTry);

 

Procure por

 


int32_t LuaScriptInterface::luaDoPlayerAddSkillTry(lua_State* L)
{
//doPlayerAddSkillTry(uid, skillid, n[, useMultiplier])
bool multiplier = true;
if(lua_gettop(L) > 3)
multiplier = popNumber(L);

uint32_t n = popNumber(L), skillid = popNumber(L);
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
player->addSkillAdvance((skills_t)skillid, n, multiplier);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}

 

E abaixo adicione :

 



int32_t LuaScriptInterface::luaDoPlayerRemoveSkillTry(lua_State* L)
{
//doPlayerRemoveSkillTry(uid, skillid, n[, useMultiplier])
bool multiplier = true;
if(lua_gettop(L) > 3)
multiplier = popNumber(L);

int32_t n = popNumber(L), skillid = popNumber(L);
ScriptEnviroment* env = getEnv();
if(Player* player = env->getPlayerByUID(popNumber(L)))
{
player->removeSkillAdvance((skills_t)skillid, n, multiplier);
lua_pushboolean(L, true);
}
else
{
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}

 

Agora vá em LUASCRIPT.H, e procure por :

 

static int32_t luaDoPlayerAddSkillTry(lua_State* L);

 

E abaixo adicione :

 

static int32_t luaDoPlayerRemoveSkillTry(lua_State* L);

 

Agora vá em Player.CPP e procure por

 


void Player::addManaSpent(uint64_t amount, bool useMultiplier/* = true*/)
{
if(!amount)
return;

uint64_t currReqMana = vocation->getReqMana(magLevel), nextReqMana = vocation->getReqMana(magLevel + 1);
if(currReqMana > nextReqMana) //player has reached max magic level
return;

if(useMultiplier)
amount = uint64_t((double)amount * rates[sKILL__MAGLEVEL] * g_config.getDouble(ConfigManager::RATE_MAGIC));

bool advance = false;
while(manaSpent + amount >= nextReqMana)
{
amount -= nextReqMana - manaSpent;
manaSpent = 0;
magLevel++;

char advMsg[50];
sprintf(advMsg, "You advanced to magic level %d.", magLevel);
sendTextMessage(MSG_EVENT_ADVANCE, advMsg);

advance = true;
CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
(*it)->executeAdvance(this, SKILL__MAGLEVEL, (magLevel - 1), magLevel);

currReqMana = nextReqMana;
nextReqMana = vocation->getReqMana(magLevel + 1);
if(currReqMana > nextReqMana)
{
amount = 0;
break;
}
}

if(amount)
manaSpent += amount;

uint32_t newPercent = Player::getPercentLevel(manaSpent, nextReqMana);
if(magLevelPercent != newPercent)
{
magLevelPercent = newPercent;
sendStats();
}
else if(advance)
sendStats();
}

 

E Abaixo Adicione :

 



void Player::removeSkillAdvance(skills_t skill, uint32_t count, bool useMultiplier/* = true*/)
{
if(!count)
return;

if(useMultiplier)
count = uint32_t((double)count * rates[skill] * g_config.getDouble(ConfigManager::RATE_SKILL));

uint32_t nextReqTries = vocation->getReqSkillTries(skill, skills[skill][sKILL_LEVEL] + 1);

if(!skills[skill][sKILL_LEVEL]) {
if (count > skills[skill][sKILL_TRIES])
count = skills[skill][sKILL_TRIES];

skills[skill][sKILL_LEVEL] = 0;
skills[skill][sKILL_TRIES] -= count;

count = 0;
}

std::stringstream s;

while(count > skills[skill][sKILL_TRIES])
{
count -= skills[skill][sKILL_TRIES] + 1;
skills[skill][sKILL_LEVEL]--;
nextReqTries = vocation->getReqSkillTries(skill, skills[skill][sKILL_LEVEL] + 1);

skills[skill][sKILL_TRIES] = nextReqTries > 0 ? nextReqTries - 1 : nextReqTries;
skills[skill][sKILL_PERCENT] = 0;

s.str("");
s << "You downgraded in " << getSkillName(skill);
if(g_config.getBool(ConfigManager::ADVANCING_SKILL_LEVEL))
s << " [" << skills[skill][sKILL_LEVEL] << "]";

s << ".";
sendTextMessage(MSG_EVENT_ADVANCE, s.str().c_str());

CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
(*it)->executeAdvance(this, skill, (skills[skill][sKILL_LEVEL] + 1), skills[skill][sKILL_LEVEL]);

if (!skills[skill][sKILL_LEVEL]) {
if (count > skills[skill][sKILL_TRIES])
count = skills[skill][sKILL_TRIES];

skills[skill][sKILL_LEVEL] = 0;
skills[skill][sKILL_TRIES] -= count;

count = 0;
break;
}
}

if(count)
skills[skill][sKILL_TRIES] -= count;

nextReqTries = vocation->getReqSkillTries(skill, skills[skill][sKILL_LEVEL] + 1);

uint32_t newPercent = Player::getPercentLevel(skills[skill][sKILL_TRIES], nextReqTries);
if(skills[skill][sKILL_PERCENT] != newPercent)
{
skills[skill][sKILL_PERCENT] = newPercent;
sendSkills();
}
else if(!s.str().empty())
sendSkills();
}

 

Para finalizar , vá em PLAYER.H, e procure por :

 

void addManaSpent(uint64_t amount, bool useMultiplier = true);

 

E abaixo adicione

 

void removeSkillAdvance(skills_t skill, uint32_t count, bool useMultiplier = true);

 

---------------------------------------------------------------------------------------------------------

Exemplo de Uso :

 

function onUse(cid)

if isPlayer(cid) then
doPlayerRemoveSkillTry(cid, 0, 10) -- Removeria 10 pontos de FIST
return true
end

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...