• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X [7.6] Vip Days left

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
I have a vip script that works great and gives the player 30 days of VIP. I would like to create a command (talkaction) that the player can see how much VIP time he still has.
Follow my VIP scroll action:

Lua:
local vipStorage = 30009
local vipDays = 30

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentTime, vipStorageValue = os.time(), getPlayerStorageValue(cid, vipStorage)
    setPlayerStorageValue(cid, vipStorage, (vipStorageValue < currentTime and currentTime or vipStorageValue) + (60 * 60 * 24 * vipDays))
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
    doRemoveItem(item.uid, 1)
    return true
end
 
Solution
Lua:
function getTimeString(self)
    local format = {
        {'day', self / 60 / 60 / 24},
        {'hour', self / 60 / 60 % 24},
        {'minute', self / 60 % 60},
        {'second', self % 60}
    }
    
    local out = {}
    for k, t in ipairs(format) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    local ret = table.concat(out)
    if ret:len() < 16 and ret:find('second') then
        local a, b = ret:find(' and ')
        ret = ret:sub(b+1)
    end
    return ret
end

function onSay(cid, words, param, channel)
    local time = getPlayerStorageValue(cid, 30009) -...
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "you got :"..getPlayerStorageValue(cid, 30009).." vip days left)
 
Im not home
i got it, but when i type my talk action, appear like this:

10:47 You got :1640656885 vip days left.
Post automatically merged:

Solve:

Lua:
local timenow = os.time()

function onSay(cid, words, param, channel)
    local quantity = math.floor((getPlayerStorageValue(cid, 30009) - timenow)/(24 * 60 * 60))
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have ".. quantity .." days of VIP left.")
    return true
end

But i sill have a problem, if a player have no VIP days, appears a negative value, like this:

11:19 You have -156 days of VIP left.
 
Last edited:
Lua:
function getTimeString(self)
    local format = {
        {'day', self / 60 / 60 / 24},
        {'hour', self / 60 / 60 % 24},
        {'minute', self / 60 % 60},
        {'second', self % 60}
    }
    
    local out = {}
    for k, t in ipairs(format) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    local ret = table.concat(out)
    if ret:len() < 16 and ret:find('second') then
        local a, b = ret:find(' and ')
        ret = ret:sub(b+1)
    end
    return ret
end

function onSay(cid, words, param, channel)
    local time = getPlayerStorageValue(cid, 30009) - os.time()
    if time <= 0 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don\'t have premium days.")
        return true
    end   
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have " .. (getTimeString(time)) .. " of VIP left.")
    return true
end
 
Solution
Lua:
function getTimeString(self)
    local format = {
        {'day', self / 60 / 60 / 24},
        {'hour', self / 60 / 60 % 24},
        {'minute', self / 60 % 60},
        {'second', self % 60}
    }
   
    local out = {}
    for k, t in ipairs(format) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    local ret = table.concat(out)
    if ret:len() < 16 and ret:find('second') then
        local a, b = ret:find(' and ')
        ret = ret:sub(b+1)
    end
    return ret
end

function onSay(cid, words, param, channel)
    local time = getPlayerStorageValue(cid, 30009) - os.time()
    if time <= 0 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don\'t have premium days.")
        return true
    end  
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have " .. (getTimeString(time)) .. " of VIP left.")
    return true
end
Very nice, thanks again Alberto
 

Similar threads

Back
Top