Diễn Đàn Game - Forum Game Private | GamePrivate.Biz

Xin Chào

Diễn Đàn Game - Forum Game Private | GamePrivate.Biz

Xin Chào

    Share Script Uỷ Thác Đã Tool Lại

      New Mem
      guildop

      Tổng số bài gửi : 14

      Giới tính : Male

      Gold : 47

      Cảm Ơn : 5

      Ngày Tham Gia : 2013-11-10

      Post by guildop 10/11/13, 11:39 pm

      Trước tiên code vài dòng câu giờ tí chứ hok bài viết ngắn lắm

      Pro đừng chém tội nghiệp em nhỏ

      Ai cũng biết muốn uỷ thác thì phải xác định được thời gian bắt đầu và thời gian kết thúc rồi mới đến xác định thời gian hiện tại là thời gian đã uỷ thác. Hơi căng thẳng rùi , nhưng suy nghĩ từ từ thấy nó cũng không khó hiểu:

      Như sau:
      timebd=thời gian bắt đầu uỷ thác
      timeut= thời gian uỷ thác
      timenow=thời gian hiện tại

      sau khi có 3 biến trên công việc còn lại khá dễ dàng:
      xác định hết thời gian uỷ thác: timebd+timeut (rất dễ hiểu đúng hem)
      xác định thời gian đã uỷ thác : timenow-timebd (lấy khoảng giữa của số lớn và số bé )

      he he giờ mới là công việc khó khăn nhất là làm sao để tính toán đc thời gian đúng hem, giờ phút giây ngày tháng năm ôi nhứt cái đầu

      Cái gì cũng vậy phải đổi về cùng đơn vị thì mới tính toán đc đúng hem, nên tui chọn đơn vị ở đây sẽ là giây. Thật đáng tiếc là trong ngôn ngữ .lua có hàm time() nhưng lại ở lua 5.0 trở lên còn JX ta chỉ là bản lua 4.0 nên ko có, nhưng không sao mọi việc đều có cách giải quyết của nó, thật ra cái hàm time() đó cũng là hàm lấy giờ hệ thống thui, nó cũng đổi giờ hệ thống ra giây rùi tính

      Dài dòng rùi bắt đầu thui, trước tiên ta sẽ lập 1 cái mảng thời gian bởi vì lua hok hổ trợ ta hàm time() "lạ
      i dài dòng"
      Code:

      TimeTable={
      [10]={31,28,31,30,31,30,31,31,30,31,30,31,365},
      [11]={31,28,31,30,31,30,31,31,30,31,30,31,365},
      [12]={31,29,31,30,31,30,31,31,30,31,30,31,366} ---- Nam nhuan
      }


      Tui chỉ làm đến năm 2012 thui vì đó là năm tận thế rùi làm nhiều chi uổng. GIải thích xíu hok giải thix ai cũng biết nhưng bệnh nói nhiều ép viết @@ :
      + Mảng 1 -> 12 là 12 tháng
      + Mảng 13 là tổng số ngày trong năm

      Tiếp theo ta sẽ dựa vào mảng trên code hàm tính thời gian hiện tại :

      Code:

      function Time()
      local cyear,cmon,cday,cHour,cMin,cSec,Smon=tonumber(date ("%y")),tonumber(date("%m")),tonumber(date("%d")), tonumber(date("%H")),tonumber(date("%M")),tonumber (date("%S")),0
      for t=1,(cmon-1) do
      Smon=Smon+TimeTable[cyear][t]*86400
      end
      Smon=Smon+cday*86400
      return cyear*TimeTable[cyear-1][13]*86400+Smon+cHour*3600+cMin*60+cSec
      end

      Nhìn nó dài dòng vậy thui những ngắn tịt nhìn kĩ tí hiểu ngay (giờ khuya rùi hok dài dòng nữa ^^)
      => sau khi sử dụng là Time() trên sẽ trả lại thời gian hiện tại(đơn vị giây) được tính theo ngày tháng năm 1 cách chính xác 90%(còn 10% là qua năm 2100 hàm này sẽ sai, ai sống đến cái ngày sai này thưởng gì tui cũng thưởng )

      vd: x=Time()
      =x
      =>321561651651 --- số giây

      Tiếp theo tui sẽ hỗ trợ luôn hàm chuyển đổi giây về dạng giờ phút giây cho nó đẹp ^^
      Code:

      function MathTime(Second)
      local Hour,Min,Sec=0,0,0
      Min=floor(Second/60)
      Sec=Second-Min*60
      if Min >= 60 then
      Hour=floor(Min/60)
      Min=Min-Hour*60
      end
      return Hour,Min,Sec
      end;


      VD: x=Time()
      Hour,Min,Sec=MathTime(Time()-x)

      Dựa vào nhiêu đó ta có thể phát triển thêm cành lá, mắm muối nữa sẽ đc 1 script Uỷ thác do tự mình viết

      Ai hem muốn tự viết thì dùng cái của tui cho lẹ

      UyThac.lua
      Code:

      --################################################
      --################ Script Uy Thac ################
      --################ Author Chicken ################
      --################################################
      Include("\\script\\dulieu\\datauythac.lua")
      exp1s=1000 --- 1 giay = 1000 exp
      TaskAnti=150
      FileUT="script/dulieu/datauythac.lua"
      TimeTable={
      [10]={31,28,31,30,31,30,31,31,30,31,30,31,365},
      [11]={31,28,31,30,31,30,31,31,30,31,30,31,365},
      [12]={31,29,31,30,31,30,31,31,30,31,30,31,366}, ---- Nam nhuan
      [13]={31,28,31,30,31,30,31,31,30,31,30,31,365},
      [14]={31,28,31,30,31,30,31,31,30,31,30,31,365},
      [15]={31,28,31,30,31,30,31,31,30,31,30,31,365},
      [16]={31,29,31,30,31,30,31,31,30,31,30,31,366} ---- Nam nhuan
      }
      TabInfoItem={{"Bach Cau Hoan (Tieu)",178},{"Bach Cau Hoan (Trung)",179},{"Bach Cau Hoan (Dai)",180}}
      exp_table = {
      {1,20},{2,30},{3,40},{4,60},{5,80},{6,110},{7,150} ,{8,180},{9,240},{10,450},{11,500},{12,550},{13,60 0},{14,650},{15,700},{16,750},{17,800},{18,850},{1 9,900},{20,1500},{21,1611},{22,1722},{23,1833},{24 ,1944},{25,2055},{26,2166},{27,2277},{28,2388},{29 ,2500},{30,4125},{31,4291},{32,4458},{33,4625},{34 ,4791},{35,4958},{36,5125},{37,5291},{38,5458},{39 ,5625},{40,8992},{41,9241},{42,9491},{43,9741},{44 ,9991},{45,10240},{46,10490},{47,10740},{48,10990} ,{49,11240},{50,17703},{51,18077},{52,18452},{53,1 8827},{54,19201},{55,19576},{56,19951},{57,20325}, {58,20700},{59,21075},{60,32890},{61,33452},{62,34 014},{63,34576},{64,35138},{65,35701},{66,36263},{ 67,36825},{68,37387},{69,37950},{70,58838},{71,607 36},{72,62634},{73,64532},{74,66430},{75,68328},{7 6,70226},{77,72124},{78,74022},{79,75920},{80,1167 27},{81,119574},{82,122421},{83,125268},{84,128115 },{85,130962},{86,133809},{87,136656},{88,139503}, {89,142350},{90,230634},{91,238226},{92,245819},{9 3,253412},{94,261005},{95,268598},{96,276191},{97, 283784},{98,291377},{99,298970},{100,486932},{101, 504017},{102,521102},{103,538188},{104,555273},{10 5,572358},{106,589444},{107,606529},{108,623614},{ 109,640700},{110,704770},{111,733245},{112,761721} ,{113,790196},{114,818672},{115,847147},{116,87562 3},{117,904098},{118,932574},{119,961050},{120,159 5260},{121,1663597},{122,1731935},{123,1800273},{1 24,1868611},{125,1936948},{126,2005286},{127,20736 24},{128,2141962},{129,2210300},{130,2440940},{131 ,2543446},{132,2645953},{133,2748460},{134,2850966 },{135,2953473},{136,3055980},{137,3158486},{138,3 260993},{139,3363500},{140,3709460},{141,3863220}, {142,4016980},{143,4170740},{144,4324500},{145,447 8260},{146,4632020},{147,4785780},{148,4939540},{1 49,5093300},{150,8418944},{151,9513406},{152,10750 149},{153,12147669},{154,13726866},{155,15511358}, {156,17527835},{157,19806453},{158,22381292},{159, 25290860},{160,28578672},{161,32293900},{162,36492 107},{163,41236081},{164,46596771},{165,52654352}, {166,59499417},{167,67234342},{168,75974806},{169, 85851531},{170,97012230},{171,109623820},{172,1238 74917},{173,139978656},{174,158175881},{175,178738 746},{176,201974783},{177,228231505},{178,25790160 1},{179,291428809},{180,329314554},{181,372125446} ,{182,420501754},{183,475166982},{184,536938690},{ 185,606740720},{186,685617013},{187,774747225},{18 8,875464364},{189,989274732},{190,1117880447},{191 ,1263204906},{192,1427421543},{193,1612986344},{19 4,1822674569},{195,2059622263},{196,2100000000},{1 97,2100000000},{198,2100000000},{199,2100000000},{ 200,2100000000}
      } ---- sv tui exp nó vậy sv khác exp nó khác
      function main()
      if GetTaskTemp(20) ~= 10 then --- check admin
      Say("<color=blue>NPC Uy Thac :<color> Cac ha muon gi o ta ?",3,"Ta muon xem thoi gian uy thac/showut","Ta muon uy thac/uythac","Ta chi di ngang qua day thoi/no")
      else
      Say("<color=blue>NPC Uy Thac :<color> Cac ha muon gi o ta ?",4,"Sap xep mang/SapXepTab","Ta muon xem thoi gian uy thac/showut","Ta muon uy thac/uythac","Ta chi di ngang qua day thoi/no")
      end
      end;
      function no()
      end;
      function showut()
      local pos=FindTableUT(GetUUID())
      if pos == 0 then
      Say("<color=blue>NPC Uy Thac :<color> Cac ha chua su dung Bach cau hoan.",1,"Thoat/no")
      else
      if dsut[pos][3]>0 and dsut[pos][4]>0 then
      local Hour,Min,Sec,Moment,TimeM,HourNew,MinNew,SecNew=Ma thTime(dsut[pos][4]),0,0,0,0,0
      Moment=Time()
      TimeM=Moment-dsut[pos][3]
      if TimeM > dsut[pos][4] then
      HourNew,MinNew,SecNew=MathTime(dsut[pos][4])
      else
      HourNew,MinNew,SecNew=MathTime(TimeM)
      end
      Say("<color=blue>NPC Uy Thac :<color>Thoi gian con lai:\n <color=yellow>"..Hour.." gio "..Min.." phut "..Sec.." giay<color>\nThoi gian su dung: <color=yellow>"..HourNew.." gio "..MinNew.." phut "..SecNew.." giay<color>\nKinh nghiem hien tai: <color=yellow>"..(abs(Moment-dsut[pos][3])*exp1s).." diem<color>",2,"Nhan diem kinh nghiem uy thac/recexpUT","Thoat/no")
      else
      Say("<color=blue>NPC Uy Thac :<color>Thoi gian con lai:\n <color=yellow>Het<color>",1,"Thoat/no")
      end
      end
      end;
      function recexpUT()
      if GetTaskTemp(TaskAnti) == 0 then
      local pos,Hour,Min,Sec,timenow,time1=FindTableUT(GetUUID ()),0,0,0,Time(),0
      if pos == 0 then
      Say("<color=blue>NPC Uy Thac :<color> Cac ha chua su dung Bach cau hoan.",1,"Thoat/no")
      else
      time1=timenow-dsut[pos][3]
      if time1 <= dsut[pos][4] then
      dsut[pos][3]=timenow
      dsut[pos][4]=dsut[pos][4]-time1
      else
      dsut[pos][3]=0
      dsut[pos][4]=0
      end
      SaveDataA(FileUT,"dsut["..pos.."][3]="..dsut[pos][3].."\ndsut["..pos.."][4]="..dsut[pos][4].."\n")
      SetTaskTemp(TaskAnti,1)
      AddExp_(time1*exp1s)
      time1=0
      Hour,Min,Sec=MathTime(dsut[pos][4])
      Talk(1,"no","Thoi gian con lai:
      end
      else
      Talk(1,"no","Cac ha hay doi them vai tieng nua roi quay lai day.")
      end
      end;
      function uythac()
      Say("<color=blue>NPC Uy Thac :<color> Nguoi muon uong loai nao ?",4,"Bach Cau Hoan (Tieu)/sBCH","Bach Cau Hoan (Trung)/mBCH","Bach Cau Hoan (Dai)/bBCH","Ta muon roi khoi day/no")
      end;
      function sBCH()
      DoUyThac(1)
      end;
      function mBCH()
      DoUyThac(2)
      end;
      function bBCH()
      DoUyThac(3)
      end;
      function DoUyThac(item)
      local ItemCount=GetItemCount(TabInfoItem[item][2])
      if ItemCount>=1 then
      DelItem(TabInfoItem[item][2])
      if GetItemCount(TabInfoItem[item][2]) == ItemCount-1 then
      local ID,name=GetUUID(),GetName()
      local pos,Hour,Min,Sec,timenow,BCH=FindTableUT(ID),0,0,0 ,Time(),item*8
      if pos == 0 then
      pos=getn(dsut)+1
      dsut[pos]={ID,name,timenow,BCH*3600}
      BCH=0
      SaveDataA(FileUT,"dsut["..pos.."]={"..dsut[pos][1]..","..format("%q",dsut[pos][2])..","..dsut[pos][3]..","..dsut[pos][4].."}\n")
      else
      dsut[pos][4]=dsut[pos][4]+BCH*3600
      BCH=0
      SaveDataA(FileUT,"dsut["..pos.."][4]="..dsut[pos][4].."\n")
      end
      Hour,Min,Sec=MathTime(dsut[pos][4])
      Talk(1,"no","Da su dung thanh cong "..TabInfoItem[item][1].."\nThoi gian con lai: "..Hour.." gio "..Min.." phut "..Sec.." giay")
      end
      else
      Talk(1,"no","Khong tim thay "..TabInfoItem[item][1])
      end
      end;
      function FindTableUT(UUID)
      for i=1,getn(dsut) do
      if dsut[i][1]==UUID then
      return i
      end
      end
      return 0
      end;
      function MathTime(Second)
      local Hour,Min,Sec=0,0,0
      Min=floor(Second/60)
      Sec=Second-Min*60
      if Min >= 60 then
      Hour=floor(Min/60)
      Min=Min-Hour*60
      end
      return Hour,Min,Sec
      end;
      function Time()
      local cyear,cmon,cday,cHour,cMin,cSec,Smon=tonumber(date ("%y")),tonumber(date("%m")),tonumber(date("%d")), tonumber(date("%H")),tonumber(date("%M")),tonumber (date("%S")),0
      for t=1,(cmon-1) do
      Smon=Smon+TimeTable[cyear][t]*86400
      end
      Smon=Smon+cday*86400
      return cyear*TimeTable[cyear-1][13]*86400+Smon+cHour*3600+cMin*60+cSec
      end
      function SapXepTab()
      SaveDataW(FileUT,TaoBang(dsut,"dsut","").."\n")
      Talk(1,"no","Da luu mang xong.")
      end;
      function SaveDataA(file, str)
      local filehd = openfile( file, "a+" ) 
      write(filehd,str) 
      closefile(filehd) 
      end;
      function SaveDataW(file, str)
      local filehd = openfile( file, "w+" ) 
      write(filehd,str) 
      closefile(filehd) 
      end;
      function TaoBang(tTable, sTableName, sTab)
      if sTab == nil then sTab = "" end;
      sTab = sTab or "";
      sTmp = ""
      sTmp = sTmp..sTab..sTableName.."={"
      local tStart = 0
      for key, value in tTable do
      if tStart == 1 then
      sTmp = sTmp..",\r"
      else
      sTmp = sTmp.."\r"
      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"..sTab.."}"
      return sTmp
      end;

      function AddExp_(Exp)
      if (Exp == nil) then Exp = 0 end
      local expcan,expco,lvbandau,hieucanco,tongexp,dkexp_C = exp_table,GetExp(),GetLevel(),0,0,0
      hieucanco = expcan[lvbandau][2]-expco
      if lvbandau < 200 then 
      if Exp <= hieucanco then
      AddOwnExp(Exp)
      tongexp = tongexp + Exp --- code them 
      else
      if (Exp > hieucanco) then
      AddOwnExp(hieucanco)
      tongexp = tongexp + hieucanco --- code them 
      expconlai = Exp-hieucanco
      dkexp_C = 1
      repeat
      if GetLevel() == 200 then--- ***
      break--- ***
      end --- *** neu gap loi thi del dong nay di
      if (expconlai > expcan[lvbandau+dkexp_C][2]) then
      AddOwnExp(expcan[lvbandau+dkexp_C][2])
      tongexp = tongexp + expcan[lvbandau+dkexp_C][2] --- code them 
      expconlai = expconlai - expcan[lvbandau+dkexp_C][2]
      dkexp_C = dkexp_C + 1
      end
      until expconlai <= expcan[lvbandau+dkexp_C][2]
      AddOwnExp(expconlai)
      tongexp = tongexp + expconlai --- code them 
      end
      end
      else
      MsgEx("Ban da dat dang cap 200 roi.")
      end
      Msg2Player("So exp da cong : "..tongexp) --- code them 
      end;

      \script\dulieu\datauythac.lua
      Code:

      dsut={
      }