Jump to content
×
×
  • Create New...

Quest Functions - NPC & Item - From imerLib Game


Recommended Posts

  • Moon

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

 

  • Love 6
  • Good 1

Plain logic saves lives.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


  • Activity

    1. 36

      Destroy Item System

    2. 1

      Brillances

    3. 0

      Fusion.org is Looking for Staff Members

    4. 1

      Brillances

    5. 3

      ELONIA2 | PVM-MEDIUM | 11 LANGUAGES | INTERNATIONAL | A NEW STORY

    6. 4

      Spider Queen not spawining in spider dungeon v1

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.