TheMadNurse 0 Posted February 23, 2018 Share Posted February 23, 2018 Hello! I need a function to use for: when vnum_NPC.take with item.get_vnum() == vnum_item begin that makes as short as possible the when-begin clause, because I need to include a lot of item values for the item.get_vnum() function. The function has to return a group of items divided into various arrays (e.g.: local name_item_group_1 = {vnum_item_1, 2 , 3, etc...}) for the various sub types of items (e.g.: swords, daggers, bows, etc...). The result has to look like that: when vnum_NPC.take with new_function() begin and not when vnum_NPC.take with item.get_vnum() == vnum_item_1 or item.get_vnum() == vnum_item_2 or item.get_vnum() == vnum_item_3 or etc... begin Thank you in advance! Link to comment Share on other sites More sharing options...
Premium WeedHex 636 Posted February 24, 2018 Premium Share Posted February 24, 2018 function right_item() local value_x = item.get_vnum() if value_x >= 85001 and value_x <= 85024 then return true else return false end end if questname.right_item() == true then Link to comment Share on other sites More sharing options...
Tasho 244 Posted February 24, 2018 Share Posted February 24, 2018 32 minutes ago, WeedHex said: function right_item() local value_x = item.get_vnum() if value_x >= 85001 and value_x <= 85024 then return true else return false end end if questname.right_item() == true then Stop to kill Lua please. function right_item() return item.get_vnum() >= 85001 and item.get_vnum() <= 85024 end And don't reply if you don't understand what exactly he want. 3 hours ago, TheMadNurse said: that makes as short as possible the when-begin clause, because I need to include a lot of item values for the item.get_vnum() function. The function has to return a group of items divided into various arrays (e.g.: local name_item_group_1 = {vnum_item_1, 2 , 3, etc...}) for the various sub types of items (e.g.: swords, daggers, bows, etc...). The result has to look like that: function CanTakeItem(itemVnum) local table_items = { 14500, 12000, 18000 } for _, v in pairs(table_items) do if v == itemVnum then return true end end return false end -- when npc_id.take with questName.CanTakeItem(item.get_vnum()) begin 1 Link to comment Share on other sites More sharing options...
Premium Solution Syreldar 1886 Posted February 24, 2018 Premium Solution Share Posted February 24, 2018 34 minutes ago, Tasho said: if v == itemVnum then return true end It's good practice to use understandable variable names. quest QUESTNAME begin state start begin function CanTakeItem(vnum) local accepted_items = {14500, 12000, 18000}; return table_is_in(accepted_items, vnum); end -- function when NPCVNUM.take with QUESTNAME.CanTakeItem(item.get_vnum()) begin -- end -- when end -- state end -- quest table_is_in is a function which already exists in every questlib.lua. This is the hidden content, please Sign In or Sign Up Yours does the same thing, but custom-made functions are meant to be readable. 5 1 4 "Nothing's free in this life. Ignorant people have an obligation to make up for their ignorance by paying those who help them. Either you got the brains or cash, if you lack both you're useless." Syreldar Link to comment Share on other sites More sharing options...
TheMadNurse 0 Posted February 24, 2018 Author Share Posted February 24, 2018 10 hours ago, Syreldar said: It's good practice to use understandable variable names. quest QUESTNAME begin state start begin function CanTakeItem(vnum) local accepted_items = {14500, 12000, 18000}; return table_is_in(accepted_items, vnum); end -- function when NPCVNUM.take with QUESTNAME.CanTakeItem(item.get_vnum()) begin -- end -- when end -- state end -- quest table_is_in is a function which already exists in every questlib.lua. This is the hidden content, please Sign In or Sign Up Yours does the same thing, but custom-made functions are meant to be readable. Thank you! Your reply suits my request, but I need a way to manage different tables in order to make the function data sheet as clear as possible, like this way: function CanTakeItem(vnum_item) local table_1 = {x1, x2, x3} local table_2 = {y1, y2, y3} return table_is_in(table_1, vnum_item) return table_is_in(table_2, vnum_item) end But it obviously is wrong. I don't need range of values, but specified values. Is the multiple "for index = 1, table.getn(table) do" for each table choice the only option ? Like this way: function CanTakeItem(vnum_item) local table_1 = {x1, x2, x3} for index_1 = 1, table.getn(table_1) do if vnum_item == table_1[index_1] then return true else return false end end local table_2 = {y1, y2, y3} for index_2 = 1, table.getn(table_2) do if vnum_item == table_2[index_2] then return true else return false end end end when vnum_NPC.take with name_quest.CanTakeItem(item.get_vnum()) == true begin Thank you in advance again! Link to comment Share on other sites More sharing options...
Premium Syreldar 1886 Posted February 24, 2018 Premium Share Posted February 24, 2018 4 hours ago, TheMadNurse said: Thank you! Your reply suits my request, but I need a way to manage different tables in order to make the function data sheet as clear as possible, like this way: function CanTakeItem(vnum_item) local table_1 = {x1, x2, x3} local table_2 = {y1, y2, y3} return table_is_in(table_1, vnum_item) return table_is_in(table_2, vnum_item) end The hell are you doing? Just insert more values to the table, you don't need to make 2 tables..and that's not a range what the hell XD quest QUESTNAME begin state start begin function CanTakeItem(vnum) local accepted_items = {14500, 12000, 18000, 1000, 2000, 7500, 9000, 18329}; return table_is_in(accepted_items, vnum); end -- function when NPCVNUM.take with QUESTNAME.CanTakeItem(item.get_vnum()) begin -- end -- when end -- state end -- quest You can add as many as you want, just stop killing the code holy.. "Nothing's free in this life. Ignorant people have an obligation to make up for their ignorance by paying those who help them. Either you got the brains or cash, if you lack both you're useless." Syreldar Link to comment Share on other sites More sharing options...
Premium WeedHex 636 Posted February 24, 2018 Premium Share Posted February 24, 2018 They say "kill script" because they know what're saying. But TheMadNurse dont worry also them kill to many codes it's sure... Link to comment Share on other sites More sharing options...
TheMadNurse 0 Posted February 26, 2018 Author Share Posted February 26, 2018 I simply asked something more than what Syreldar showed me, storing values in more than one table, because I need to include a lot of values, just to have the data as clear as possible. It's not a problem if anyone from you can't afford that last my request, your support was enought helpful for me anyway. I'll follow Syreldar's function like this way: local table = { x1, x2, x3, ---table_1 y1, y2, y3 ---table_2 z1, z2, z3 ---table_3 etc... } Tne two-return in the function I posted was simply an example to show you what I meant, I wrote that it was obviously wrong, and the "range of values" was referred to the other users who replied to me with that solution, including range of values (e.g.: item.get_vnum() >= x1 and item.get_vnum() <= x2). Don't worry, I know how to lua code just as you all do, I could not be expert as you, but I developed a lot of usefull systems and I know what I'm doing too. By the way, thank you all again, expecially to Syreldar. Link to comment Share on other sites More sharing options...
Bot Metin2 Dev 4929 Posted February 26, 2018 Bot Share Posted February 26, 2018 Is the same possible with the use event? Alias: when use with GetItemVnum(item.get_vnum()) begin [...] King Regards Cyber Link to comment Share on other sites More sharing options...
Premium Syreldar 1886 Posted February 26, 2018 Premium Share Posted February 26, 2018 2 hours ago, Cyber36 said: Is the same possible with the use event? Alias: when use with GetItemVnum(item.get_vnum()) begin [...] King Regards Cyber No it's not, unfortunately. 6 hours ago, TheMadNurse said: I simply asked something more than what Syreldar showed me, storing values in more than one table, because I need to include a lot of values, just to have the data as clear as possible. It's not a problem if anyone from you can't afford that last my request, your support was enought helpful for me anyway. I'll follow Syreldar's function like this way: local table = { x1, x2, x3, ---table_1 y1, y2, y3 ---table_2 z1, z2, z3 ---table_3 etc... } Tne two-return in the function I posted was simply an example to show you what I meant, I wrote that it was obviously wrong, and the "range of values" was referred to the other users who replied to me with that solution, including range of values (e.g.: item.get_vnum() >= x1 and item.get_vnum() <= x2). Don't worry, I know how to lua code just as you all do, I could not be expert as you, but I developed a lot of usefull systems and I know what I'm doing too. By the way, thank you all again, expecially to Syreldar. function GetItemTables(index) local tables = { [1] = {1, 101, 29838, 134}, [2] = {94729, 4398292, 3928, 12}, [3] = {298, 4325, 34289, 438} }; return tables[index]; end -- function function DoesIndexContainItem(index, vnum) return table_is_in(QUESTNAME.GetItemTables(index), vnum); end -- function when NPCVNUM.take with QUESTNAME.DoesIndexContainItem(1|2|3, item.get_vnum()) begin --- end -- when "Nothing's free in this life. Ignorant people have an obligation to make up for their ignorance by paying those who help them. Either you got the brains or cash, if you lack both you're useless." Syreldar Link to comment Share on other sites More sharing options...
Forum Moderator Raylee 658 Posted February 28, 2018 Forum Moderator Share Posted February 28, 2018 #Topic closed Request solved. Best regards Raylee Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now