Jump to content

[Ajuda]Verificação de Table


Recommended Posts

Posted

Olá amigos, estou desenvolvendo um código cujo o player só pode executar determinado tempo. pórem eu queria mesmo que o player quando saísse do Servidor, o timer continuasse correndo, mas acho que não tem como, então tentei fazer de uma maneira diferente, porém parece que quando o player logo, meio que não é verificado se ele está nessa tabela...

server-side

local theMarker = createMarker (1409.666, -1790.515, 13.546 -1.0, "cylinder", 1.2, 200, 50, 0, 150)
local theTimers = {}

function DeltaSCRAbrir (hitElement, matchingDimension)
    if (getElementType(hitElement)) == "player" then
        if getPedOccupiedVehicle(hitElement) == false then
			local theTimer = theTimers[hitElement]
            if not (theTimer) then
                    theTimers[hitElement] = setTimer (function ()
                    theTimers[hitElement] = nil
                end, 60000, 1)
            elseif theTimer and isTimer(theTimer) then
				outputChatBox ("╔═════════════════════════════════════════════════╗", hitElement, 200, 50, 0)
                outputChatBox ("ERRO: #FFFFFFVocê já resgatou seu bônus diario, aguarde para resgatar o próximo", hitElement, 200, 50, 0, true)
				outputChatBox ("╚═════════════════════════════════════════════════╝", hitElement, 200, 50, 0)
				return
            end
            triggerClientEvent (hitElement, "DeltaSCR:Abrir", root)
        end
    end
end
addEventHandler ("onMarkerHit", theMarker, DeltaSCRAbrir)

function setDataLogout (thePreviousAccount, theCurrentAccount)
	setAccountData (thePreviousAccount, "DeltaSCR:Timers", timerDetails)
end
addEventHandler ("onPlayerLogout", getRootElement(), setDataLogout)

function setDataLogin (thePreviousAccount, theCurrentAccount)
	if isTimer(theTimers) then
		local timerDetails = getTimerDetails (theTimers)
		local dataTimer = getAccountData (theCurrentAccount, "DeltaSCR:Timers")
		if dataTimer then
			setElementData (source, "DeltaSCR:Timers", dataTimer)
		end
	end
end
addEventHandler ("onPlayerLogin", getRootElement(), setDataLogin)

addEventHandler ("onPlayerQuit", root,
	function()
		if theTimers[source] then
			if isTimer(theTimers[source]) then
				killTimer(theTimers[source])
			end
			theTimers[source] = nil
		end
	end	
)

 

client-side (evento que está sendo chamado pelo server)

function AbrirPainel ()
	if PainelDX then
		removeEventHandler ("onClientRender", getRootElement(), DeltaSCRDX)
		showChat(true)
		showCursor(false)
	else
		addEventHandler ("onClientRender", getRootElement(), DeltaSCRDX)
		showChat(false)
		showCursor(true)
	end
	PainelDX = not PainelDX
end
addEvent ("DeltaSCR:Abrir", true)
addEventHandler ("DeltaSCR:Abrir", getRootElement(), AbrirPainel)

 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

  • Moderators
Posted

Quando o jogador sair do servidor, vc deve salvar o tempo restante do timer dele com o setAccountData e com o getTimerDetails. E logo em seguida dar killTimer para não ficar contando o tempo do player que não existe.

Quando o player logar de novo, cria o timer de novo normalmente com o setTimer usando o tempo restante que estava salvo na conta dele com getAccountData.

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted
39 minutes ago, Lord Henry said:

Quando o jogador sair do servidor, vc deve salvar o tempo restante do timer dele com o setAccountData e com o getTimerDetails. E logo em seguida dar killTimer para não ficar contando o tempo do player que não existe.

Quando o player logar de novo, cria o timer de novo normalmente com o setTimer usando o tempo restante que estava salvo na conta dele com getAccountData.

Eu criei uma variável com o getTimerDatails, porém acho que pelo fato dela está dentro de uma função, não pegou no setAccountData, acho que foi mais em questão do killTimer, agora uma dúvida: nessa última parte que você falou, de adicionar um setTimer no Player assim que ele logar, eu deverei armazenar na mesma table?

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

Posted

@Lord Henry Fiz pequenas alterações, estaria correto assim?

local theTimers = {}

