Jump to content

[AJUDA] salario VIP


Recommended Posts

O script era para  O player que possui o vip ( ouro, platina, diamante, rubi) Receberá uma quantia em dinheiro todo dia. mas ta bugando tem hora que pode pegar sempre. nao to conseguindo resolver me ajuda.

local paydayCommand = "salario"
local baseSalary = 5000
local timers = {}
local milisseconds = 60000 --// 60sec
local hour = milisseconds * 60 --// 1h
local theTime = hour * 24 --// 1d

function takePayDay(thePlayer, cmd)
	local playerTime = timers[thePlayer]
	if not (playerTime) then
		timers[thePlayer] = setTimer(function()
			timers[thePlayer] = nil
		end, theTime, 1)
	elseif playerTime and isTimer(playerTime) then
		outputChatBox ("╔═════════════════════════════════════════════════╗", thePlayer, 255, 0, 0)
		outputChatBox ("ERRO: #FFFFFFNo momento você não pode utilizar esse comando.", thePlayer, 255, 0, 0, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", thePlayer, 255, 0, 0)
		return
	end

	local accountName = getAccountName(getPlayerAccount(thePlayer))
	if isObjectInACLGroup("user."..accountName, aclGetGroup("Ouro")) then
		givePlayerMoney(thePlayer, baseSalary)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..baseSalary.."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	elseif isObjectInACLGroup("user."..accountName, aclGetGroup("Platina")) then
		givePlayerMoney(thePlayer, baseSalary + 750)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..(baseSalary + 750).."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	elseif isObjectInACLGroup("user."..accountName, aclGetGroup("Diamante")) then
		givePlayerMoney(thePlayer, baseSalary + 1500)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..(baseSalary + 1500).."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	elseif isObjectInACLGroup("user."..accountName, aclGetGroup("Rubi")) then
		givePlayerMoney(thePlayer, baseSalary + 2500)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..(baseSalary + 2500).."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	end
end
addCommandHandler(paydayCommand, takePayDay)


addEventHandler ("onPlayerLogout", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local timerDetails = getTimerDetails (timers[source])
	setAccountData (thePreviousAccount, "DeltaSCR:Timers", timerDetails)
end)

addEventHandler ("onPlayerQuit", getRootElement(), function()
	if isTimer(timers[source]) then
		local timerDetails = getTimerDetails (timers[source])
		setAccountData (getPlayerAccount(source), "DeltaSCR:Timers", timerDetails)
		killTimer(timers[source])
	end
	timers[source] = nil
end)

addEventHandler ("onPlayerLogin", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local dataTimer = getAccountData (theCurrentAccount, "DeltaSCR:Timers")
	if dataTimer then
		setAccountData (theCurrentAccount, "DeltaSCR:Timers", false)
		timers[source] = setTimer (function ()
			timers[source] = nil
		end, dataTimer, 1)
	end
end)

 

Link to comment
  • Other Languages Moderators

Não use setTimers para isso.

  • Se o jogador reconectar no servidor, ele será outro elemento, logo o timer dele será perdido.
  • Não é recomendável usar setTimer para grandes períodos de tempo, eles consomem muito processamento do servidor para se manterem ativos.
  • Use o timestamp do getRealTime. Assim você será capaz de salvar o instante que o jogador pegou a grana pela última vez na conta dele, e quando ele tentar novamente, verificar se o momento salvo já faz mais do que 24 horas passadas.
Link to comment

Assim?

local paydayCommand = "salario"
local baseSalary = 5000
local timers = {}
local milisseconds = 60000 --// 60sec
local hour = milisseconds * 60 --// 1h
local theTime = hour * 24 --// 1d

function takePayDay(thePlayer, cmd)
	local playerTime = timers[thePlayer]
	if not (playerTime) then
		timers[thePlayer] = timestamp(function()
			timers[thePlayer] = nil
		end, theTime, 1)
	elseif playerTime and isTimer(playerTime) then
		outputChatBox ("╔═════════════════════════════════════════════════╗", thePlayer, 255, 0, 0)
		outputChatBox ("ERRO: #FFFFFFNo momento você não pode utilizar esse comando.", thePlayer, 255, 0, 0, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", thePlayer, 255, 0, 0)
		return
	end

	local accountName = getAccountName(getPlayerAccount(thePlayer))
	if isObjectInACLGroup("user."..accountName, aclGetGroup("Ouro")) then
		givePlayerMoney(thePlayer, baseSalary)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..baseSalary.."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	elseif isObjectInACLGroup("user."..accountName, aclGetGroup("Platina")) then
		givePlayerMoney(thePlayer, baseSalary + 750)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..(baseSalary + 750).."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	elseif isObjectInACLGroup("user."..accountName, aclGetGroup("Diamante")) then
		givePlayerMoney(thePlayer, baseSalary + 1500)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..(baseSalary + 1500).."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	elseif isObjectInACLGroup("user."..accountName, aclGetGroup("Rubi")) then
		givePlayerMoney(thePlayer, baseSalary + 2500)
		outputChatBox ("╔═════════════════════════════════════════════════╗", root, 0, 200, 75)
		outputChatBox ("INFO: #FFFFFFO jogador "..getPlayerName(thePlayer).." #ffffffresgatou o seu sálario no valor de R$"..(baseSalary + 2500).."", root, 0, 200, 75, true)
		outputChatBox ("╚═════════════════════════════════════════════════╝", root, 0, 200, 75)
	end
end
addCommandHandler(paydayCommand, takePayDay)


addEventHandler ("onPlayerLogout", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local timerDetails = getTimerDetails (timers[source])
	setAccountData (thePreviousAccount, "DeltaSCR:Timers", timerDetails)
end)

addEventHandler ("onPlayerQuit", getRootElement(), function()
	if isTimer(timers[source]) then
		local timerDetails = getTimerDetails (timers[source])
		setAccountData (getPlayerAccount(source), "DeltaSCR:Timers", timerDetails)
		killTimer(timers[source])
	end
	timers[source] = nil
end)

addEventHandler ("onPlayerLogin", getRootElement(), function (thePreviousAccount, theCurrentAccount)
	local dataTimer = getAccountData (theCurrentAccount, "DeltaSCR:Timers")
	if dataTimer then
		setAccountData (theCurrentAccount, "DeltaSCR:Timers", false)
		timers[source] = timestamp (function ()
			timers[source] = nil
		end, dataTimer, 1)
	end
end)

 

Link to comment
  • Other Languages Moderators

N.

Vou dar um exemplo:

function pegarGrana (thePlayer, cmd)
	if isGuestAccount (getPlayerAccount (thePlayer)) then return end -- Se o jogador está deslogado, então cancela essa função e nada acontece.
	local account = getPlayerAccount (thePlayer) -- 'account' recebe a conta que o jogador que executou o comando está logado.
	local agora = getRealTime().timestamp -- 'agora' recebe um número bem grande, que é a quantidade de segundos que se passaram desde 01/01/1970
	local antes = getAccountData (account, "ultimaGrana") -- 'antes' recebe o que estava salvo na conta do jogador, se não existir essa data, recebe false. (sempre será uma string caso exista, mesmo se você salvar um número)
	if (antes) then -- Se existe uma data na conta, então:
		if ((agora - tonumber(antes)) > 86400) then -- Se a diferença de 'agora' e de 'antes' for maior que 86400 segundos (1 dia), então:
			setAccountData (account, "ultimaGrana", agora) -- Salva o 'agora' na conta do jogador.
			outputChatBox ("Você pegou o dinheiro. Poderá pegar novamente daqui a 24 horas.", thePlayer)
			givePlayerMoney (thePlayer, 10000) -- Dá o dinheiro pro jogador.
		else -- Se a diferença de 'agora' e de 'antes' não for maior que 86400 segundos, significa que não faz 24 horas que o dinheiro foi pego. Então:
			outputChatBox ("Você precisa esperar mais tempo para poder pegar o dinheiro.", thePlayer)
		end
	else -- Se não existe essa data na conta do jogador (ele nunca pegou a grana antes), então:
		setAccountData (account, "ultimaGrana", agora) -- Salva o 'agora' na conta do jogador.
		outputChatBox ("Você pegou o dinheiro. Poderá pegar novamente daqui a 24 horas.", thePlayer)
		givePlayerMoney (thePlayer, 10000) -- Dá o dinheiro pro jogador.
	end
end
addCommandHandler ("pegar", pegarGrana) -- Comando pra ativar essa função: /pegar

 

Edited by Lord Henry
Corrigida indentação e adicionada verificação de guest account.
Link to comment

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...