sangpronhat
22-06-09, 02:19 PM
Sau đây là Code
Thằng này là thằng nguyệt lão nhá :
DANH_SACH_KET_HON={}
Include("\\script\\ket_hon\\danh_sach_marrie.lua")
strMain = {
"<bclr=red>Nguyet Lao<bclr> : Ta la nguoi chuyen lam nghe may moi, nguoi muon ta giup gi ?",
"Ta muon ket hon/kethonok",
"Ta muon ly hon/kethondel",
"Ket thuc doi thoai/out"
}
function main()
strSay = strMain[1].."\n<bclr=water>Ten chong<bclr> <bclr=pink>Ten Vo<bclr>\n"
for i=1,getn(DANH_SACH_KET_HON) do
strSay = strSay..DANH_SACH_KET_HON[i][1].." "..DANH_SACH_KET_HON[i][2].."\n"
end
if KETHON(GetName()) == 1 then
Say(strSay,2,strMain[3],strMain[4])
else
Say(strSay,2,strMain[2],strMain[4])
end
end
function kethonok()
team=GetTeam()
size=GetTeamSize()
if team==nil then
Say("<bclr=red>Nguyet Lao<bclr> : Nguoi phai lap to doi 2 nguoi la nam va nu thi moi ket hon duoc !",0)
elseif team~=nil and size ~= 2 then
Say("<bclr=red>Nguyet Lao<bclr> : Nguoi phai lap to doi 2 nguoi thi moi ket hon duoc ! doi ban chi co"..size,0)
elseif team~=nil and size==2 and IsCaptain()~=1 then
Say("<bclr=red>Nguyet Lao<bclr> : Chi co chu nhom moi den dang ky duoc !",0)
elseif team~=nil and size==2 and IsCaptain()==1 then
Say("<bclr=red>Nguyet Lao<bclr> : Nguoi da du dieu kien de ket hon roi nguoi co muon ket hon khong ?",2,"Tat nhien muon/ok","Ta chua chuan bi tam ly/out")
end
end
function ok()
team=GetTeam()
sex=GetSex()
name=GetName()
if TIMKIEM(GetName()) == 1 then
Say("Nguoi dung la khong chung thuy ma ta se mach cho "..VOLA(GetName()).." do",0)
return
end
if GetSex() == 0 then
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == team and GetName() ~= name then
if GetSex() == 1 then
DANH_SACH_KET_HON[getn(DANH_SACH_KET_HON)+1] = {name,GetName()} --chong--vo--
danhsachkethon = TaoBang(DANH_SACH_KET_HON,"DANH_SACH_KET_HON","")
SaveData("script/ket_hon/danh_sach_marrie.lua",danhsachkethon)
Msg2SubWorld("Chuc mung ! 1 cap vo chong vua ket hon la "..name.." va "..GetName().." !")
break
else
Msg2Team("Hai nguoi muon tro thanh nguoi dong tinh u >''<")
end
end
end
else
Say("Nguoi la con gai chuyen dai su nay phai de cho nam gioi lam chu ! dung trach ta co hu nhe !",0)
end
end
function kethondel()
if KETHON(GetName()) == 1 then
for i=1,getn(DANH_SACH_KET_HON) do
if DANH_SACH_KET_HON[i][1] or DANH_SACH_KET_HON[i][2] == GetName() then
Msg2SubWorld("Cap vo chong vua ly hon la :"..DANH_SACH_KET_HON[i][1].." :"..DANH_SACH_KET_HON[i][2])
DANH_SACH_KET_HON[i] = nil
danhsachkethon = TaoBang(DANH_SACH_KET_HON,"DANH_SACH_KET_HON","")
SaveData("script/ket_hon/danh_sach_marrie.lua",danhsachkethon)
end
end
else
Say("Nguoi van chua ket hon ly hon voi ai the !",0)
end
end
function TIMKIEM(string)
for i=1,getn(DANH_SACH_KET_HON) do
for k=1,getn(DANH_SACH_KET_HON[i]) do
if DANH_SACH_KET_HON[i][k] == string then
return 1
end
end
end
end
function KETHON(name)
if getn(DANH_SACH_KET_HON) == 0 then
return 0
end
for i=1,getn(DANH_SACH_KET_HON) do
if DANH_SACH_KET_HON[i][1] == name or DANH_SACH_KET_HON[i][2] == name then
return 1
end
end
end
function VOLA(husband)
if husband == nil then
return 0
end
for i=1,getn(DANH_SACH_KET_HON) do
if DANH_SACH_KET_HON[i][1] == husband then
return DANH_SACH_KET_HON[i][2]
end
end
end
function TaoBang(tTable, sTableName, sTab) --include cua manh tuyen
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.."={"
local tStart = 0
for key, value in tTable do
if tStart == 1 then
sTmp = sTmp..",\r\n"
else
sTmp = sTmp.."\r\n"
tStart = 1
end
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..TaoBang(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
end
sTmp = sTmp.."\r\n"..sTab.."}"
return sTmp
end
function SaveData(file, string) ---Tuy ngan nhung wan trong nhat >''<
file_op = openfile( file, "w+" ) --- a+ la vit them hem xoa file dau -- w+ -- la che do doc ghi xoa file dau
write(file_op,string)
closefile(file_op)
end
function out()
end
file này là file danh_sach_marrie.lua
DANH_SACH_KET_HON={}copy vào đậu thì nhìn đường dẫn include
Pác Mạnh Tuyên có xem bài này thì giải thích cho ae nghe quá trình làm việc của hàm TaoBang(table,tablename,tab) nhá tui chỉ lấy cái đó xài thôi còn
nó làm việc sao thì không hiểu nữa
Thanks mạnh tuyên trước !
Thằng này là thằng nguyệt lão nhá :
DANH_SACH_KET_HON={}
Include("\\script\\ket_hon\\danh_sach_marrie.lua")
strMain = {
"<bclr=red>Nguyet Lao<bclr> : Ta la nguoi chuyen lam nghe may moi, nguoi muon ta giup gi ?",
"Ta muon ket hon/kethonok",
"Ta muon ly hon/kethondel",
"Ket thuc doi thoai/out"
}
function main()
strSay = strMain[1].."\n<bclr=water>Ten chong<bclr> <bclr=pink>Ten Vo<bclr>\n"
for i=1,getn(DANH_SACH_KET_HON) do
strSay = strSay..DANH_SACH_KET_HON[i][1].." "..DANH_SACH_KET_HON[i][2].."\n"
end
if KETHON(GetName()) == 1 then
Say(strSay,2,strMain[3],strMain[4])
else
Say(strSay,2,strMain[2],strMain[4])
end
end
function kethonok()
team=GetTeam()
size=GetTeamSize()
if team==nil then
Say("<bclr=red>Nguyet Lao<bclr> : Nguoi phai lap to doi 2 nguoi la nam va nu thi moi ket hon duoc !",0)
elseif team~=nil and size ~= 2 then
Say("<bclr=red>Nguyet Lao<bclr> : Nguoi phai lap to doi 2 nguoi thi moi ket hon duoc ! doi ban chi co"..size,0)
elseif team~=nil and size==2 and IsCaptain()~=1 then
Say("<bclr=red>Nguyet Lao<bclr> : Chi co chu nhom moi den dang ky duoc !",0)
elseif team~=nil and size==2 and IsCaptain()==1 then
Say("<bclr=red>Nguyet Lao<bclr> : Nguoi da du dieu kien de ket hon roi nguoi co muon ket hon khong ?",2,"Tat nhien muon/ok","Ta chua chuan bi tam ly/out")
end
end
function ok()
team=GetTeam()
sex=GetSex()
name=GetName()
if TIMKIEM(GetName()) == 1 then
Say("Nguoi dung la khong chung thuy ma ta se mach cho "..VOLA(GetName()).." do",0)
return
end
if GetSex() == 0 then
for i=1,GetPlayerCount() do
PlayerIndex = i
if GetTeam() == team and GetName() ~= name then
if GetSex() == 1 then
DANH_SACH_KET_HON[getn(DANH_SACH_KET_HON)+1] = {name,GetName()} --chong--vo--
danhsachkethon = TaoBang(DANH_SACH_KET_HON,"DANH_SACH_KET_HON","")
SaveData("script/ket_hon/danh_sach_marrie.lua",danhsachkethon)
Msg2SubWorld("Chuc mung ! 1 cap vo chong vua ket hon la "..name.." va "..GetName().." !")
break
else
Msg2Team("Hai nguoi muon tro thanh nguoi dong tinh u >''<")
end
end
end
else
Say("Nguoi la con gai chuyen dai su nay phai de cho nam gioi lam chu ! dung trach ta co hu nhe !",0)
end
end
function kethondel()
if KETHON(GetName()) == 1 then
for i=1,getn(DANH_SACH_KET_HON) do
if DANH_SACH_KET_HON[i][1] or DANH_SACH_KET_HON[i][2] == GetName() then
Msg2SubWorld("Cap vo chong vua ly hon la :"..DANH_SACH_KET_HON[i][1].." :"..DANH_SACH_KET_HON[i][2])
DANH_SACH_KET_HON[i] = nil
danhsachkethon = TaoBang(DANH_SACH_KET_HON,"DANH_SACH_KET_HON","")
SaveData("script/ket_hon/danh_sach_marrie.lua",danhsachkethon)
end
end
else
Say("Nguoi van chua ket hon ly hon voi ai the !",0)
end
end
function TIMKIEM(string)
for i=1,getn(DANH_SACH_KET_HON) do
for k=1,getn(DANH_SACH_KET_HON[i]) do
if DANH_SACH_KET_HON[i][k] == string then
return 1
end
end
end
end
function KETHON(name)
if getn(DANH_SACH_KET_HON) == 0 then
return 0
end
for i=1,getn(DANH_SACH_KET_HON) do
if DANH_SACH_KET_HON[i][1] == name or DANH_SACH_KET_HON[i][2] == name then
return 1
end
end
end
function VOLA(husband)
if husband == nil then
return 0
end
for i=1,getn(DANH_SACH_KET_HON) do
if DANH_SACH_KET_HON[i][1] == husband then
return DANH_SACH_KET_HON[i][2]
end
end
end
function TaoBang(tTable, sTableName, sTab) --include cua manh tuyen
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.."={"
local tStart = 0
for key, value in tTable do
if tStart == 1 then
sTmp = sTmp..",\r\n"
else
sTmp = sTmp.."\r\n"
tStart = 1
end
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..TaoBang(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
end
sTmp = sTmp.."\r\n"..sTab.."}"
return sTmp
end
function SaveData(file, string) ---Tuy ngan nhung wan trong nhat >''<
file_op = openfile( file, "w+" ) --- a+ la vit them hem xoa file dau -- w+ -- la che do doc ghi xoa file dau
write(file_op,string)
closefile(file_op)
end
function out()
end
file này là file danh_sach_marrie.lua
DANH_SACH_KET_HON={}copy vào đậu thì nhìn đường dẫn include
Pác Mạnh Tuyên có xem bài này thì giải thích cho ae nghe quá trình làm việc của hàm TaoBang(table,tablename,tab) nhá tui chỉ lấy cái đó xài thôi còn
nó làm việc sao thì không hiểu nữa
Thanks mạnh tuyên trước !