raymondle
20-09-12, 12:48 AM
Do script này mình dev cho PTTK, nay toàn bộ script bị share nên thôi share nốt luôn
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Script cong don dev by Raymond Le
-- Ban quyen thuoc ve duy nhat PTTK.VN
-------------------------------------------------------------------------------------------------------------------------
function LoadDuLieu()
local exp_table = openfile("Settings/Player/level_exp.txt","r");
exp_data = read(exp_table,"*all")
local split_tab = split(exp_data,"\n")
exp_sl = getn(split_tab) - 1
level_exp = {}
level_exp_chinh = {}
for i=2,exp_sl do
level_exp=split(split_tab[i],"\t")
level_exp_chinh[i]=level_exp[2]
end;
closefile(exp_table)
return level_exp_chinh
end;
function AddExpDon(advance_exp)
--------------------------------------------
exp_hientai = GetExp() -- Diem exp hien dang user dang co
exp_lvl = {}
exp_lvl = LoadDuLieu()
exp_lvl1 = exp_lvl[GetLevel() + 1] -- lay exp trong table cua cap do do'
---Bien tam --------------------------------
exp_du = 0 -- EXP du de len cap
exp_thua = 0 -- EXP thua de cong don
--------------------------------------------
if (advance_exp <= (exp_lvl1 - exp_hientai)) then -- Thuc hien khi EXP hien tai lon hon EXP can them
ThemEXP(advance_exp)
else
--------------------------------------------
i = 1
exp_temp = 0
exp_temp2 = 0
exp_temp3 = 0
exp_temp4 = 0
--------------------------------------------
while (tonumber(exp_lvl[GetLevel() + i]) <= advance_exp) do
if exp_temp == 0 then
exp_temp = exp_lvl1 - exp_hientai -- Lay exp du de len cap tiep theo
exp_temp3 = exp_temp -- Set Temp cho exp exp du de len cap tiep theo
end
exp_temp = exp_temp + exp_lvl[GetLevel() + i + 1] -- EXP exp du de len cap tiep theo + EXP cap tiep theo
if exp_temp <= advance_exp then -- Neu exp temp nho? hon EXP muon them thi len 1 cap nua
i = i + 1
else
exp_temp2 = exp_temp - exp_lvl[GetLevel() + i + 1] -- Tra ve exp truoc neu exp lon hon exp can them
break
end
end
--------------------------------------------
if i > 1 then
for a=1,i do AddOwnExp(9999999999999) end
--------------------------------------------
exp_temp4 = advance_exp - exp_temp2
--------------------------------------------
AddOwnExp(exp_temp4)
--------------------------------------------
else
chuyentiep = 0
while (chuyentiep == 0) do
exp_du = exp_lvl1 - GetExp()
AddOwnExp(exp_du) -- Add EXP Du de len cap
exp_thua = advance_exp - exp_du
chuyentiep = 1
end;
AddOwnExp(exp_thua) -- Add EXP thua\ lai.
---------------------------------------
end;
Msg2Player("B¹n nhËn ®îc "..advance_exp.." ®iÓm kinh nghiÖm!")
end;
end;
function ThemEXP(exp)
AddOwnExp(exp)
Msg2Player("B¹n nhËn ®îc "..exp.." ®iÓm kinh nghiÖm!")
end
Chú ý script chỉ chạy nếu server của bạn có hỗ trợ hàm split của Lua. Dùng hàm AddExpDon(exp)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Script cong don dev by Raymond Le
-- Ban quyen thuoc ve duy nhat PTTK.VN
-------------------------------------------------------------------------------------------------------------------------
function LoadDuLieu()
local exp_table = openfile("Settings/Player/level_exp.txt","r");
exp_data = read(exp_table,"*all")
local split_tab = split(exp_data,"\n")
exp_sl = getn(split_tab) - 1
level_exp = {}
level_exp_chinh = {}
for i=2,exp_sl do
level_exp=split(split_tab[i],"\t")
level_exp_chinh[i]=level_exp[2]
end;
closefile(exp_table)
return level_exp_chinh
end;
function AddExpDon(advance_exp)
--------------------------------------------
exp_hientai = GetExp() -- Diem exp hien dang user dang co
exp_lvl = {}
exp_lvl = LoadDuLieu()
exp_lvl1 = exp_lvl[GetLevel() + 1] -- lay exp trong table cua cap do do'
---Bien tam --------------------------------
exp_du = 0 -- EXP du de len cap
exp_thua = 0 -- EXP thua de cong don
--------------------------------------------
if (advance_exp <= (exp_lvl1 - exp_hientai)) then -- Thuc hien khi EXP hien tai lon hon EXP can them
ThemEXP(advance_exp)
else
--------------------------------------------
i = 1
exp_temp = 0
exp_temp2 = 0
exp_temp3 = 0
exp_temp4 = 0
--------------------------------------------
while (tonumber(exp_lvl[GetLevel() + i]) <= advance_exp) do
if exp_temp == 0 then
exp_temp = exp_lvl1 - exp_hientai -- Lay exp du de len cap tiep theo
exp_temp3 = exp_temp -- Set Temp cho exp exp du de len cap tiep theo
end
exp_temp = exp_temp + exp_lvl[GetLevel() + i + 1] -- EXP exp du de len cap tiep theo + EXP cap tiep theo
if exp_temp <= advance_exp then -- Neu exp temp nho? hon EXP muon them thi len 1 cap nua
i = i + 1
else
exp_temp2 = exp_temp - exp_lvl[GetLevel() + i + 1] -- Tra ve exp truoc neu exp lon hon exp can them
break
end
end
--------------------------------------------
if i > 1 then
for a=1,i do AddOwnExp(9999999999999) end
--------------------------------------------
exp_temp4 = advance_exp - exp_temp2
--------------------------------------------
AddOwnExp(exp_temp4)
--------------------------------------------
else
chuyentiep = 0
while (chuyentiep == 0) do
exp_du = exp_lvl1 - GetExp()
AddOwnExp(exp_du) -- Add EXP Du de len cap
exp_thua = advance_exp - exp_du
chuyentiep = 1
end;
AddOwnExp(exp_thua) -- Add EXP thua\ lai.
---------------------------------------
end;
Msg2Player("B¹n nhËn ®îc "..advance_exp.." ®iÓm kinh nghiÖm!")
end;
end;
function ThemEXP(exp)
AddOwnExp(exp)
Msg2Player("B¹n nhËn ®îc "..exp.." ®iÓm kinh nghiÖm!")
end
Chú ý script chỉ chạy nếu server của bạn có hỗ trợ hàm split của Lua. Dùng hàm AddExpDon(exp)