function DeltaSCRAbrir (hitElement, matchingDimension)
    if (getElementType(hitElement)) == "player" then
        if getPedOccupiedVehicle(hitElement) == false then
			local theTimer = theTimers[hitElement]
            if not (theTimer) then
                    theTimers[hitElement] = setTimer (function ()
                    theTimers[hitElement] = nil
                end, 60000, 1)
            elseif theTimer and isTimer(theTimer) then
				outputChatBox ("╔═════════════════════════════════════════════════╗", hitElement, 200, 50, 0)
                outputChatBox ("ERRO: #FFFFFFVocê já resgatou seu bônus diario, aguarde para resgatar o próximo", hitElement, 200, 50, 0, true)
				outputChatBox ("╚═════════════════════════════════════════════════╝", hitElement, 200, 50, 0)
				return
            end
            triggerClientEvent (hitElement, "DeltaSCR:Abrir", root)
        end
    end
end
addEventHandler ("onMarkerHit", theMarker, DeltaSCRAbrir)

local timerDetails = getTimerDetails (theTimers)

function setDataLogout (thePreviousAccount, theCurrentAccount)
	setAccountData (thePreviousAccount, "DeltaSCR:Timers", timerDetails)
end
addEventHandler ("onPlayerLogout", getRootElement(), setDataLogout)

addEventHandler ("onPlayerQuit", root,
	function()
		if theTimers[source] then
			if isTimer(theTimers[source]) then
				killTimer(theTimers[source])
			end
			theTimers[source] = nil
		end
	end	
)

function setDataLogin (thePreviousAccount, theCurrentAccount)
	if isTimer(theTimers) then
		local dataTimer = getAccountData (theCurrentAccount, "DeltaSCR:Timers")
		if dataTimer then
			setElementData (source, "DeltaSCR:Timers", dataTimer)
		end
	end
end
addEventHandler ("onPlayerLogin", getRootElement(), setDataLogin)

 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

  • Moderators
Posted (edited)
12 hours ago, Gw8 said:

Também daria, mas eu particularmente usaria getRealTime().timestamp pois ele não está trabalhando com datas, só com tempo.

@#DeltaSCR da linha 6 em diante não faz sentido vc criar uma variável local para guardar uma variável global.

function DeltaSCRAbrir (theMarker, matchingDimension)
	if getPedOccupiedVehicle(source) == false then
		if isTimer(theTimers[source]) then
			outputChatBox ("╔═════════════════════════════════════════════════╗", source, 200, 50, 0)
			outputChatBox ("ERRO: #FFFFFFVocê já resgatou seu bônus diario, aguarde para resgatar o próximo", source, 200, 50, 0, true)
			outputChatBox ("╚═════════════════════════════════════════════════╝", source, 200, 50, 0)
		else
			theTimers[source] = setTimer (function ()
				theTimers[source] = nil
			end, 60000, 1) -- 1 minuto.
			triggerClientEvent (source, "DeltaSCR:Abrir", source)
		end
	end
end
addEventHandler ("onPlayerMarkerHit", theMarker, DeltaSCRAbrir) -- A função só funciona quando um player colide no marker. Dessa forma n precisa verificar se o elemento que colidiu é um player. source = player que colidiu no marker.

 

Edited by Lord Henry

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted
8 minutes ago, Lord Henry said:

Também daria, mas eu particularmente usaria getRealTime().timestamp pois ele não está trabalhando com datas, só com tempo.

@#DeltaSCR da linha 6 em diante não faz sentido vc criar uma variável local para guardar uma variável global. Em vez de usar theTimer, use theTimers[hitElement]

No caso nas verificações?

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

  • Moderators
Posted

Editei a resposta.

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

  • Moderators
Posted

Claro que vai, só n coloquei pq ela fica fora daquela função.

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

  • Moderators
Posted (edited)
local theTimers = {}

function DeltaSCRAbrir (theMarker, matchingDimension)
	if getPedOccupiedVehicle(source) == false then
		if isTimer(theTimers[source]) then
			outputChatBox ("╔═════════════════════════════════════════════════╗", source, 200, 50, 0)
			outputChatBox ("ERRO: #FFFFFFVocê já resgatou seu bônus diario, aguarde para resgatar o próximo", source, 200, 50, 0, true)
			outputChatBox ("╚═════════════════════════════════════════════════╝", source, 200, 50, 0)
		else
			theTimers[source] = setTimer (function ()
				theTimers[source] = nil
			end, 60000, 1) -- 1 minuto.
			triggerClientEvent (source, "DeltaSCR:Abrir", source)
		end
	end
