Jump to content

Mensaje cada 24 horas


Anzo

Recommended Posts

Posted

¿Cómo puedo hacer que el mensaje "Hola" aparezca cada vez que te logees en el servidor, pero que funcione solo si pasaron 24 horas?

Me refiero a algo así: El primer día que se inició el script y te logeas te sale el mensaje, pero si te deslogeas y vuelves a loguear no saldrá el mensaje hasta que pasen 24 horas, luego de que pasen, te logeas y sale el mensaje.

Posted
51 minutes ago, aka Blue said:

Yo creo que se tendría que hacer con un guardado. Guardar un tickCount y compararlo.

No me digas que hay que usar sqlite? ;v

Posted

La verdad, no sé si se podrían usar tablas. No he testeado a ver si cuando me desconecto y entro de nuevo sigue un valor, por lo tanto, SQLite para un dato creo que no es muy importante, podrías usar elementData, así:

-- Cuando se desconecte:
setElementData( player, "tiempo", getTickCount( ) + 86400000 )

-- Cuando se conecte
local tiempo = getElementData( player, "tiempo" ) or 0
if getTickCount( ) > tiempo or tiempo == 0 then
	outputChatBox( "Han pasado 24 horas" )
	setElementData( player, "tiempo", getTickCount( ) + 86400000 )
else
	outputChatBox( "No han pasado 24 horas" )
end

Creo que debería funcionar.

Posted
4 hours ago, aka Blue said:

La verdad, no sé si se podrían usar tablas. No he testeado a ver si cuando me desconecto y entro de nuevo sigue un valor, por lo tanto, SQLite para un dato creo que no es muy importante, podrías usar elementData, así:


-- Cuando se desconecte:
setElementData( player, "tiempo", getTickCount( ) + 86400000 )

-- Cuando se conecte
local tiempo = getElementData( player, "tiempo" ) or 0
if getTickCount( ) > tiempo or tiempo == 0 then
	outputChatBox( "Han pasado 24 horas" )
	setElementData( player, "tiempo", getTickCount( ) + 86400000 )
else
	outputChatBox( "No han pasado 24 horas" )
end

Creo que debería funcionar.

No va a funcionar porque se resetea el elementData.

@Anzo usa setTimer.

Posted
40 minutes ago, Gaberiel said:

No va a funcionar porque se resetea el elementData.

@Anzo usa setTimer.

Cuando se desconecto pongo el timer o cuando se logea?

Posted (edited)
5 hours ago, aka Blue said:

La verdad, no sé si se podrían usar tablas. No he testeado a ver si cuando me desconecto y entro de nuevo sigue un valor, por lo tanto, SQLite para un dato creo que no es muy importante, podrías usar elementData, así:


-- Cuando se desconecte:
setElementData( player, "tiempo", getTickCount( ) + 86400000 )

-- Cuando se conecte
local tiempo = getElementData( player, "tiempo" ) or 0
if getTickCount( ) > tiempo or tiempo == 0 then
	outputChatBox( "Han pasado 24 horas" )
	setElementData( player, "tiempo", getTickCount( ) + 86400000 )
else
	outputChatBox( "No han pasado 24 horas" )
end

Creo que debería funcionar.

No va a funcionar porque se resetea el elementData.

@Anzo usa setTimer.

Si mal no recuerdo el timer al estar en el server side no se borra porque al estar en el cliente siempre vas a cargarlo, pero el server side tiene que sincronizarse con el cliente antes de que inicie. Eso fue lo que me había dicho hace tiempo CiBeR

Edited by Gaberiel
  • MTA Team
Posted

Podes utilizar tablas server-side para almacenar datos temporales. Sino simplemente utiliza accountData. Cabe destacar que no podes usar el elemento player para guardar nada, mas bien deberías usar su cuenta o su serial, algun tipo de dato que no sea dinamico y mas bien estatico.

Posted

Tan difícil yo creo que no es:

addEventHandler( "onPlayerQuit", getRootElement( ),
	function( )
		local account = getPlayerAccount( source )
		if account and not isGuestAccount( account ) then
			local tiempo_guardar = getTickCount( ) + 86400000
			setAccountData( account, "tiempo.espera", tonumber( tiempo_guardar ) )
		end
	end
)

addEventHandler( "onPlayerLogin", getRootElement( ),
	function( _, cuenta )
		local data_tiempo = getAccountData( cuenta, "tiempo.espera" )
		if data_tiempo then
			if data_tiempo < getTickCount( ) then
				outputChatBox( "Han pasado 24 horas" )
			else
				outputChatBox( "No han pasado 24 horas" )
			end
		end
	end
)

 

Posted
5 hours ago, aka Blue said:

Tan difícil yo creo que no es:


addEventHandler( "onPlayerQuit", getRootElement( ),
	function( )
		local account = getPlayerAccount( source )
		if account and not isGuestAccount( account ) then
			local tiempo_guardar = getTickCount( ) + 86400000
			setAccountData( account, "tiempo.espera", tonumber( tiempo_guardar ) )
		end
	end
)

addEventHandler( "onPlayerLogin", getRootElement( ),
	function( _, cuenta )
		local data_tiempo = getAccountData( cuenta, "tiempo.espera" )
		if data_tiempo then
			if data_tiempo < getTickCount( ) then
				outputChatBox( "Han pasado 24 horas" )
			else
				outputChatBox( "No han pasado 24 horas" )
			end
		end
	end
)

 

Usa getRealTime().timestamp, ya que las tick count se reinician cuando el servidor se inicia.

Posted
2 minutes ago, aka Blue said:

@Tomas Eso pensaba yo, pero, timestamp devuelve milisegundos o qué, exactamente?

Ese devuelve un UNIX timestamp, la cantidad de segundos desde el primero de enero de 1970 a las 00:00:00 UTC.

  • MTA Team
Posted
2 hours ago, aka Blue said:

@Tomas Si, pero si se tiene que comparar tipo, si han pasado 24 horas del último timestamp guardado, ¿cómo tendría que hacerse?

24 horas tiene 86400 segundos. Tomando en cuenta que el UNIX Timestamp de getRealTime().timestamp devuelve los segundos que pasaron desde 1970 solo tienes que almacenar el current timestamp + 86400 segundos y luego comparar al momento de loguear si getRealTime().timestamp del momento del logueo es igual o mayor que el dato almacenado.

addEventHandler( "onPlayerQuit", getRootElement( ),
	function( )
		local account = getPlayerAccount( source )
		if account and not isGuestAccount( account ) then
			local tiempo_guardar = getRealTime().timestamp + 86400
			setAccountData( account, "tiempo.espera", tonumber( tiempo_guardar ) )
		end
	end
)

addEventHandler( "onPlayerLogin", getRootElement( ),
	function( _, cuenta )
		local data_tiempo = getAccountData( cuenta, "tiempo.espera" )
		if data_tiempo then
			if data_tiempo <= getRealTime().timestamp then
				outputChatBox( "Han pasado 24 horas" )
			else
				outputChatBox( "No han pasado 24 horas" )
			end
		end
	end
)

 

  • Recently Browsing   0 members

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