In The Fitst This Is A Beginner Tut
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
Code:
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
Code:
[B] [/B]
Let's Start
Code:
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},
Code:
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
Code:
[B]for num1,str1 in ipairs(data01) do[/B][B] < 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 [/B]
and now the part from quest to show tab for the player :
Code:
local seltab01 = select_table(menu01, " Close ")
Code:
local count_check = pc.count_item(data01[seltab01][2])
Code:
[B][B]pc.count_item = count function[/B][/B] [B][B][B]data01 = the table[/B][/B][/B] [B][B][B][B]seltab01 = the [/B][/B][/B][/B][B][B][B][B][B]selected item tab[/B][/B][/B][/B][/B] [B][B][B][B][B][2] = second tab from the selected item ( the item vnum tab ) [/B][/B][/B][/B][/B]
and i think The rest code is clear
sry for my bed Engish
I Hope This Help Some Pepole







