Ir para conteúdo

Onmove(Cid, Fromposition, Toposition)


Foxkbt

Posts Recomendados

ola galera!

estou começando com c++

e estou add umas coisinhas que acho em forums no meu serv afim de implementalo e aprender um pouquinho mais

=D

encontrei um script muito legal em outro forum que e o onMove para creatureScripts

mas ele tem um probleminha que faz o onThink parar de funcionar...

=(

se alguem puder fixar isso ajudaria muito! "estou tentando fixar aki tb, se conceguir eu edito o post"

^^

 

creditos pelos scripts: 100% darkhaos

 

creatureevent.h:

abaixo de:

CREATURE_EVENT_DIRECTION,

cole:

CREATURE_EVENT_MOVE,

abaixo de:

uint32_t executeDirection(Creature* creature, Direction old, Direction current);

cole:

uint32_t executeMove(Creature* creature, const Position& fromPosition, const Position& toPosition);

 

creatureevent.cpp:

abaixo de:

 else if(tmpStr == "direction")
       m_type = CREATURE_EVENT_DIRECTION;

cole:

 else if(tmpStr == "move")
       m_type = CREATURE_EVENT_MOVE;

abaixo de:

case CREATURE_EVENT_DIRECTION:
           return "onDirection";

cole:

case CREATURE_EVENT_MOVE:
           return "onMove";

abaixo de:

case CREATURE_EVENT_OUTFIT:
           return "cid, old, current";

cole:

case CREATURE_EVENT_MOVE:
           return "cid, fromPosition, toPosition";

agora abaixo desta função:

uint32_t CreatureEvent::executeDirection(Creature* creature, Direction old, Direction current)

cole esta:

uint32_t CreatureEvent::executeMove(Creature* creature, const Position& fromPosition, const Position& toPosition)
{
   //onMove(cid, old, current)
   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;

                       env->streamPosition(scriptstream, "fromPosition", fromPosition, 0);
                       env->streamPosition(scriptstream, "toPosition", toPosition, 0);

           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__
           char desc[30];
           sprintf(desc, "%s", creature->getName().c_str());
           env->setEventDesc(desc);
           #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));
           LuaScriptInterface::pushPosition(L, fromPosition);
           LuaScriptInterface::pushPosition(L, toPosition);

           bool result = m_interface->callFunction(3);
           m_interface->releaseEnv();
           return result;
       }
   }
   else
   {
       std::cout << "[Error - CreatureEvent::executeMove] Call stack overflow." << std::endl;
       return 0;
   }
}

 

game.cpp:

abaixo de:

 else if(currentPos.z != 7 && (!(tmpTile = map->getTile(destPos)) || (!tmpTile->ground &&
           !tmpTile->hasProperty(BLOCKSOLID))) && (tmpTile = map->getTile(Position(
           destPos.x, destPos.y, destPos.z + 1))) && tmpTile->hasHeight(3)) //try go down
       {
           flags = flags | FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE;
           destPos.z++;
       }
   }

cole

    bool deny = false;
   CreatureEventList moveEvents = creature->getCreatureEvents(CREATURE_EVENT_MOVE);
   for(CreatureEventList::iterator it = moveEvents.begin(); it != moveEvents.end(); ++it)
       if(!(*it)->executeMove(creature, currentPos, destPos))
       deny = true;

   if(deny)
       return RET_NOTPOSSIBLE;

 

agora e so compilar

XD

 

use como exemplo!

function onMove(cid, fromPosition, toPosition)
   if(toPosition.x == 100 and toPosition.y == 100 and toPosition.z == 7) then
       doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
   end
   return true
end

 <event type="move" name="Move" event="script" value="move.lua"/>

 

bugs!

voce n pode usar desta forma:

if(toPosition == {x = 100, y = 100, z = 7}) then
   --execute script

não sei pq, nem o criador do scirpt sabe...

XD

ele tb disse que n e para usar return false

se n da esse erro:

 J:\Users\xxx\Documents\Documents\OT\0.3.6pl1\game.cpp In member function `ReturnValue Game::internalMoveCreature(Creature*, Direction, uint32_t)': 
1174
J:\Users\xxx\Documents\Documents\OT\0.3.6pl1\game.cpp cannot convert `bool' to `ReturnValue' in return 
J:\Users\xxx\Documents\Documents\OT\My Compiling\Makefile.win [build Error]  [../0.3.6pl1/game.o] Error 1

espero ter ajudado...

 

se me ajudar com os bugs...

irei editar o post colocando a correção

adicionar seus creditos

e lhe dar rep++

^^

 

17 views e nenhum coment

¬¬'

Editado por Foxkbt
Link para o comentário
Compartilhar em outros sites

  • 2 months later...
  • 4 years later...
×
×
  • Criar Novo...