vip = {
name = "Vip system",
author = "Mock",
version = "1.0.0.0",
query="ALTER TABLE `accounts` ADD `vip_time` INT( 15 ) NOT NULL"
}
function vip.setTable()
db.executeQuery(vip.query)
end
function vip.getVip(cid)
assert(tonumber(cid),'Parameter must be a number')
if not isPlayer(cid) then error('Player not found') end
local ae = db.getResult("SELECT `vip_time` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."';")
return ae:getID() ~= -1 and ae:getDataInt("vip_time") or 0
end
function vip.getVipByAcc(acc)
assert(acc,'Account is nil')
local a = db.getResult("SELECT `vip_time` FROM `accounts` WHERE `name` = '"..acc.."';")
return a:getID() == -1 and error('Account not found') or (a:getDataInt("vip_time") or 0)
end
function vip.setVip(cid,time)
assert(tonumber(cid),'Parameter must be a number')
assert(tonumber(time),'Parameter must be a number')
if not isPlayer(cid) then error('Player not found') end
db.executeQuery("UPDATE `accounts` SET `vip_time` = "..(os.time()+time).." WHERE `name` = '".. getPlayerAccount(cid).."' LIMIT 1;")
end
function vip.getVipByAccount(acc)
assert(acc,'Account is nil')
return db.getResult("SELECT `vip_time` FROM `accounts` WHERE `name` = '"..acc.."';"):getDataInt("vip_time") or 0
end
function vip.hasVip(cid)
assert(tonumber(cid),'Parameter must be a number')
if isPlayer(cid) == FALSE then error('Player don\'t find') end
return os.time(day) < (vip.getVip(cid) or 0)
end
function vip.accountHasVip(acc)
assert(acc,'Account is nil')
return os.time() < vip.getVipByAccount(acc)
end
function vip.getDays(days)
return 3600 * 24 * days
end
function vip.addVipByAccount(acc,time)
assert(acc,'Account is nil')
assert(tonumber(time),'Parameter must be a number')
return vip.setVipByAccount(acc, math.max(0, os.difftime(vip.getVipByAcc(acc), os.time())) + time)
end
function vip.setVipByAccount(acc,time)
assert(acc,'Account is nil')
assert(tonumber(time),'Parameter must be a number')
db.executeQuery("UPDATE `accounts` SET `vip_time` = "..(os.time()+time).." WHERE `name` = '"..acc.."' LIMIT 1;")
return TRUE
end
function vip.returnVipString(cid)
assert(tonumber(cid),'Parameter must be a number')
return isPlayer(cid) and os.date("%d %B %Y %X ", vip.getVip(cid))
end