end
addEventHandler ("onPlayerMarkerHit", theMarker, DeltaSCRAbrir)

addEventHandler ("onPlayerLogout", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local timerDetails = getTimerDetails (theTimers[source]) -- Nesta função, source = player que deslogou.
	setAccountData (thePreviousAccount, "DeltaSCR:Timers", timerDetails)
end)

addEventHandler ("onPlayerQuit", getRootElement(), function() -- OnPlayerQuit não chama o evento onPlayerLogout, vc deve salvar a data aqui também.
	if isTimer(theTimers[source]) then -- Nesta função, source = player que quitou do server.
		local timerDetails = getTimerDetails (theTimers[source])
		setAccountData (getPlayerAccount(source), "DeltaSCR:Timers", timerDetails) -- Salva a data na conta do player que quitou.
		killTimer(theTimers[source]) -- Cancela o timer.
	end
	theTimers[source] = nil -- Anula a variável do timer, para liberar espaço na memória.
end)

addEventHandler ("onPlayerLogin", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local dataTimer = getAccountData (theCurrentAccount, "DeltaSCR:Timers")
	if dataTimer then
		setAccountData (theCurrentAccount, "DeltaSCR:Timers", false) -- Remove o tempo restante da conta do player. Ela será salva novamente caso o player deslogue ou quite do server.
		theTimers[source] = setTimer (function () -- Nesta função, source = player que logou.
			theTimers[source] = nil
		end, dataTimer, 1) -- Recria o timer com o tempo restante que estava salvo.
	end
end)

 

Edited by Lord Henry

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted
40 minutes ago, Lord Henry said:

local theTimers = {}

function DeltaSCRAbrir (theMarker, matchingDimension)
	if getPedOccupiedVehicle(source) == false then
		if isTimer(theTimers[source]) then
			outputChatBox ("╔═════════════════════════════════════════════════╗", source, 200, 50, 0)
			outputChatBox ("ERRO: #FFFFFFVocê já resgatou seu bônus diario, aguarde para resgatar o próximo", source, 200, 50, 0, true)
			outputChatBox ("╚═════════════════════════════════════════════════╝", source, 200, 50, 0)
		else
			theTimers[source] = setTimer (function ()
				theTimers[source] = nil
			end, 60000, 1) -- 1 minuto.
			triggerClientEvent (source, "DeltaSCR:Abrir", source)
		end
	end
end
addEventHandler ("onPlayerMarkerHit", theMarker, DeltaSCRAbrir)

addEventHandler ("onPlayerLogout", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local timerDetails = getTimerDetails (theTimers[source]) -- Nesta função, source = player que deslogou.
	setAccountData (thePreviousAccount, "DeltaSCR:Timers", timerDetails)
end)

addEventHandler ("onPlayerQuit", getRootElement(), function() -- OnPlayerQuit não chama o evento onPlayerLogout, vc deve salvar a data aqui também.
	if isTimer(theTimers[source]) then -- Nesta função, source = player que quitou do server.
		local timerDetails = getTimerDetails (theTimers[source])
		setAccountData (getPlayerAccount(source), "DeltaSCR:Timers", timerDetails) -- Salva a data na conta do player que quitou.
		killTimer(theTimers[source]) -- Cancela o timer.
	end
	theTimers[source] = nil -- Anula a variável do timer, para liberar espaço na memória.
end)

addEventHandler ("onPlayerLogin", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local dataTimer = getAccountData (theCurrentAccount, "DeltaSCR:Timers")
	if dataTimer then
		setAccountData (theCurrentAccount, "DeltaSCR:Timers", false) -- Remove o tempo restante da conta do player. Ela será salva novamente caso o player deslogue ou quite do server.
		theTimers[source] = setTimer (function () -- Nesta função, source = player que logou.
			theTimers[source] = nil
		end, dataTimer, 1) -- Recria o timer com o tempo restante que estava salvo.
	end
end)

 

Mas no evento "onPlayerMarkerHit", não teria que ser root no lugar de theMarker?

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

  • Moderators
Posted

Não. Só se vc quiser que a função ative em todos os markers do server.

Ah, se der erro é pq faltou vc criar o theMarker.

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted

A linha do Marker está assim:

