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

RevScripts killuaCaveOwners/no back temple

Gaber Zen

Well-Known Member
Joined
Apr 22, 2023
Messages
241
Reaction score
62
Location
Egypt
Hello, how are everyone, I am facing a problem that I do not know how to solve. When the person runs out of time from using the card, he does not leave the room after the specified period of 6 hours
function restTempo(storage)-- By Zefz
local segundos, minutos, horas = 0,0,0
local tot = storage - os.time()
horas = math.floor(tot/3600)
tot = tot - horas * 3600
minutos = math.floor(tot/60)
tot = tot - minutos * 60
segundos = tot
return string.format("Você jل usou este item e precisa esperar %.2d:%.2d:%.2d para usar novamente.", horas, minutos, segundos)
end


local storages = {

722340,
722341,
722342,
722343,
722344,
722345,
722346,
722347,
722348,
722349,
722363,
722364,
722365,
722366,
722367,
722368,
722369,
722370,
722371,
722372

}

local stg = 722340

local function hasCave(cid)
local storages = {722340,722341,722342,722343,722344,722345,722346,722347,722348,722349,722363,722364,722365,722366,722367,722368,722369,722370,722371,722372}

for a,b in pairs(storages) do
sto = getGlobalTableStorage(b)
if sto.guid and sto.guid == getCreatureName(cid) then
if tonumber(sto.time) > os.time() then
return a
end
end
end
return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

if hasCave(cid) then
return doPlayerSendCancel(cid,"Você jل é o dono da cave "..hasCave(cid).." e nمo pode alugar outra até o aluguel dela acabar.")
end
if getPlayerStorageValue(cid, stg) < os.time() then
setPlayerStorageValue(cid, stg, os.time() + (24*3600))
local check, cave = false, 0
for i = 1, #storages do
sto = getGlobalTableStorage(storages)
if not sto.time then
setGlobalTableStorage(storages,{guid = getCreatureName(cid), time = os.time() + (6*3600)})
doRemoveItem(item.uid,1)
doSendMagicEffect(getThingPos(cid), 12)
cave = i
check = true
break;
end
if sto.time and tonumber(sto.time) > 0 then
if tonumber(sto.time) < os.time() then
setGlobalTableStorage(storages,{guid = getCreatureName(cid), time = os.time() + (6*3600)})
doRemoveItem(item.uid,1)
doSendMagicEffect(getThingPos(cid), 12)
cave = i
check = true
break;
end
end
end

if check then
doSaveServer()
doPlayerSendTextMessage(cid,25,"Você acabou de alugar a cave "..cave.." por 6 horas. Aproveite!")
else
doPlayerSendCancel(cid,"Todas as caves jل estمo alugadas no momento... Tente novamente mais tarde.")
end
else
doPlayerSendTextMessage(cid,25, restTempo(getPlayerStorageValue(cid, stg)))
end
return true
end

 
Hello Gaber Zen,

I made changes to the local variables in the restTempo function and removed the redundant storages array from the hasCave function.

Here's the revised script:
Lua:
function restTempo(storage)
  local tot = storage - os.time()
  local horas = math.floor(tot / 3600)
  tot = tot - horas * 3600
  local minutos = math.floor(tot / 60)
  tot = tot - minutos * 60
  local segundos = tot
  return string.format("Você jل usou este item e precisa esperar %.2d:%.2d:%.2d para usar novamente.", horas, minutos, segundos)
end

local storages = {722340, 722341, 722342, 722343, 722344, 722345, 722346, 722347, 722348, 722349, 722363, 722364, 722365, 722366, 722367, 722368, 722369, 722370, 722371, 722372}
local stg = 722340

local function hasCave(cid)
  for a, b in pairs(storages) do
    sto = getGlobalTableStorage(b)
    if sto.guid and sto.guid == getCreatureName(cid) then
      if tonumber(sto.time) > os.time() then
        return a
      end
    end
  end
  return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if hasCave(cid) then
    return doPlayerSendCancel(cid, "Você jل é o dono da cave " .. hasCave(cid) .. " e nمo pode alugar outra até o aluguel dela acabar.")
  end

  if getPlayerStorageValue(cid, stg) < os.time() then
    setPlayerStorageValue(cid, stg, os.time() + 24 * 3600)

    local check, cave = false, 0

    for i = 1, #storages do
      sto = getGlobalTableStorage(storages)
      if not sto.time then
        setGlobalTableStorage(storages, {guid = getCreatureName(cid), time = os.time() + 6 * 3600})
        doRemoveItem(item.uid, 1)
        doSendMagicEffect(getThingPos(cid), 12)
        cave = i
        check = true
        addEvent(function(name, pos)
          local cid = getPlayerByName(name)

          if cid and isPlayer(cid) then
            doTeleportThing(cid, pos)
          end
        end, 1 * 60 * 1000, cid, getTownTemplePosition(getPlayerTown(cid)))
        break
      end

      if sto.time and tonumber(sto.time) > 0 then
        if tonumber(sto.time) < os.time() then
          setGlobalTableStorage(storages, {guid = getCreatureName(cid), time = os.time() + 6 * 3600})
          doRemoveItem(item.uid, 1)
          doSendMagicEffect(getThingPos(cid), 12)
          cave = i
          check = true
          addEvent(function(name, pos)
            local cid = getPlayerByName(name)

            if cid and isPlayer(cid) then
              doTeleportThing(cid, pos)
            end
          end, 1 * 60 * 1000, getCreatureName(cid), getTownTemplePosition(getPlayerTown(cid)))
          break
        end
      end
    end

    if check then
      doSaveServer()
      doPlayerSendTextMessage(cid, 25, "Você acabou de alugar a cave " .. cave .. " por 6 horas. Aproveite!")
    else
      doPlayerSendCancel(cid, "Todas as caves jل estمo alugadas no momento... Tente novamente mais tarde.")
    end
  else
    doPlayerSendTextMessage(cid, 25, restTempo(getPlayerStorageValue(cid, stg)))
  end
  return true
end

To implement these changes, please replace your existing script with this version and then reload or restart your server. Make sure to monitor the console for any potential errors. For the purpose of testing, I've reduced the wait time for teleportation to one minute to expedite your testing process.

Kind regards
 
Last edited:

Similar threads

Back
Top