Jump to content

Quest Functions - NPC & Item - From imerLib Game


Recommended Posts

M2 Download Center

This is the hidden content, please
( 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

 

  • Metin2 Dev 2
  • Good 1
  • Love 9

Plain logic saves lives.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Announcements



  • Similar Content

  • Similar Content

  • Similar Content

  • Tags

  • Activity

    1. 3

      Crystal Metinstone

    2. 3

      Feeding game source to LLM

    3. 113

      Ulthar SF V2 (TMP4 Base)

    4. 3

      Feeding game source to LLM

    5. 0

      Target Information System

    6. 3

      Feeding game source to LLM

    7. 2

      anti exp explanation pls

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • 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.