JO
pedido

Comando /save e Clean automático

Por JonatasLucasf, 17 de mai. de 2015 em Scripts

resolvido
9
3.1k
17 de maio de 2015 às 10:28

galera estou precisando do comando /save para salvar os players online, houses,etc, de preferencia deixar ele automático, também queria um clean automático se possível

 

USO TFS 1.1 VERSÃO 10.76

AdministradorA
17 de maio de 2015 às 10:37

CLEAN AUTOMÁTICO

data/globalevents/scripts/clean.lua

function executeClean(interval)
	doCleanMap()
	doBroadcastMessage("Game map cleaned, next clean in " .. table.concat(string.timediff(interval / 1000)) .. ".")
	return true
end

function onThink(interval)
	doBroadcastMessage("Game map cleaning within 30 seconds, please pick up your items!")
	addEvent(executeClean, 240000, interval)
	return true
end

globalevents.xml

	<globalevent name="clean" interval="7200000" event="script" value="clean.lua"/>


 

SAVE AUTOMÁTICO

globalevents/scripts/save.lua

local config = {
	broadcast = {120, 30},
	flags = 13,
	delay = 120,
	events = 30
}

local function executeSave(seconds)
	if(isInArray(config.broadcast, seconds)) then
		doBroadcastMessage("Server save within " .. seconds .. " seconds, please mind it may freeze!")
	end

	if(seconds > 0) then
		addEvent(executeSave, config.events * 1000, seconds - config.events)
	else
		doSaveServer(config.flags)
	end
end

function onThink(interval)
	if(table.maxn(config.broadcast) == 0) then
		doSaveServer(config.flags)
	else
		executeSave(config.delay)
	end

	return true
end

globalevents.xml

	<globalevent name="save" interval="900000" event="script" value="save.lua"/>


 

SAVE POR COMANDO

talkactions/scripts/save.lua

local savingEvent = 0

function onSay(cid, words, param, channel)
	local tmp = tonumber(param)
	if(tmp ~= nil) then
		stopEvent(savingEvent)
		save(tmp * 60 * 1000)
	elseif(param:trim() == '') then
		doSaveServer(13)
	else
		local tid = getPlayerByNameWildcard(param)
		if(not tid or (isPlayerGhost(tid) and getPlayerGhostAccess(tid) > getPlayerGhostAccess(cid))) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " not found.")
		else
			doPlayerSave(tid)
		end
	end

	return true
end

function save(delay)
	doSaveServer(13)
	if(delay > 0) then
		savingEvent = addEvent(save, delay, delay)
	end
end

talkactions.xml

	<talkaction log="yes" group="4" access="3" words="/save" event="script" value="save.lua"/>
18 de maio de 2015 às 15:24

Daniel o /save deu erro na linha 9 in function doSaveserver esse script está adaptado para tfs 1.1?

FurabioF
18 de maio de 2015 às 15:46

Save e clean automático, peguei do server do Printer,

 

 

 

servesave.lua (data/globalevents/scripts/) :

local shutdownAtServerSave = false
local cleanMapAtServerSave = true

local function serverSave()
	if shutdownAtServerSave then
		Game.setGameState(GAME_STATE_SHUTDOWN)
	else
		Game.setGameState(GAME_STATE_NORMAL)
	end

	if cleanMapAtServerSave then
		cleanMap()
	end

	saveServer()
end

local function secondServerSaveWarning()
	Game.broadcastMessage('Server is saving game in one minute. Please go to a safe place.', MESSAGE_STATUS_WARNING)
	addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
	Game.broadcastMessage('Server is saving game in 3 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
	addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
	Game.broadcastMessage('Server is saving game in 5 minutes. Please go to a safe place.', MESSAGE_STATUS_WARNING)
	Game.setGameState(GAME_STATE_STARTUP)
	addEvent(firstServerSaveWarning, 120000)
	return not shutdownAtServerSave
end

globalevents.XML (data/globalevents/) :

	<globalevent name="ServerSave" time="09:55:00" script="serversave.lua" />
18 de maio de 2015 às 16:24

esse eu tenho amigo, então pode ser só o comando /save poderia fazer pra mim?

FurabioF
18 de maio de 2015 às 16:30


function onSay(player, words, param)

 

if not player:getGroup():getAccess() then

return true

end

 

if player:getAccountType() < ACCOUNT_TYPE_GOD then

return false

end

 

saveServer()

Game.broadcastMessage('Server is saved.', MESSAGE_STATUS_WARNING)

 

return false

end

BrunoB
18 de maio de 2015 às 16:35
Melhor resposta

Em data/talkactions/scripts crie um arquivo chamado save.lua com o conteúdo:

local shutdownAtServerSave = false -- se o server vai fechar quando for salvo
local cleanMapAtServerSave = true -- se o server vai ser limpo quando for salvo

local function serverSave()
	if shutdownAtServerSave then
		Game.setGameState(GAME_STATE_SHUTDOWN)
	else
		Game.setGameState(GAME_STATE_NORMAL)
	end

	if cleanMapAtServerSave then
		cleanMap()
	end

	saveServer()
end

function onSay(player, words, param)
	if not player:getGroup():getAccess() then
		return true
	end
	
	local timeSave = param
	if timeSave ~= nil then
		timeSave = timeSave * 1000
		addEvent(serverSave, timeSave)
	else
		serverSave()
	end
	
	return true
end
Agora em data/talkactions/talkactions.xml adicione a seguinte linha:

<talkaction words="/save" separator=" " script="save.lua" />
Edit: agora você pode colocar tempo em segundos para o save. Exemplo: /save 60 (vai executar o save em 1 minuto)

Editado Maio 18 por Bruno Minervino

18 de maio de 2015 às 16:55

Em data/talkactions/scripts crie um arquivo chamado save.lua com o conteúdo:

local shutdownAtServerSave = false -- se o server vai fechar quando for salvo
local cleanMapAtServerSave = true -- se o server vai ser limpo quando for salvo

local function serverSave()
	if shutdownAtServerSave then
		Game.setGameState(GAME_STATE_SHUTDOWN)
	else
		Game.setGameState(GAME_STATE_NORMAL)
	end

	if cleanMapAtServerSave then
		cleanMap()
	end

	saveServer()
end

function onSay(player, words, param)
	if not player:getGroup():getAccess() then
		return true
	end
	
	local timeSave = param
	if timeSave ~= nil then
		timeSave = timeSave * 1000
		addEvent(serverSave, timeSave)
	else
		serverSave()
	end
	
	return true
end
Agora em data/talkactions/talkactions.xml adicione a seguinte linha:

<talkaction words="/save" separator=" " script="save.lua" />
Edit: agora você pode colocar tempo em segundos para o save. Exemplo: /save 60 (vai executar o save em 1 minuto)

 

Obrigado Bruno funcionou uma duvida ele salva o player também né como level, posição etc?

@ScreaM Obrigado também.

BrunoB
18 de maio de 2015 às 17:03

Obrigado Bruno funcionou uma duvida ele salva o player também né como level, posição etc?

@ScreaM Obrigado também.[/size]

Sim, salva no estado atual.

Tópico movido para a seção de dúvidas e pedidos resolvidos.