Witam chcialem wrzucic na to forum Skrypt
C++ do
TFS na event
onAdvance.
Nie testowalem tego, lecz uwazam ze kod dziala poprawnie.
Autorem kodu jest Nostradamus creatureevent.cpp
Po:
Kod:
m_logoutEvent = NULL;
Dodaj:
Kod:
m_advanceEvent = NULL;
Po:
Kod:
delete m_logoutEvent;
Dodaj:
Kod:
delete m_advanceEvent;
Po:
Kod:
m_logoutEvent->clearEvent();
Dodaj:
Kod:
m_advanceEvent->clearEvent();
Po:
Kod:
case CREATURE_EVENT_LOGOUT:
delete m_logoutEvent;
m_logoutEvent = creatureEvent;
return true;
Dodaj:
Kod:
case CREATURE_EVENT_ADVANCE:
delete m_advanceEvent;
m_advanceEvent = creatureEvent;
return true;
Po:
Kod:
uint32_t CreatureEvents::playerLogout(Player* player)
{
if(m_logoutEvent)
return m_logoutEvent->executeOnLogout(player);
else
return 0;
}
Dodaj:
Kod:
uint32_t CreatureEvents::playerAdvance(Player* player)
{
if(m_advanceEvent)
return m_advanceEvent->executeOnAdvance(player);
else
return 0;
}
Po:
Kod:
else if(str == "logout")
m_type = CREATURE_EVENT_LOGOUT;
Dodaj:
Kod:
else if(str == "advance")
m_type = CREATURE_EVENT_ADVANCE;
Po:
Kod:
case CREATURE_EVENT_LOGOUT:
return "onLogout";
Dodaj:
Kod:
case CREATURE_EVENT_ADVANCE:
return "onAdvance";
Na
koncu dodaj:
Kod:
uint32_t CreatureEvent::executeOnAdvance(Player* player)
{
//onAdvance(cid)
if(m_scriptInterface->reserveScriptEnv())
{
ScriptEnviroment* env = m_scriptInterface->getScriptEnv();
#ifdef __DEBUG_LUASCRIPTS__
char desc[30];
sprintf(desc, "%s", player->getName().c_str());
env->setEventDesc(desc);
#endif
env->setScriptId(m_scriptId, m_scriptInterface);
env->setRealPos(player->getPosition());
uint32_t cid = env->addThing(player);
lua_State* L = m_scriptInterface->getLuaState();
m_scriptInterface->pushFunction(m_scriptId);
lua_pushnumber(L, cid);
int32_t result = m_scriptInterface->callFunction(1);
m_scriptInterface->releaseScriptEnv();
return (result == LUA_TRUE);
}
else
{
std::cout << "[Error] Call stack overflow. CreatureEvent::executeOnLogout" << std::endl;
return 0;
}
}
creatureevent.h
Po:
Kod:
CREATURE_EVENT_LOGOUT,
Dodaj:
Kod:
CREATURE_EVENT_ADVANCE
Po:
Kod:
uint32_t playerLogout(Player* player);
Dodaj:
Kod:
uint32_t playerAdvance(Player* player);
Po:
Kod:
CreatureEvent* m_logoutEvent;
Dodaj:
Kod:
CreatureEvent* m_advanceEvent;
Po:
Kod:
uint32_t executeOnLogout(Player* player);
Dodaj:
Kod:
uint32_t executeOnAdvance(Player* player);
player.cpp
Po:
Kod:
levelMsg << "You advanced from Level " << prevLevel << " to Level " << newLevel << ".";
sendTextMessage(MSG_EVENT_ADVANCE, levelMsg.str());
Dodaj:
Kod:
//scripting event - onAdvance
g_creatureEvents->playerAdvance(this);
Po:
Kod:
advMsg << "You advanced in " << g_game.getSkillName(skill) << ".";
client->sendTextMessage(MSG_EVENT_ADVANCE, advMsg.str());
client->sendSkills();
Dodaj:
Kod:
//scripting event - onAdvance
g_creatureEvents->playerAdvance(this);
Po:
Kod:
MaglvMsg << "You advanced to magic level " << magLevel << ".";
sendTextMessage(MSG_EVENT_ADVANCE, MaglvMsg.str());
sendStats();
Dodaj:
Kod:
//scripting event - onAdvance
g_creatureEvents->playerAdvance(this);
Mysle ze wielu osoba to sie przyda.
Tylko trzeba pamietac o jednym.
Przy dodawaniu skryptu z funkcja onAdvence, zamiast: Kod:
function onAdvance(cid, oldlevel)
Dajemy: Kod:
function onAdvance(cid)
Inaczej Bedzie CRASH Silnika Przykladowy skrypt: Kod:
function onAdvance(cid)
if getPlayerLevel(cid) == 100 then
broadcastMessage(getPlayerName(cid)..", awansowal na 100 LvL. Gratulujemy !",
MESSAGE_EVENT_ADVANCE)
end
end
Jezeli dodamy wyzej wymieniony skpypt, to jezeli jakis gracz zdobedzie 100 LvL to wszyscy to zobacza w formie napisu: Nick Gracza, awansowal na 100 LvL. Gratulujemy!
---------------------------------
Mysle ze artykul jest czytelny. Prosze O Komentarze. Pozdrawiam.