Jump to content

[Questlib] Table index rework and extended


Recommended Posts

  • Active Member

Hello

 

I have reworked the get function calls without parameters.

I mean when you use pc.empire instead of pc.get_empire()

This time I have extended to more features and added the quest features.

 

Tested in Marty Sama.

 

Explanation:

To add more functions you must know which ones.
Functions must return a value and must not receive any parameters.
pc.get_empire() is very simple, it returns a number and no parameter is sent. Its "alias" would be pc.empire or whatever name best suits it.
item.get_value() does not work. Its alias would be item.value but the server will not know which value it refers to, since it needs to specify the index of that value. This structure does not work if the function requires parameters.

When you need to use q.getcurrentquestindex(), you just put q.index. Now it's simpler.

 

 

Steps:

questlib.lua. Remove this code:

Remove:

npc_index_table = {
    ['race'] = npc.getrace,
    ['empire'] = npc.get_empire,
}

pc_index_table = {
    ['weapon']		= pc.getweapon,
    ['level']		= pc.get_level,
    ['hp']		= pc.gethp,
    ['maxhp']		= pc.getmaxhp,
    ['sp']		= pc.getsp,
    ['maxsp']		= pc.getmaxsp,
    ['exp']		= pc.get_exp,
    ['nextexp']		= pc.get_next_exp,
    ['job']		= pc.get_job,
    ['money']		= pc.getmoney,
    ['gold'] 		= pc.getmoney,
    ['name'] 		= pc.getname,
    ['playtime'] 	= pc.getplaytime,
    ['leadership'] 	= pc.getleadership,
    ['empire'] 		= pc.getempire,
    ['skillgroup'] 	= pc.get_skill_group,
    ['x'] 		= pc.getx,
    ['y'] 		= pc.gety,
    ['local_x'] 	= pc.get_local_x,
    ['local_y'] 	= pc.get_local_y,
}

item_index_table = {
    ['vnum']		= item.get_vnum,
    ['name']		= item.get_name,
    ['size']		= item.get_size,
    ['count']		= item.get_count,
    ['type']		= item.get_type,
    ['sub_type']	= item.get_sub_type,
    ['refine_vnum']	= item.get_refine_vnum,
    ['level']		= item.get_level,
}

function npc_index(t,i)
    local npit = npc_index_table
    if npit[i] then
    return npit[i]()
    else
    return rawget(t,i)
    end
end

function pc_index(t,i)
    local pit = pc_index_table
    if pit[i] then
    return pit[i]()
    else
    return rawget(t,i)
    end
end

function item_index(t, i)
    local iit = item_index_table
    if iit[i] then
    return iit[i]()
    else
    return rawget(t, i)
    end
end

setmetatable(pc,{__index=pc_index})
setmetatable(npc,{__index=npc_index})
setmetatable(item,{__index=item_index})


Add this code:
 

index_tables = {
	pc = {
		['weapon']		= pc.getweapon,
		['level']		= pc.get_level,
		['hp']			= pc.gethp,
		['maxhp']		= pc.getmaxhp,
		['sp']			= pc.getsp,
		['maxsp']		= pc.getmaxsp,
		['exp']			= pc.get_exp,
		['nextexp']		= pc.get_next_exp,
		['job']			= pc.get_job,
		['money']		= pc.getmoney,
		['gold'] 		= pc.getmoney,
		['name'] 		= pc.getname,
		['playtime'] 	= pc.getplaytime,
		['leadership'] 	= pc.getleadership,
		['empire'] 		= pc.getempire,
		['skillgroup'] 	= pc.get_skill_group,
		['x'] 			= pc.getx,
		['y'] 			= pc.gety,
		['local_x'] 	= pc.get_local_x,
		['local_y'] 	= pc.get_local_y,
		['mapindex'] 	= pc.get_map_index,
		['guild'] 		= pc.get_guild,
		['sex'] 		= pc.get_sex,
		['gmlevel'] 	= pc.get_gm_level,
		['ip'] 			= pc.get_ip0,
		['hwid'] 		= pc.get_hwid,
	},
	npc = {
		['race']		= npc.getrace,
		['empire']		= npc.get_empire,
		['vid']			= npc.get_vid,
		['level']		= npc.get_level0,
		['name']		= npc.get_name0,
		['pid']			= npc.get_pid0,
		['type']		= npc.get_type0,
		['hwid']		= npc.get_hwid,
	},
	item = {
		['id']			= item.get_id,
		['cell']		= item.get_cell,
		['vnum']		= item.get_vnum,
		['name']		= item.get_name,
		['size']		= item.get_size,
		['count']		= item.get_count,
		['type']		= item.get_type,
		['sub_type']	= item.get_sub_type,
		['refine_vnum']	= item.get_refine_vnum,
		['level']		= item.get_level,
		['levellimit']	= item.get_level_limit,
		['wearflag']	= item.get_wearflag0,
		['antiflag']	= item.get_antiflag0,
		['immuneflag']	= item.get_immuneflag0,
	},
	q = {
		['index']		= q.getcurrentquestindex,
		['name']		= q.getcurrentquestname,
	}
	--add your new space
}

function generic_index(t, i)
	local it = index_tables[t]
	return it[i] and it[i]() or rawget(t, i)
end

setmetatable(pc, { __index = function(t, i) return generic_index("pc", i) end })
setmetatable(npc, { __index = function(t, i) return generic_index("npc", i) end })
setmetatable(item, { __index = function(t, i) return generic_index("item", i) end })
setmetatable(q, { __index = function(t, i) return generic_index("q", i) end }) --quest
--add your new space

 

  • Metin2 Dev 1
Link to comment
Share on other sites

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.