• 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!

Compiling Problem compile onMonsterSpawn

maikons

Member
Joined
Aug 1, 2015
Messages
227
Reaction score
16
I've tried to use this in my 0.4 sources:
Feature - [CreatureEvent] OnSpawn(cid)

But it's not compiling...

Showing me this errors:
Code:
creatureevent.cpp: In member function ‘uint32_t CreatureEvent::executeOnSpawn(Creature*)’:
creatureevent.cpp:2045:7: error: could not convert ‘((CreatureEvent*)this)->CreatureEvent::<anonymous>.Event::m_scriptData’ from ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ to ‘bool’
    if(m_scriptData)
       ^
creatureevent.cpp:2046:21: error: no match for ‘operator*’ (operand type is ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’)
     scriptstream << *m_scriptData;
                     ^
In file included from /usr/include/boost/detail/container_fwd.hpp:98:0,
                 from /usr/include/boost/functional/hash/extensions.hpp:22,
                 from /usr/include/boost/functional/hash/hash.hpp:558,
                 from /usr/include/boost/functional/hash.hpp:6,
                 from /usr/include/boost/regex/v4/basic_regex.hpp:23,
                 from /usr/include/boost/regex/v4/regex.hpp:67,
                 from /usr/include/boost/regex.hpp:31,
                 from otpch.h:36,
                 from creatureevent.cpp:17:
/usr/include/c++/5/complex:404:5: note: candidate: template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const std::complex<_Tp>&)
     operator*(const _Tp& __x, const complex<_Tp>& __y)
     ^
/usr/include/c++/5/complex:404:5: note:   template argument deduction/substitution failed:
creatureevent.cpp:2046:22: note:   candidate expects 2 arguments, 1 provided
     scriptstream << *m_scriptData;
                      ^
In file included from /usr/include/boost/detail/container_fwd.hpp:98:0,
                 from /usr/include/boost/functional/hash/extensions.hpp:22,
                 from /usr/include/boost/functional/hash/hash.hpp:558,
                 from /usr/include/boost/functional/hash.hpp:6,
                 from /usr/include/boost/regex/v4/basic_regex.hpp:23,
                 from /usr/include/boost/regex/v4/regex.hpp:67,
                 from /usr/include/boost/regex.hpp:31,
                 from otpch.h:36,
                 from creatureevent.cpp:17:
/usr/include/c++/5/complex:395:5: note: candidate: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const _Tp&)
     operator*(const complex<_Tp>& __x, const _Tp& __y)
     ^
/usr/include/c++/5/complex:395:5: note:   template argument deduction/substitution failed:
creatureevent.cpp:2046:22: note:   ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ is not derived from ‘const std::complex<_Tp>’
     scriptstream << *m_scriptData;
                      ^
In file included from /usr/include/boost/detail/container_fwd.hpp:98:0,
                 from /usr/include/boost/functional/hash/extensions.hpp:22,
                 from /usr/include/boost/functional/hash/hash.hpp:558,
                 from /usr/include/boost/functional/hash.hpp:6,
                 from /usr/include/boost/regex/v4/basic_regex.hpp:23,
                 from /usr/include/boost/regex/v4/regex.hpp:67,
                 from /usr/include/boost/regex.hpp:31,
                 from otpch.h:36,
                 from creatureevent.cpp:17:
/usr/include/c++/5/complex:386:5: note: candidate: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const std::complex<_Tp>&)
     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
     ^
/usr/include/c++/5/complex:386:5: note:   template argument deduction/substitution failed:
creatureevent.cpp:2046:22: note:   ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ is not derived from ‘const std::complex<_Tp>’
     scriptstream << *m_scriptData;
                      ^
Makefile:547: recipe for target 'creatureevent.o' failed
make[1]: *** [creatureevent.o] Error 1

creatureevent.cpp
hastebin

creatureevent.h
hastebin

monster.cpp
hastebin
 
Solution
Code:
uint32_t CreatureEvent::executeOnSpawn(Creature* creature)
{
    //onSpawn(cid)
    if(m_interface->reserveEnv())
    {
        ScriptEnviroment* env = m_interface->getEnv();
        if(m_scripted == EVENT_SCRIPT_BUFFER)
        {
            env->setRealPos(creature->getPosition());
            std::stringstream scriptstream;
            scriptstream << "local cid = " << env->addThing(creature) << std::endl;
            scriptstream << m_scriptData;
            bool result = true;
            if(m_interface->loadBuffer(scriptstream.str()))
            {
                lua_State* L = m_interface->getState();
                result = m_interface->getGlobalBool(L, "_result", true);
            }
            m_interface->releaseEnv()...
Code:
uint32_t CreatureEvent::executeOnSpawn(Creature* creature)
{
    //onSpawn(cid)
    if(m_interface->reserveEnv())
    {
        ScriptEnviroment* env = m_interface->getEnv();
        if(m_scripted == EVENT_SCRIPT_BUFFER)
        {
            env->setRealPos(creature->getPosition());
            std::stringstream scriptstream;
            scriptstream << "local cid = " << env->addThing(creature) << std::endl;
            scriptstream << m_scriptData;
            bool result = true;
            if(m_interface->loadBuffer(scriptstream.str()))
            {
                lua_State* L = m_interface->getState();
                result = m_interface->getGlobalBool(L, "_result", true);
            }
            m_interface->releaseEnv();
            return result;
        }
        else
        {
            #ifdef __DEBUG_LUASCRIPTS__
            std::stringstream desc;
            desc << creature->getName();
            env->setEvent(desc.str());
            #endif
            env->setScriptId(m_scriptId, m_interface);
            env->setRealPos(creature->getPosition());
            lua_State* L = m_interface->getState();
            m_interface->pushFunction(m_scriptId);
            lua_pushnumber(L, env->addThing(creature));
            bool result = m_interface->callFunction(1);
            m_interface->releaseEnv();
            return result;
        }
    }
    else
    {
        std::clog << "[Error - CreatureEvent::executeCast] Call stack overflow." << std::endl;
        return 0;
    }
}
 
Solution
Thank you @heba now it's compiling right!
But why not work? Why monster is not spawning with skulls? Do i understand something wrong?

Code:
<event type="spawn" name="monsterSpawn" registerTo ="monster" event="script" value="monster_spawn.lua"/>

monster_spawn.lua
Code:
function onSpawn(cid)
    doBroadcastMessage("Monster ".. getCreatureName(cid).." was created.")
    doCreatureSetSkullType(cid, math.random(1, 5))
    return true
end
 
Back
Top