local theMarker = createMarker (1409.666, -1790.515, 13.546 -1.0, "cylinder", 1.2, 200, 50, 0, 150)

 

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

  • Moderators
Posted

Ele quis dizer que está faltando a parte do render. Que tem os dxDraw.

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted (edited)
function DeltaSCRDX ()
	-- //BOTÃO
	dxDrawLine((screenW * 0.4414) - 1, (screenH * 0.5667) - 1, (screenW * 0.4414) - 1, screenH * 0.6167, tocolor(0, 0, 0, 255), 1, false)
	dxDrawLine(screenW * 0.5586, (screenH * 0.5667) - 1, (screenW * 0.4414) - 1, (screenH * 0.5667) - 1, tocolor(0, 0, 0, 255), 1, false)
	dxDrawLine((screenW * 0.4414) - 1, screenH * 0.6167, screenW * 0.5586, screenH * 0.6167, tocolor(0, 0, 0, 255), 1, false)
	dxDrawLine(screenW * 0.5586, screenH * 0.6167, screenW * 0.5586, (screenH * 0.5667) - 1, tocolor(0, 0, 0, 255), 1, false)
	dxDrawRectangle(screenW * 0.4414, screenH * 0.5667, screenW * 0.1172, screenH * 0.0500, tocolor(0, 180, 50, 255), false)
	
	dxDrawText("Resgatar", (screenW * 0.4414) - 1, (screenH * 0.5667) - 1, (screenW * 0.5586) - 1, (screenH * 0.6167) - 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Resgatar", (screenW * 0.4414) + 1, (screenH * 0.5667) - 1, (screenW * 0.5586) + 1, (screenH * 0.6167) - 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Resgatar", (screenW * 0.4414) - 1, (screenH * 0.5667) + 1, (screenW * 0.5586) - 1, (screenH * 0.6167) + 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Resgatar", (screenW * 0.4414) + 1, (screenH * 0.5667) + 1, (screenW * 0.5586) + 1, (screenH * 0.6167) + 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Resgatar", screenW * 0.4414, screenH * 0.5667, screenW * 0.5586, screenH * 0.6167, tocolor(255, 255, 255, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	
	-- //CANCELAR
	dxDrawLine((screenW * 0.4414) - 1, (screenH * 0.6367) - 1, (screenW * 0.4414) - 1, screenH * 0.6867, tocolor(0, 0, 0, 255), 1, false)
	dxDrawLine(screenW * 0.5586, (screenH * 0.6367) - 1, (screenW * 0.4414) - 1, (screenH * 0.6367) - 1, tocolor(0, 0, 0, 255), 1, false)
	dxDrawLine((screenW * 0.4414) - 1, screenH * 0.6867, screenW * 0.5586, screenH * 0.6867, tocolor(0, 0, 0, 255), 1, false)
	dxDrawLine(screenW * 0.5586, screenH * 0.6867, screenW * 0.5586, (screenH * 0.6367) - 1, tocolor(0, 0, 0, 255), 1, false)
	dxDrawRectangle(screenW * 0.4414, screenH * 0.6367, screenW * 0.1172, screenH * 0.0500, tocolor(200, 0, 0, 255), false)
	
	dxDrawText("Cancelar", (screenW * 0.4414) - 1, (screenH * 0.6367) - 1, (screenW * 0.5586) - 1, (screenH * 0.6867) - 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Cancelar", (screenW * 0.4414) + 1, (screenH * 0.6367) - 1, (screenW * 0.5586) + 1, (screenH * 0.6867) - 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Cancelar", (screenW * 0.4414) - 1, (screenH * 0.6367) + 1, (screenW * 0.5586) - 1, (screenH * 0.6867) + 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Cancelar", (screenW * 0.4414) + 1, (screenH * 0.6367) + 1, (screenW * 0.5586) + 1, (screenH * 0.6867) + 1, tocolor(0, 0, 0, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
	dxDrawText("Cancelar", screenW * 0.4414, screenH * 0.6367, screenW * 0.5586, screenH * 0.6867, tocolor(255, 255, 255, 255), 1.00, customFont, "center", "center", false, false, false, false, false)
end

function AbrirPainel ()
	if PainelDX then
		removeEventHandler ("onClientRender", getRootElement(), DeltaSCRDX)
		showChat(true)
		showCursor(false)
	else
		addEventHandler ("onClientRender", getRootElement(), DeltaSCRDX)
		showChat(false)
		showCursor(true)
	end
	PainelDX = not PainelDX
end
addEvent ("DeltaSCR:Abrir", true)
addEventHandler ("DeltaSCR:Abrir", getRootElement(), AbrirPainel)

-- // --

function DeltaSCRClicks (button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
    if PainelDX == true then
        if state == "down" then
            if isCursorOnElement (screenW * 0.4414, screenH * 0.5667, screenW * 0.1172, screenH * 0.0500) then
                givePlayerMoney(3000)
                AbrirPainel ()
                outputChatBox ("╔═════════════════════════════════════════════════╗", 200, 50, 0)
                outputChatBox ("INFO: #FFFFFFVocê resgatou seu bônus diário com sucesso", 200, 50, 0, true)
                outputChatBox ("╚═════════════════════════════════════════════════╝", 200, 50, 0)
            elseif isCursorOnElement (screenW * 0.4414, screenH * 0.6367, screenW * 0.1172, screenH * 0.0500) then
                AbrirPainel ()
            else
                AbrirPainel ()
            end
        end
    end
end
addEventHandler ("onClientClick", getRootElement(), DeltaSCRClicks)

 

Edited by #DeltaSCR

Minha resposta te ajudou? Por favor, não esqueça de avaliar - #DeltaSCR

Minha página no Facebook: Delta Scripting - MTA


"Viribus et honor"

  • Moderators
Posted (edited)

Verifiquei aqui e detectei alguns erros na parte server-side. Aparentemente o onPlayerMarkerHit só funciona anexado ao root mesmo, o que é bem estranho...

Também havia problemas com o timer, que não é capaz de obter source de outro evento, sendo necessário passar o source por parâmetro nele.

Então ficou assim:

local theTimers = {}
local theMarker = createMarker (1409.666, -1790.515, 12.6, "cylinder", 1.2, 200, 50, 0, 150)

function DeltaSCRAbrir (marker, matchingDimension)
	if marker == theMarker then
		if getPedOccupiedVehicle(source) == false then
			if isTimer(theTimers[source]) then
				outputChatBox ("╔═════════════════════════════════════════════════╗", source, 200, 50, 0)
				outputChatBox ("ERRO: #FFFFFFVocê já resgatou seu bônus diário, aguarde para resgatar o próximo", source, 200, 50, 0, true)
				outputChatBox ("╚═════════════════════════════════════════════════╝", source, 200, 50, 0)
			else
				theTimers[source] = setTimer (function (theSource)
					theTimers[theSource] = nil
				end, 60000, 1, source) -- 1 minuto.
				triggerClientEvent (source, "DeltaSCR:Abrir", source)
			end
		end
	end
end
addEventHandler ("onPlayerMarkerHit", getRootElement(), DeltaSCRAbrir)

addEventHandler ("onPlayerLogout", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local timerDetails = getTimerDetails (theTimers[source]) -- Nesta função, source = player que deslogou.
	setAccountData (thePreviousAccount, "DeltaSCR:Timers", timerDetails)
end)

addEventHandler ("onPlayerQuit", getRootElement(), function() -- OnPlayerQuit não chama o evento onPlayerLogout, vc deve salvar a data aqui também.
	if isTimer(theTimers[source]) then -- Nesta função, source = player que quitou do server.
		local timerDetails = getTimerDetails (theTimers[source])
		setAccountData (getPlayerAccount(source), "DeltaSCR:Timers", timerDetails) -- Salva a data na conta do player que quitou.
		killTimer(theTimers[source]) -- Cancela o timer.
	end
	theTimers[source] = nil -- Anula a variável do timer, para liberar espaço na memória.
end)

addEventHandler ("onPlayerLogin", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local dataTimer = getAccountData (theCurrentAccount, "DeltaSCR:Timers")
	if dataTimer then
		setAccountData (theCurrentAccount, "DeltaSCR:Timers", false) -- Remove o tempo restante da conta do player. Ela será salva novamente caso o player deslogue ou quite do server.
		theTimers[source] = setTimer (function (theSource) -- Nesta função, source = player que logou.
			theTimers[theSource] = nil
		end, dataTimer, 1, source) -- Recria o timer com o tempo restante que estava salvo.
	end
end)

 

Edited by Lord Henry
  • Thanks 1

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...