MRXBBC Posted April 30, 2020 Posted April 30, 2020 (edited) Gostaria de fazer um painel vip com keys aleatória que teria um data de validade setada pelo console por exemplo: eu quero uma key que só tenha validade por 2 dias ai eu vou lá e seto, alguém pode me dá uma ajuda Server value = nil local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end function Teste ( ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then local Key = generateString(12) value = Key outputChatBox(Key.."Nova Key",root) else outputChatBox("Fora",root) end end addEvent ("Gen:Set", true) addEventHandler ("Gen:Set", root, Teste) addCommandHandler ( "Usar" , function ( player ) if ( value ~= nil ) then outputChatBox("Sua Chave: "..tostring(value),source,0,255,0,true) setElementData ( player, "Vip", "Desbloqueado" ) else outputChatBox("Chave inexistente",player,255,0,0,true) end end ) ; Edited April 30, 2020 by MRXBBC
Angelo Pereira Posted April 30, 2020 Posted April 30, 2020 Teoricamente, o que eu consegui compreende, foi que, você apenas quer gerar um key por vez. Então, nessa key gerada, a pessoa apenas dará o comando, caso a key existir, já é ativado o vip na conta dela. Para adicionar uma validade, basta : local key = nil local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end function Teste ( ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then key = generateString(12) outputChatBox("Foi Gerado Uma Nova KEY: "..key.."", source, 255, 255, 255, true) if isTimer(tempo_remover_key) then killTimer(tempo_remover_key) end tempo_remover_key = setTimer ( function ( ) --/> AQUI key = nil --/> AQUI end, 60000*60*24*2, 1) --/> AQUI else outputChatBox("Acesso Negado.", source, 255, 255, 255, true) end end addEvent ("Gen:Set", true) addEventHandler ("Gen:Set", root, Teste) addCommandHandler ( "Usar", function ( player ) if ( key ~= nil ) then outputChatBox("Sua Chave: "..tostring(key), player, 0, 255, 0, true) setElementData ( player, "Vip", "Desbloqueado" ) killTimer(tempo_remover_key) --/> Kill Timer. key = nil --/> Nil Variável Key. else outputChatBox("Chave Inexistente.", player, 255, 0, 0, true) end end)
MRXBBC Posted April 30, 2020 Author Posted April 30, 2020 5 minutes ago, Angelo Pereira said: Teoricamente, o que eu consegui compreende, foi que, você apenas quer gerar um key por vez. Então, nessa key gerada, a pessoa apenas dará o comando, caso a key existir, já é ativado o vip na conta dela. Para adicionar uma validade, basta : local key = nil local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } function generateString ( len ) if tonumber ( len ) then math.randomseed ( getTickCount () ) local str = "" for i = 1, len do local charlist = allowed[math.random ( 1, 3 )] str = str .. string.char ( math.random ( charlist[1], charlist[2] ) ) end return str end return false end function Teste ( ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then key = generateString(12) outputChatBox("Foi Gerado Uma Nova KEY: "..key.."", source, 255, 255, 255, true) if isTimer(tempo_remover_key) then killTimer(tempo_remover_key) end tempo_remover_key = setTimer ( function ( ) --/> AQUI key = nil --/> AQUI end, 60000*60*24*2, 1) --/> AQUI else outputChatBox("Acesso Negado.", source, 255, 255, 255, true) end end addEvent ("Gen:Set", true) addEventHandler ("Gen:Set", root, Teste) addCommandHandler ( "Usar", function ( player ) if ( key ~= nil ) then outputChatBox("Sua Chave: "..tostring(key), player, 0, 255, 0, true) setElementData ( player, "Vip", "Desbloqueado" ) killTimer(tempo_remover_key) --/> Kill Timer. key = nil --/> Nil Variável Key. else outputChatBox("Chave Inexistente.", player, 255, 0, 0, true) end end) se eu quiser setar o dia eu vu setar tempo_remover_key em milisegundos?
Angelo Pereira Posted April 30, 2020 Posted April 30, 2020 28 minutes ago, MRXBBC said: se eu quiser setar o dia eu vu setar tempo_remover_key em milisegundos? Ele estará sempre em 2 dias, se quiser trazer quantos dias do client-side, para o server-side, então fará basicamente assim : function Teste ( dia ) --/> Trazer os dias do client.... local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then local dia = tonumber(dia) key = generateString(12) outputChatBox("Foi Gerado Uma Nova KEY: "..key.."", source, 255, 255, 255, true) if isTimer(tempo_remover_key) then killTimer(tempo_remover_key) end tempo_remover_key = setTimer ( function ( ) --/> AQUI key = nil --/> AQUI end, 60000*60*24*dia, 1) --/> AQUI, fará a soma. else outputChatBox("Acesso Negado.", source, 255, 255, 255, true) end end addEvent ("Gen:Set", true) addEventHandler ("Gen:Set", root, Teste 1
Other Languages Moderators Lord Henry Posted April 30, 2020 Other Languages Moderators Posted April 30, 2020 (edited) Para longos períodos de tempo, usa-se getRealTime().timestamp em vez de setTimer. Até porque se alguém der restart no resource sem querer, o setTimer é perdido e o VIP vai ficar lá pra sempre. Com o timestamp, vc salva o momento que o VIP foi atribuído na conta do jogador com um setAccount. E depois sempre que ele logar, verifica se já se passaram os 2 dias desde o momento salvo na conta. Se passou, remove o VIP ao logar. Edited April 30, 2020 by Lord Henry 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now