Jump to content

What fuction to use from Character to make two mobs fight each other?


Recommended Posts

  • Premium

I m trying to make a mob, attack another mob, by specific attacker vid and victim vid, but can't figure out which Character class method does the actual attack
 

    int game_mob_attack_mob(lua_State *L)
    {
        if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3))
        {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Invalid argument. Usage: mob_attack_mob(attacker_vid, target_vid, map_index)");
            return 2;
        }

        int attacker_vid = (int)lua_tonumber(L, 1);
        int target_vid = (int)lua_tonumber(L, 2);
        int map_index = (int)lua_tonumber(L, 3); // Expected map index

        LPCHARACTER attacker = CHARACTER_MANAGER::instance().Find(attacker_vid);
        LPCHARACTER target = CHARACTER_MANAGER::instance().Find(target_vid);

        if (!attacker || !attacker->IsMonster())
        {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Attacker not found or is not a monster.");
            return 2;
        }

        if (!target || !target->IsMonster())
        {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Target not found or is not a monster.");
            return 2;
        }

        if (attacker->GetMapIndex() != map_index || target->GetMapIndex() != map_index)
        {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Either attacker or target is not in the specified map.");
            return 2;
        }

        // All checks passed, proceed to set victim
        attacker->SetVictim(target);
        attacker->BeginFight(target);
        lua_pushboolean(L, 1);
        lua_pushstring(L, "Attack set successfully.");
        return 2;
    }

Basically, "Attack set successfully is triggered but the mobs do not attack each otther, even if they are loading by their vid...

Updated it to use
 

		attacker->SetVictim(target);
		target->SetVictim(attacker);

		// Trigger the initial attack and capture the return values
		bool bAttackSuccess1 = attacker->Attack(target, 0);

		// Return the result of the first attack attempt to Lua for debugging
		lua_pushboolean(L, bAttackSuccess1);
		if (bAttackSuccess1)
			lua_pushstring(L, "Attack by attacker was successful.");
		else
			lua_pushstring(L, "Attack by attacker failed.");

		return 2;
	}

But for some reason Attack method does not get triggered at all.. but the Attack by attacker failed is pushed succesfully

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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.