• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

CreatureScript -> onAdvance

Nostradamus

Member
Joined
Jun 2, 2007
Messages
219
Reaction score
6
I saw here in this forum, one function named onAdvance by 4220niller, but i didn't like his script, so i decided to make for myself.

I did not tested the code, but i think it will work, if not, please report the problem occured here.

creatureevent.cpp

After:

Code:
m_logoutEvent = NULL;

Add:

Code:
m_advanceEvent = NULL;

After:

Code:
delete m_logoutEvent;

Add:

Code:
delete m_advanceEvent;

After:

Code:
m_logoutEvent->clearEvent();

Add:

Code:
m_advanceEvent->clearEvent();

After:

Code:
case CREATURE_EVENT_LOGOUT:
    delete m_logoutEvent;
    m_logoutEvent = creatureEvent;
    return true;

Add:

Code:
case CREATURE_EVENT_ADVANCE:
    delete m_advanceEvent;
    m_advanceEvent = creatureEvent;
    return true;

After:

Code:
uint32_t CreatureEvents::playerLogout(Player* player)
{
    if(m_logoutEvent)
        return m_logoutEvent->executeOnLogout(player);
    else
        return 0;
}

Add:

Code:
uint32_t CreatureEvents::playerAdvance(Player* player)
{
    if(m_advanceEvent)
        return m_advanceEvent->executeOnAdvance(player);
    else
        return 0;
}

After:

Code:
else if(str == "logout")
    m_type = CREATURE_EVENT_LOGOUT;

Add:

Code:
else if(str == "advance")
    m_type = CREATURE_EVENT_ADVANCE;

After:

Code:
case CREATURE_EVENT_LOGOUT:
    return "onLogout";

Add:

Code:
case CREATURE_EVENT_ADVANCE:
    return "onAdvance";

In the end of the file, add:

Code:
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

After:

Code:
CREATURE_EVENT_LOGOUT,

Add:

Code:
CREATURE_EVENT_ADVANCE

_____________________________________

After:

Code:
uint32_t playerLogout(Player* player);

Add:

Code:
uint32_t playerAdvance(Player* player);

After:

Code:
CreatureEvent* m_logoutEvent;

Add:

Code:
CreatureEvent* m_advanceEvent;

After:

Code:
uint32_t executeOnLogout(Player* player);
Add:

Code:
uint32_t executeOnAdvance(Player* player);

player.cpp

After:

Code:
levelMsg << "You advanced from Level " << prevLevel << " to Level " << newLevel << ".";
sendTextMessage(MSG_EVENT_ADVANCE, levelMsg.str());

Add:

Code:
//scripting event - onAdvance
g_creatureEvents->playerAdvance(this);

After:

Code:
advMsg << "You advanced in " << g_game.getSkillName(skill) << ".";
client->sendTextMessage(MSG_EVENT_ADVANCE, advMsg.str());
client->sendSkills();

Add:

Code:
//scripting event - onAdvance
g_creatureEvents->playerAdvance(this);

After:

Code:
MaglvMsg << "You advanced to magic level " << magLevel << ".";
sendTextMessage(MSG_EVENT_ADVANCE, MaglvMsg.str());
sendStats();

Add:

Code:
//scripting event - onAdvance
g_creatureEvents->playerAdvance(this);
 
Last edited:
you could, for example, broadcast whenever someone advances.
Or maybe change a file when someone sets a new highscore.
etc.
:p
 
I prefer niller's. It doesn't require you to re-compile. It's also better cause you get to know oldlevel and newlevel.
 
Its awesome, but what it will return?

When i tried:
Code:
function onAdvance(cid, oldlevel)
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "GZ!")
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, oldlevel)
end
And server crashed.

So i checked in sources and i see, that i will only return "cid?

so i need to check level like this?:
Code:
function onAdvance(cid)
    if getPlayerLevel(cid) == 100 then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Woow! 100 level, gz!")
    end
end

#Edit

Hahha, this is really cool :D

Example script:
Code:
function onAdvance(cid)
	if getPlayerLevel(cid) == 100 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 level! Gratz! ;)", 

MESSAGE_EVENT_ADVANCE)
	end
end

#Edit2

But what if i want add something more, like skills checking?
Code:
function onAdvance(cid)
	if getPlayerLevel(cid) == 100 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 level! Gratz!", 

MESSAGE_EVENT_ADVANCE)
	elseif getPlayerSkill(cid, 2) == 100 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 sword fighting skill! Gratz! ", MESSAGE_EVENT_ADVANCE)
	end	
end

It will always send "xxx has advanced to 100 level! Gratz" when player have 100 level, and advance in sword =\
 
Last edited:
Help please, i try make this feature for the lastes TFS SVN and give me this error

Code:
228 C:\TFS\forgottenserver\trunk\creatureevent.cpp no `uint32_t CreatureEvents::playerAdvance(Player*)' member function declared in class `CreatureEvents'

Code:
Compiler: Default compiler
Building Makefile: "C:\TFS\forgottenserver\Makefile.win"
Executing  make...
make.exe -f "C:\TFS\forgottenserver\Makefile.win" all
g++.exe -c trunk/creatureevent.cpp -o trunk/creatureevent.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"  -D__USE_MYSQL__ -D__USE_SQLITE__ -D__SERVER_PROTECTION__  

trunk/creatureevent.cpp:189: error: no `uint32_t CreatureEvents::playerAdvance(Player*)' member function declared in class `CreatureEvents'

make.exe: *** [trunk/creatureevent.o] Error 1

Execution terminated
 
Last edited:
Its awesome, but what it will return?

When i tried:
Code:
function onAdvance(cid, oldlevel)
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "GZ!")
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, oldlevel)
end
And server crashed.

So i checked in sources and i see, that i will only return "cid?

so i need to check level like this?:
Code:
function onAdvance(cid)
    if getPlayerLevel(cid) == 100 then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Woow! 100 level, gz!")

       else

    end
end

#Edit

Hahha, this is really cool :D

Example script:
Code:
function onAdvance(cid)
	if getPlayerLevel(cid) == 100 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 level! Gratz! ;)", 

MESSAGE_EVENT_ADVANCE)
	end
end

#Edit2

But what if i want add something more, like skills checking?
Code:
function onAdvance(cid)
	if getPlayerLevel(cid) == 100 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 level! Gratz!", 

MESSAGE_EVENT_ADVANCE)
	elseif getPlayerSkill(cid, 2) == 100 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 sword fighting skill! Gratz! ", MESSAGE_EVENT_ADVANCE)
	end	
end

It will always send "xxx has advanced to 100 level! Gratz" when player have 100 level, and advance in sword =\


You can always add a storage value...


Code:
function onAdvance(cid)

	if getPlayerLevel(cid) == 100 and getPlayerStorageValue(cid, 1000) == -1 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 level! Gratz!", 
                setPlayerStorageValue(cid, 1000)

MESSAGE_EVENT_ADVANCE)
	elseif getPlayerSkill(cid, 2) == 100 and getPlayerStorageValue(cid, 1001) == -1 then
		broadcastMessage(getPlayerName(cid).." has advanced to 100 sword fighting skill! Gratz! ", MESSAGE_EVENT_ADVANCE)
                setPlayerStorageValue(cid, 1001)
        else

	end	
end
 
I don't have m_logoutEvent = NULL; in my creaturevent.cpp :/ Help me. I have tfs 0.2.13 by gesior
 
This code isn't made for newer TFS, things have been changed since this code was released.
 
Back
Top