Jump to content

Beginner Quest - How To Use Table


Recommended Posts

  • Premium

Hallo all

In The Fitst This Is A Beginner Tut smile.gif

in this tut we going to use

  • table insted of if elseif else
  • ipairs insted of table.getn ( Thanks To Marty <3 )

In What This Will help ? I am Seening To many pepole who want make quest and it's have too many if + elseif and they dont know when they put else or when they put end

in the end u have atleast 20 elseif and quest maybe 300 line

so i will show u how to write it in maybe 20 line and easy to understnad also easy to add new item to it

i will take a e.g for a item trade ( player give items for npc and he take a new item )

e.g For Quest

quest table_test begin
        state start begin
            when xxx.click begin
            say("chose what u want to give")
            local data01 = {
                -- Name        vnum    count        give_vnum        count
                {"Enargy", 51001, 200, 71159, 1},
                {"Drink", 71054, 1, 71160, 1},
            }
            local menu01 = {}
            for num1,str1 in ipairs(data01) do
                table.insert(menu01, str1[1])
            end
            local seltab01 = select_table(menu01, " Close ")
            local count_check = pc.count_item(data01[seltab01][2])
            if seltab01 == table.getn(menu01) then return end
            say(" Are u Sure U want Give ".. data01[seltab01][1] .." To Get "..item_name(data01[seltab01][4]).." ")
            if select("Yes Sure","No I Dont Want It") == 2 then return end
            if count_check < 1 then syschat("Not possess the required number") return end
            say_reward("You Get : "..item_name(data01[seltab01][3]+1).."")
            pc.removeitem(data01[seltab01][2],data01[seltab01][3])
            pc.give_item2(data01[seltab01][4], data01[seltab01][5])
        end -- when
    end -- state
end -- quest
            


Let's Start smile.gif

local data01 = {
Thos for Start The Table Items

{"Enargy", 51001, 200, 71159, 1},
Name        vnum    count        give_vnum        count

if u want add Other Item Just Add New Line
{"Name", vnum, count, give_vnum, count},


Now To The Part That It's Show The Items in game:

            local menu01 = {}
            for num1,str1 in ipairs(data01) do
                table.insert(menu01, str1[1])
            end

Here As U Can See We Make New  Local And It's empty and we give him name menu01

then

for num1,str1 in ipairs(data01) do < we here load the first tab from the data01

table.insert(menu01, str1[1])
we here insert the first tab from data01 to the menu01


and now the part from quest to show tab for the player :
local seltab01 = select_table(menu01, " Close ")


the check count for the selected item
local count_check = pc.count_item(data01[seltab01][2])

pc.count_item = count function
data01 = the table
seltab01 = the selected item tab
[2] = second tab from the selected item ( the item vnum tab )


and i think
The rest code is clear smile.gif

sry for my bed Engish

I Hope This Help Some Pepole biggrin.gif



  Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 3

If you're going to do something, then do it right.

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.