Jump to content

Quest Functions - NPC & Item - From imerLib Game


Recommended Posts

M2 Download Center

Download Here ( Internal )

Hi guys. Someone still does not know how to add function in source files and if you have source files and you don't know anything about c++, This topic usefull for you :)

 

Meanwhile thanks imer for codes.

 

 

If you are ready then let's go ;)

 

First open questlua_npc.cpp after add these;

	int npc_get_pid(lua_State* L)
	{
		CQuestManager & q = CQuestManager::instance();
		LPCHARACTER npc = q.GetCurrentNPCCharacterPtr();
		lua_pushnumber(L,npc->GetPlayerID());
		return 1;
	}

	int npc_select(lua_State* L)
	{
		if(lua_isnumber(L,1))
		{
			DWORD vid = lua_tonumber(L,1);
			LPCHARACTER pc = CQuestManager::instance().GetCurrentCharacterPtr();
			LPCHARACTER ch = CHARACTER_MANAGER::instance().Find(vid);
			if(ch)
			{
				pc->SetQuestNPCID(vid);
				lua_pushnumber(L,1);
				return 1;
			}
		}
		lua_pushnumber(L,0);
		return 1;
	}

Add these ;

			{ "select",npc_select},
			{ "get_pid",npc_get_pid},

After open questlua_item.cpp add these ;

	int item_get_wearflag(lua_State* L)
	{
		LPITEM item = CQuestManager::instance().GetCurrentItem();
		if(item)
		{
			lua_pushnumber(L,item->GetProto()->dwWearFlags);
			return 1;
		}
		lua_pushnumber(L,0);
		return 1;
	}

	int item_is_wearflag(lua_State* L)
	{
		LPITEM item = CQuestManager::instance().GetCurrentItem();
		if(item)
		{
			lua_pushboolean(L,(item->GetProto()->dwWearFlags & (DWORD)lua_tonumber(L,1)));
			return 1;
		}
		lua_pushnumber(L,0);
		return 1;
	}

	int item_get_attr(lua_State* L)
	{
		LPITEM item = CQuestManager::instance().GetCurrentItem();
		
		if(!lua_isnumber(L,1) || !item)
		{
			return 0;
		}

		int attr_index = lua_tonumber(L,1);
		
		if(attr_index < 0 || attr_index > 6)
		{
			return 0;
		}

		TPlayerItemAttribute attr = item->GetAttribute(attr_index);
		lua_pushnumber(L,attr.bType);
		lua_pushnumber(L,attr.sValue);
		return 2;
	}

	int item_set_attr(lua_State* L)
	{
		LPITEM item = CQuestManager::instance().GetCurrentItem();
		
		if(!lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !item)
		{
			lua_pushboolean(L,false);
			return 1;
		}

		int attr_index = lua_tonumber(L,1);

		if(attr_index < 0 || attr_index > 6)
		{
			lua_pushboolean(L,false);
			return 1;
		}

		item->SetForceAttribute(attr_index,lua_tonumber(L,2),lua_tonumber(L,3));
		lua_pushboolean(L,true);
		return 1;
	}

	int item_equip(lua_State* L)
	{
		LPITEM item = CQuestManager::instance().GetCurrentItem();
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

		if(!lua_isnumber(L,1) || !item || !ch)
		{
			lua_pushboolean(L,false);
			return 1;
		}

		int equipcell = lua_tonumber(L,1);
		
		LPITEM wear = ch->GetWear(equipcell);

		if(wear)
		{
			ch->UnequipItem(wear);
		}
		item->EquipTo(ch,equipcell);
		lua_pushboolean(L,true);
		return 1;
	}

Add these ;

			{ "get_wearflag", item_get_wearflag},
			{ "is_wearflag", item_is_wearflag},
			{ "get_attr", item_get_attr},
			{ "set_attr", item_set_attr},
			{ "equip", item_equip},

How to use these function in my quest? 

quest examples begin
	state start begin
		when 20354.take begin
			say(item.get_wearflag())
		end
		when 20354.take begin
			local type,value = item.get_attr(1)
			say("Type : "..type)
			say("Value : "..value)
		end
		when 20354.take begin
			item.set_attr(1,2,2000)
		end
		when kill with npc.is_pc() begin
			setskin(NOWINDOW)
			chat(npc.get_pid())
		end
		when kill with npc.is_pc() begin
			local a = npc.select(npc.get_vid())
			chat(pc.get_name())
			npc.select(a)
		end
	end
end

Kind Regards

HaveBeen

 

  • Love 6

Plain logic saves lives.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



Shoutbox

Shoutbox

Chatroom Rules

 

Join our Discord

A request for help = Shoutbox Ban

Be respectful & Respect the rules

 

×
×
  • 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.