Jump to content

Spawning monster causes it to be type NPC, how to make it so it is monster?


Recommended Posts

  • Premium
ALUA(_spawn_monster_in_map)

    {

        if (false == lua_isnumber(L, 1) || false == lua_isnumber(L, 2) || false == lua_isboolean(L, 3) ||

            false == lua_isnumber(L, 4) || false == lua_isnumber(L, 5) || false == lua_isnumber(L, 6))

        {

            lua_pushnumber(L, 0); // Return an error in the form of 0 if inputs are incorrect

            return 1;

        }


        const DWORD dwVnum = static_cast<DWORD>(lua_tonumber(L, 1));

        const size_t count = MINMAX(1, static_cast<size_t>(lua_tonumber(L, 2)), 10);

        const bool isAggressive = static_cast<bool>(lua_toboolean(L, 3));

        const int iMapIndex = static_cast<int>(lua_tonumber(L, 4));

        const int iMapX = static_cast<int>(lua_tonumber(L, 5));

        const int iMapY = static_cast<int>(lua_tonumber(L, 6));


        PIXEL_POSITION pos;

        if (!SECTREE_MANAGER::instance().GetMapBasePositionByMapIndex(iMapIndex, pos))

        {

            sys_err("QUEST _spawn_mob_in_map: cannot find base position in this map %d", iMapIndex);

            lua_pushnumber(L, 0); // Push 0 to indicate failure

            return 1;

        }


        const CMob *pMonster = CMobManager::instance().Get(dwVnum);

        if (pMonster == NULL)

        {

            sys_err("QUEST _spawn_mob_in_map: no mob data for VNUM %d", dwVnum);

            lua_pushnumber(L, 0); // Push 0 to indicate failure

            return 1;

        }


        lua_newtable(L); // Create a new table on the stack to hold the VIDs


        size_t SpawnCount = 0;


        for (size_t i = 0; i < count; ++i)

        {

            LPCHARACTER pSpawnMonster = CHARACTER_MANAGER::instance().SpawnMobRange(dwVnum,

                                                                                    iMapIndex,

                                                                                    pos.x - number(200, 750) + (iMapX * 100),

                                                                                    pos.y - number(200, 750) + (iMapY * 100),

                                                                                    pos.x + number(200, 750) + (iMapX * 100),

                                                                                    pos.y + number(200, 750) + (iMapY * 100),

                                                                                    true,

                                                                                    pMonster->m_table.bType == CHAR_TYPE_MONSTER,

                                                                                    isAggressive);


            if (pSpawnMonster != NULL)

            {

                lua_pushnumber(L, SpawnCount + 1);          // Push the index in the table

                lua_pushnumber(L, pSpawnMonster->GetVID()); // Push the VID

                lua_settable(L, -3);                        // Set the table at index -3 with key at -2 and value at -1

                SpawnCount++;

            }

        }


        sys_log(0, "QUEST Spawn Monster: VNUM(%u) COUNT(%u) isAggressive(%b)", dwVnum, SpawnCount, isAggressive);


        return 1; // Returns the table at the top of the stack

    }

As u can see above i spawn the mob as `CHAR_TYPE_MONSTER` but when I m checking if
 

		if (attacker->IsNPC() || target->IsNPC())
		{
			sys_log(0, "MOB_ATTACK_FUNC Victim is NPC not Monster not attackable");
			lua_pushboolean(L, 0);
			lua_pushstring(L, "MOB_ATTACK_FUNC Victim is NPC not Monster not attackable");
			return 0;
		}

This is always returning true, and bcs of it, i cannot set `bool bAttackSuccess1 = attacker->Attack(target, 0);`
Because apparently a npc cannot attack

does anybody know how to spawn a mob (Character instance) that is not NPC but mosnter so it can attack other monsters?

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Active+ Member
On 4/14/2024 at 12:02 AM, astroNOT said:
ALUA(_spawn_monster_in_map)

    {

        if (false == lua_isnumber(L, 1) || false == lua_isnumber(L, 2) || false == lua_isboolean(L, 3) ||

            false == lua_isnumber(L, 4) || false == lua_isnumber(L, 5) || false == lua_isnumber(L, 6))

        {

            lua_pushnumber(L, 0); // Return an error in the form of 0 if inputs are incorrect

            return 1;

        }


        const DWORD dwVnum = static_cast<DWORD>(lua_tonumber(L, 1));

        const size_t count = MINMAX(1, static_cast<size_t>(lua_tonumber(L, 2)), 10);

        const bool isAggressive = static_cast<bool>(lua_toboolean(L, 3));

        const int iMapIndex = static_cast<int>(lua_tonumber(L, 4));

        const int iMapX = static_cast<int>(lua_tonumber(L, 5));

        const int iMapY = static_cast<int>(lua_tonumber(L, 6));


        PIXEL_POSITION pos;

        if (!SECTREE_MANAGER::instance().GetMapBasePositionByMapIndex(iMapIndex, pos))

        {

            sys_err("QUEST _spawn_mob_in_map: cannot find base position in this map %d", iMapIndex);

            lua_pushnumber(L, 0); // Push 0 to indicate failure

            return 1;

        }


        const CMob *pMonster = CMobManager::instance().Get(dwVnum);

        if (pMonster == NULL)

        {

            sys_err("QUEST _spawn_mob_in_map: no mob data for VNUM %d", dwVnum);

            lua_pushnumber(L, 0); // Push 0 to indicate failure

            return 1;

        }


        lua_newtable(L); // Create a new table on the stack to hold the VIDs


        size_t SpawnCount = 0;


        for (size_t i = 0; i < count; ++i)

        {

            LPCHARACTER pSpawnMonster = CHARACTER_MANAGER::instance().SpawnMobRange(dwVnum,

                                                                                    iMapIndex,

                                                                                    pos.x - number(200, 750) + (iMapX * 100),

                                                                                    pos.y - number(200, 750) + (iMapY * 100),

                                                                                    pos.x + number(200, 750) + (iMapX * 100),

                                                                                    pos.y + number(200, 750) + (iMapY * 100),

                                                                                    true,

                                                                                    pMonster->m_table.bType == CHAR_TYPE_MONSTER,

                                                                                    isAggressive);


            if (pSpawnMonster != NULL)

            {

                lua_pushnumber(L, SpawnCount + 1);          // Push the index in the table

                lua_pushnumber(L, pSpawnMonster->GetVID()); // Push the VID

                lua_settable(L, -3);                        // Set the table at index -3 with key at -2 and value at -1

                SpawnCount++;

            }

        }


        sys_log(0, "QUEST Spawn Monster: VNUM(%u) COUNT(%u) isAggressive(%b)", dwVnum, SpawnCount, isAggressive);


        return 1; // Returns the table at the top of the stack

    }

As u can see above i spawn the mob as `CHAR_TYPE_MONSTER` but when I m checking if
 

		if (attacker->IsNPC() || target->IsNPC())
		{
			sys_log(0, "MOB_ATTACK_FUNC Victim is NPC not Monster not attackable");
			lua_pushboolean(L, 0);
			lua_pushstring(L, "MOB_ATTACK_FUNC Victim is NPC not Monster not attackable");
			return 0;
		}

This is always returning true, and bcs of it, i cannot set `bool bAttackSuccess1 = attacker->Attack(target, 0);`
Because apparently a npc cannot attack

does anybody know how to spawn a mob (Character instance) that is not NPC but mosnter so it can attack other monsters?

 

Seems like this function is trying to create a new table in db ? is this mob u trying to spawn already an NPC In mob db ?

spacer.png

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.