Ir para conteúdo
  • 0

[House] Perder A House


FehZito

Pergunta

Posts Recomendados

  • 0

@Zmovir

 

para de floodar por favor.

 

@Topic

 

estou vendo o que posso fazer aqui e ja ja edito.

 

@edit

 

é um globalevent.

 

 

globalevent.xml

 

<globalevent name="cleanhouses" type="start" event="script" value="cleanhouses.lua"/>

 

cleanhouses.lua

 

local config = {
   days = 14,
   log = true,
   file = getDataDir() .. "/logs/cleanhouses.txt"
}   
local ns_query =[[ SELECT houses.owner,houses.id,players.name FROM houses
		    LEFT JOIN players ON players.id=houses.owner
		    WHERE players.lastlogin < (UNIX_TIMESTAMP() - ]] ..config.days.. [[*24*60*60)
		    AND
		    players.world_id =]] .. getConfigValue("worldId")[/font]
[font=tahoma, geneva, sans-serif]function onStartup(_time)[/font]
[font=tahoma, geneva, sans-serif]    local house = db.getResult(ns_query)
   local logs = "  Houses cleaned:\n\n"
   if house:getID() ~= -1 then
    repeat
	    logs = logs .. getHouseInfo(house:getDataInt('id')).name ..", owned by " .. house:getDataString('name') .. "\n"
	    setHouseOwner(house:getDataInt('id'), 0)
    until not house:next()
    house:free()
   else
    logs = logs .. "There were no houses to clean."
   end
   if config.log then
    doWriteLogFile(config.file, logs)
   end
   addEvent(doSaveServer, 1000)
end

 

Créditos:

Nsanee

 

 

c

Editado por Beeki
Link para o comentário
Compartilhar em outros sites

  • 0

Fiz um aqui, testei mais pouco. Qualquer erro fala. E funciona quando o player fica 30 dias sem logar. Eu tava fazendo antes do Beeki postar, então vou postar msm assim.

 

Vai em data/globalscripts/scripts/ duplica um arquivo e nomeia para "houseclean" sem as aspas e nele cole:

function onThink(interval, lastExecution, thinkInterval)

local b = 0
local d = db.getResult("SELECT `owner` FROM `houses` WHERE `owner` > "..b..";")

if (d:getDataInt("owner") ~= false) then
   local c = db.getResult("SELECT `name` FROM `players` WHERE `id` == "..d:getDataInt("owner")..";")
   local lastLogin = getPlayerLastLoginSaved(getPlayerByName(c:getDataString("name")))
   local e = db.getResult("SELECT `id` FROM `houses` WHERE `owner` == "..d:getDataInt("owner")..";")

   if (os.date("%d", lastLogin) <= os.date("%d") and os.date("%b", lastLogin) ~= os.date("%b")) then
       doCleanHouse(e:getDataInt("id"))
       setHouseOwner(e:getDataInt("id"), 0)
   end
end

while (d:next() ~= false) do
   c = db.getResult("SELECT `name` FROM `players` WHERE `group_id` == "..d:getDataInt("owner")..";")
   lastLogin = getPlayerLastLoginSaved(getPlayerByName(c:getDataString("name")))
   e = db.getResult("SELECT `id` FROM `houses` WHERE `owner` == "..d:getDataInt("owner")..";")
   if (os.date("%d", lastLogin) <= os.date("%d") and os.date("%b", lastLogin) ~= os.date("%b")) then
       doCleanHouse(e:getDataInt("id"))
       setHouseOwner(e:getDataInt("id"), 0)
   end
end

return true
end

 

Agora em globalevents.xml cole a tag:

<globalevent name="houseclean" interval="86400" event="script" value="houseclean.lua"/>

Link para o comentário
Compartilhar em outros sites

  • 0

achei uma talk,não é minha:

 

houseclean.lua


--Adam 2008 Edited by Teh Maverick to work in 0.2+

--Config
local safelist = {1,2}
local days = 10*3600*24

--Leave these
local ownerr = 0
local hid = 0
local pid = 0
local lastlogin = 0
local cleared = 0
local name = ""
local house = nil
local player = nil
local playerID = nil
local cur = nil
local cur2 = nil

function onSay(cid, words, param)
if getPlayerGroupId(cid) > 2 then
   pdelete = "Inactive Players With Houses:\n\n"
   t=os.date('*t')
  dofile("./config.lua")
  env = assert(luasql.mysql())
  con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
  local houseID = assert(con:execute("SELECT `owner` FROM `houses`  WHERE `owner` > 0"))
  local houseCount = numRows(houseID)
  cur = assert(con:execute("SELECT `owner`, `id` FROM `houses` WHERE `owner` > 0"))
  house  = cur:fetch({}, "a")
  cur:close()

 if(houseCount >= 1) then
  for owner, id in rows(con, "SELECT `owner`, `id` FROM `houses` WHERE `owner` > 0 ORDER BY `id` DESC;") do
       ownerr = tonumber(owner)
       hid = tonumber(id)
     playerID = assert(con:execute("SELECT `id` FROM `players` WHERE `id` = '"..ownerr.."'  "))
     cur2 = assert(con:execute("SELECT `id`,`name`,`lastlogin` FROM `players` WHERE `id` = '"..ownerr.."'  "))
     player = cur2:fetch({}, "a")
     cur2:close()

           if(numRows(playerID) >= 1) then
               lastlogin = player.lastlogin
               pid = player.id
               name = player.name
               time=os.time(t) - lastlogin
               offline = time - days

               if offline >= 0 then
                   pdelete = pdelete.."House #"..hid.." owned by "..name.."\n"
                   if isInArray(safelist,hid) == FALSE then                    
                       setHouseOwner(hid, 0)
                 cleared=cleared+1
                   end
               end
           player = nil
           end
   end
    if cleared < 1 then
     pdelete = "No players have been inactive.\n"
    end
   doShowTextDialog(cid, 5958, pdelete.."\n"..cleared.." Houses cleared.")
 else
   doPlayerSendCancel(cid, "No one owns any houses")
   print('No one owns any houses')
 end
 house = nil
 con:close()
 env:close()
end
return TRUE
end

 

talkactions.xml

<talkaction words="/cleanhouses" script="houseclean.lua"/>

 

lib/functions adc:

function numRows(cursor)
  local row = cursor:fetch()
  local rows = 0
  while row do
     rows = rows + 1
     row = cursor:fetch()
  end
  cursor:close()
  return rows
end

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...