local usrdir="/user/" if fs.exists(usrdir)==false then fs.makeDir(usrdir) end commandBlock=peripheral.wrap("back") ami = peripheral.wrap("adventure map interface_N") function getWorldTime() if not http then print("Pastebin requires http API!!!") print("Set enable API_http in ComputerCraft.cfg") error() end local response = http.get("http://www.timeapi.org/utc/now") --change args if response then local time_mess = response.readAll() response.close() return time_mess else return false end end function playerLoginDetect() local e, user_name = os.pullEvent("player_login") return user_name end function sayChat(msg) commandBlock.setCommand("/say "..msg) commandBlock.runCommand() end function giveItem(name_player, id, count) commandBlock.setCommand("/give " .. name_player .. " " .. id .. " " .. count) commandBlock.runCommand() end function makeAccount(username) local f=fs.open(usrdir .. username, "w") f.writeLine(tonumber(getDate())-1) f.writeLine("0") f.close() end function readAccountData(username) local f=fs.open(usrdir .. username, "r") local lastlogin=f.readLine() local totalDays=f.readLine() f.close() return lastlogin, totalDays end function writeAccountData(username, lastlogin, totalDays) local f=fs.open(usrdir .. username, "w") f.writeLine(lastlogin) f.writeLine(totalDays) f.close() end function getDate() local preTime=getWorldTime() day=tonumber(string.sub(preTime, 9, 10)) month=tonumber(string.sub(preTime, 6, 7)) year=tonumber(string.sub(preTime, 1, 4)) local date=tonumber(year .. month .. day) return date end function getDateAdvanced() local preTime=getWorldTime() day=tonumber(string.sub(preTime, 9, 10)) month=tonumber(string.sub(preTime, 6, 7)) year=tonumber(string.sub(preTime, 1, 4)) return day, month, year end function giftDaily(player) items={264, 5} --ids of gifts itemsNames={"Diamond", "Wood Planks"} --names of gifts itemsMin={1, 10} -- minimal gifts count itemsMax={5, 256} --maximal gifts count giftsTotal=2 -- count of total avilable gifts local item=math.random(1, giftsTotal) local itemID=items[item] local count=math.random(itemsMin[item], itemsMax[item]) sayChat("[Gifter] " .. player .. " won " .. itemsNames[item ] .. " x " .. count) giveItem(player, itemID, count) end function giftFinal(player) items={264, 5} --ids of gifts itemsNames={"Diamond", "Wood Planks"} --names of gifts itemsMin={1, 10} -- minimal gifts count itemsMax(5, 256) --maximal gifts count giftsTotal=2 -- count of total avilable gifts local item=math.random(1, giftsTotal) local itemID=items[item] local count=math.random(itemsMin[item], itemsMax[item]) sayChat("[Gifter] " .. player .. " won FINAL GIFT " .. itemsName[item ] .. " x " .. count) giveItem(player, itemID, count) end sayChat("[Gifter] Gifter by MelnikovSM") sayChat("[Gifter] Wroten for http://computercraft.ru") while true do local player = playerLoginDetect() if fs.exists(usrdir .. player)==false then makeAccount(player) end local lastlogin, totalDays=readAccountData(player) local day, month, year=getDateAdvanced() if tonumber(lastlogin)+1==tonumber(getDate()) then count=totalDays+1 giftDaily(player) writeAccountData(player, tonumber(getDate()), count) if totalDays=7 then giftFinal() end elseif tonumber(string.sub(tostring(lastlogin))), 7,8)))==30 and tonumber(string.sub(tostring(getDate(), 7, 7))==1 then --заплатка для случая перехода дат с 30 по 1, где длинна номера месяца больше 10(числа вроде 08 tonumber превращает в 8) count=totalDays+1 giftDaily(player) writeAccountData(player, tonumber(getDate()), count) elseif tonumber(string.sub(tostring(lastlogin))), 7,8)))==31 and tonumber(string.sub(tostring(getDate(), 7, 7))==1 then --заплатка для случая перехода дат с 31 по 1, где длинна номера месяца больше 10(числа вроде 08 tonumber превращает в 8) count=totalDays+1 giftDaily(player) writeAccountData(player, tonumber(getDate()), count) if totalDays=7 then giftFinal() end elseif tonumber(string.sub(tostring(lastlogin))), 6,7)))==30 and tonumber(string.sub(tostring(getDate(), 6, 6))==1 then --заплатка для случая перехода дат с 30 по 1, где длинна номера месяца не больше 10(числа вроде 08 tonumber превращает в 8) count=totalDays+1 giftDaily(player) writeAccountData(player, tonumber(getDate()), count) if totalDays=7 then giftFinal() end elseif tonumber(string.sub(tostring(lastlogin))), 6,7)))==31 and tonumber(string.sub(tostring(getDate(), 6, 6))==1 then --заплатка для случая перехода дат с 31 по 1, где длинна номера месяца небольше 10(числа вроде 08 tonumber превращает в 8) count=totalDays+1 giftDaily(player) writeAccountData(player, tonumber(getDate()), count) if totalDays=7 then giftFinal() end elseif tonumber(string.sub(tostring(lastlogin))), 5,5)))==2 and tonumber(string.sub(tostring(lastlogin))), 6,7)))==29 and tonumber(string.sub(tostring(getDate(), 6, 6))==1 then --заплатка для случая перехода дат с 29 по 1 (февраль-март), где длинна номера месяца больше 10(числа вроде 08 tonumber превращает в 8) count=totalDays+1 giftDaily(player) writeAccountData(player, tonumber(getDate()), count) else sayChat("[Gifter] " .. player .. "'s account reset: he not joined game yesterday!") makeAccount(player) if totalDays=7 then giftFinal() end end end