Jump to content

Recommended Posts

  • Premium

File: questlua_global.cpp

Find :

void RegisterGlobalFunctionTable(lua_State* L)

and above this function add:

	// mob_spawn(vnum, x, y, map_index)
	int _mob_spawn(lua_State* L)
	{
		if (lua_gettop(L) < 4)
		{
			sys_err("_mob_spawn: not enough arguments");
			lua_pushboolean(L, 0);
			return 1;
		}

		if(false == lua_isnumber(L, 1) || false == lua_isnumber(L, 2) || false == lua_isnumber(L, 3) || false == lua_isnumber(L, 4))
		{
			sys_err("_mob_spawn: invalid arguments");
			lua_pushboolean(L, 0);
			return 1;
		}

		const DWORD dwVnum = static_cast<DWORD>(lua_tonumber(L, 1));
		const long lX = static_cast<long>(lua_tonumber(L, 2));
		const long lY = static_cast<long>(lua_tonumber(L, 3));
		const long lMapIndex = static_cast<long>(lua_tonumber(L, 4));

		const CMob* pMonster = CMobManager::instance().Get(dwVnum);
		if (!pMonster)
		{
			sys_err("_mob_spawn: wrong vnum");
			lua_pushboolean(L, 0);
			return 1;
		}

		LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(lMapIndex);
		if (!pkSectreeMap)
		{
			sys_err("_mob_spawn: wrong mapindex");
			lua_pushboolean(L, 0);
			return 1;
		}

		LPCHARACTER mob = CHARACTER_MANAGER::instance().SpawnMob(dwVnum, lMapIndex, lX, lY, 0);
		if (!mob)
		{
			sys_err("_mob_spawn: mob not spawned; coords maybe wrong?");
			lua_pushboolean(L, 0);
			return 1;
		}

		lua_pushboolean(L, 1);
		return 1;
	}

Now search for

{	"spawn_mob",					_spawn_mob						},

And add after:

{	"mob_spawn",					_mob_spawn						},

And you call it like this:

mob_spawn(vnum, x, y, map_index)

The function returns true/false if mob was called or not.

Also, if the mob is not called then it will display an error in your syserr file:

"_mob_spawn: not enough arguments" -- you called the function with fewer arguments


"_mob_spawn: invalid arguments" -- you passed an wrong arguments. all must be numbers
"_mob_spawn: wrong vnum" -- you provided wrong mob vnum
"_mob_spawn: wrong mapindex" -- you provided wrong map index
"_mob_spawn: mob not spawned; coords maybe wrong?" -- mob could not be spawned. this may happen if the coords are wrong

  • Love 1
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.