RI

getCreaturePathTo(cid, position, maxSearchDist)

Por RigBy, 01 de jun. de 2015 em Linguagens de Programação

script
7
1.5k
RigByR
01 de junho de 2015 às 10:50

getCreaturePathTo(cid, position, maxSearchDist)

g5q414x.gif

 

Retornará uma tabela com as direções que o jogador deve seguir para chegar no ponto position. Não contem as posições que ele deve passar por. maxSearchDist é o valor máximo de passos que ele vai dar em direção à essa position e na via das dúvidas coloque o maior valor de distancia entre as duas posições.

Ex: Da para fazer um npc anda até certo lugar e depois volta.

 

Suporte para: TFS 0.4/0.3.6 e OTX2

 

Em luascript.h depois de:

static int32_t luaGetCreatureName(lua_State* L);

Adicionar:

static int32_t luaGetCreaturePathTo(lua_State* L);

Em luascript.cpp depois de:

//getCreatureName(cid)
lua_register(m_luaState, "getCreatureName", LuaInterface::luaGetCreatureName);

Adicionar:

//getCreaturePathTo(cid, pos, maxSearchDist)
lua_register(m_luaState, "getCreaturePathTo", LuaInterface::luaGetCreaturePathTo);

Depois de:

int32_t LuaInterface::luaGetCreatureName(lua_State* L)
{
//getCreatureName(cid)
    ScriptEnviroment* env = getEnv();
    if(Creature* creature = env->getCreatureByUID(popNumber(L)))
        lua_pushstring(L, creature->getName().c_str());
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    return 1;
}

Adicionar:

int32_t LuaInterface::luaGetCreaturePathTo(lua_State* L)
{
//getCreaturePathTo(cid, pos, maxSearchDist)
    ScriptEnviroment* env = getEnv();
    int32_t maxSearchDist = popNumber(L);
    PositionEx position;
    popPosition(L, position);
    Creature* creature = env->getCreatureByUID(popNumber(L));
    if (!creature) {
        lua_pushnil(L);
        return 1;
    }
    std::list<Direction> dirList;
    lua_newtable(L);
    if (g_game.getPathTo(creature, position, dirList, maxSearchDist)) {
        std::list<Direction>::const_iterator it = dirList.begin();
        for (int32_t index = 1; it != dirList.end(); ++it, ++index) {
            lua_pushnumber(L, index);
            lua_pushnumber(L, (*it));
            pushTable(L);
        }
    } else {
        lua_pushboolean(L, false);
    }
    return 1;
}

Credito: Elwyn

Editado Junho 2 por RigBy

FurabioF
01 de junho de 2015 às 13:17

best função do nosso amado guga happy.png

BeekiB
02 de junho de 2015 às 13:01

Pode fazer um video ou postar screenshots dela funcionando inGame?

RigByR
02 de junho de 2015 às 13:24

Tá, depois eu faço isso, eu tô no celular agora mas ainda hoje tento posta uma gif aqui com o funcionamento dele.

FurabioF
02 de junho de 2015 às 13:32

uma gif feita pelo wolf, com a função :

 

g5q414x.gif

RigByR
02 de junho de 2015 às 13:45

uma gif feita pelo wolf, com a função :

 

g5q414x.gif

 

"Você já atingiu seu limite de reputações positivas para hoje."

Vlw ai, já coloquei la no tópico.

6 meses depois...
CaronteC
09 de dezembro de 2015 às 13:33

Uma pena não funcionar para descer escadas...

mas nada que um teleportThing não resolva...