• 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!

C++ check seconds

Lais Prad

Disgusting Scammer
Joined
Apr 12, 2017
Messages
153
Solutions
6
Reaction score
15
I'm trying to make this, and check how many seconds left to enter:

tfs 1.3

Lua:
local FerumbrasStorage = {}
local FerumbrasxStorage = 1209600 -- em segundos
local FerumbrasRoom = {x = 33376, y = 32307, z = 14}

function onStepIn(cid, item, position, lastPosition)  
      
        local player = Player(cid)
        local name = player:getName()  
 
        if not FerumbrasStorage[name] or FerumbrasStorage[name] <= os.time() then
        FerumbrasStorage[name] = os.time() + FerumbrasxStorage
        player:teleportTo(FerumbrasRoom)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            else
         player:sendCancelMessage(string.format("Wait %d seconds to enter again.", math.ceil(os.time()/1000)))
        player:teleportTo(lastPosition) -- pra onde?
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)          
        end          
      
return true
end
 
Try:
Lua:
player:sendCancelMessage(string.format("Wait %d seconds to enter again.", math.ceil(FerumbrasStorage[name] - os.time())))
 
Solution
Try:
Lua:
player:sendCancelMessage(string.format("Wait %d seconds to enter again.", math.ceil(FerumbrasStorage[name] - os.time())))

this works, thanks.

Hey, If i reload movements or restart the server I can enter in room, you know why this?
 
It wont reset on reloading movements if you change:
Lua:
local FerumbrasStorage = {}
to:
Lua:
if not FerumbrasStorage then
    FerumbrasStorage = {}
end
It wont saveon server restart though. You have to save it database in special table or just use player storages. Try this:

Lua:
local FerumbrasStorageId = 77777
local FerumbrasxStorage = 1209600 -- em segundos
local FerumbrasRoom = {x = 33376, y = 32307, z = 14}
function onStepIn(cid, item, position, lastPosition) 
    
        local player = Player(cid)
       
        if player:getStorageValue(FerumbrasStorageId) <= os.time() then
            player:setStorageValue(FerumbrasStorageId, os.time() + FerumbrasxStorage)
            player:teleportTo(FerumbrasRoom)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        else
            player:sendCancelMessage(string.format("Wait %d seconds to enter again.", math.ceil(player:getStorageValue(FerumbrasStorageId) - os.time())))
            player:teleportTo(lastPosition) -- pra onde?
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)         
        end         
    
    return true
end
 
It wont reset on reloading movements if you change:
Lua:
local FerumbrasStorage = {}
to:
Lua:
if not FerumbrasStorage then
    FerumbrasStorage = {}
end
It wont saveon server restart though. You have to save it database in special table or just use player storages. Try this:

Lua:
local FerumbrasStorageId = 77777
local FerumbrasxStorage = 1209600 -- em segundos
local FerumbrasRoom = {x = 33376, y = 32307, z = 14}
function onStepIn(cid, item, position, lastPosition)
  
        local player = Player(cid)
     
        if player:getStorageValue(FerumbrasStorageId) <= os.time() then
            player:setStorageValue(FerumbrasStorageId, os.time() + FerumbrasxStorage)
            player:teleportTo(FerumbrasRoom)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        else
            player:sendCancelMessage(string.format("Wait %d seconds to enter again.", math.ceil(player:getStorageValue(FerumbrasStorageId) - os.time())))
            player:teleportTo(lastPosition) -- pra onde?
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)       
        end       
  
    return true
end

Nice, this works!
 
Last edited:
Back
Top