BRbugadao Posted February 25, 2024 Share Posted February 25, 2024 To criando um sistema sono pro meu servidor Como eu nao entendo praticamente nada de scripting, estou indo por tutoriais e logica, até o momento criei uma linha de codigo onde vc dorme e teoricamente te congelaria e colocaria uma imagem na sua tela escrita, voce dormiu Peguei base de um sistema de fome Open que achei por ai. O timer ocorre o freeze funciona, creio que quando eu setar a animação tambem, porém a imagem nao tem outras coisas que queria adicionar como um /dormir em markers para recuperar sono completo. O countdown do sistema esta baixo para testes server.lua ---------------------------------------------------------------- connection = dbConnect('sqlite', 'dados.sqlite') dbExec(connection, 'CREATE TABLE IF NOT EXISTS fs (conta, sono)') outputDebugString("Script iniciado com sucesso!", 3) addEventHandler ( "onPlayerLogin", root, function ( _, acc ) setTimer ( Carregar_FS, 50, 1, acc ) end ) function Carregar_FS(conta) if not isGuestAccount(conta) then if conta then local result = dbPoll(dbQuery(connection, 'SELECT * FROM fs WHERE conta = ?', getAccountName(conta)), - 1) local player = getAccountPlayer(conta) if #result ~= 0 then local sono = result[1]['sono'] setElementData(player, "sono", tonumber(sono)) else setElementData(player, "sono", tonumber(100)) end end end end function Iniciar_FS_Resource(res) if res == getThisResource() then for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then Carregar_FS(acc) end end end end addEventHandler("onResourceStart", getRootElement(), Iniciar_FS_Resource ) function Salvar_FS(conta) if conta then local sono = getElementData(source, "sono") or 100 local result = dbPoll(dbQuery(connection, 'SELECT * FROM fs WHERE conta = ?', getAccountName(conta)), - 1) if #result ~= 0 then dbExec(connection, 'UPDATE fs SET sono=? WHERE conta=?', sono, getAccountName(conta)) else dbExec(connection, 'INSERT INTO fs (conta, sono) VALUES(?, ?)', getAccountName(conta), sono) end end end function checksonoCount() for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then local sono = getElementData(player,"sono") or 0 setElementData(player, "sono", sono -1) if sono <= 10 then exports["n3xt_dxmessages"]:addBox(player, "Você precisa dormir.", "info") end if sono <= 0 then setElementData(player,"sono",1) setElementFrozen(player, true) triggerClientEvent(player, "exibirEfeitoVisual", resourceRoot, "SonoSystem/img/efeito.png") setPedAnimation(player, "BED", "BED_Loop_A", -1, true, false, false, false) setTimer(function() setElementFrozen(player, false) -- Descongela o jogador triggerClientEvent(player, "removerEfeitoVisual", resourceRoot) setPedAnimation(player, false) end, 100, 0) end end end end setTimer(checksonoCount,100,0) function Desligar_FS(res) if res == getThisResource() then for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount (player) if not isGuestAccount(acc) then Salvar_FS(acc) end end end end addEventHandler("onResourceStop", getRootElement(), Desligar_FS) function Sair_Servidor(quitType) local acc = getPlayerAccount(source) if not isGuestAccount(acc) then if acc then Salvar_FS(acc) end end end addEventHandler("onPlayerQuit", getRootElement(), Sair_Servidor) --------------------------------- Fim --------------------- client.lua -------------------------------------------------- local screenWidth, screenHeight = guiGetScreenSize() local renderEventHandler function exibirEfeitoVisual(path) if not path then return end local textura = dxCreateTexture(path) if not textura then return end renderEventHandler = addEventHandler("onClientRender", root, function() local playerScreenW, playerScreenH = guiGetScreenSize() local imageW, imageH = 200, 200 local x = (playerScreenW - imageW) / 2 local y = (playerScreenH - imageH) / 2 dxDrawImage(x, y, imageW, imageH, textura) end) end addEvent("exibirEfeitoVisual", true) addEventHandler("exibirEfeitoVisual", resourceRoot, function(path) exibirEfeitoVisual("SonoSystem/img/" .. path) end) function removerEfeitoVisual() if renderEventHandler then removeEventHandler("onClientRender", root, renderEventHandler) renderEventHandler = nil end end addEvent("removerEfeitoVisual", true) addEventHandler("removerEfeitoVisual", resourceRoot, removerEfeitoVisual) Link to comment
FernandoMTA Posted February 25, 2024 Share Posted February 25, 2024 @BRbugadao Opa tudo bom? Pf coloque o código dentro da caixa correspondente clicando nesse botão: fica muito mais fácil visualizar. Link to comment
BRbugadao Posted February 25, 2024 Author Share Posted February 25, 2024 (edited) Foi mal kkk é minha primeira vez aqui Segue server.lua connection = dbConnect('sqlite', 'dados.sqlite') dbExec(connection, 'CREATE TABLE IF NOT EXISTS fs (conta, sono)') outputDebugString("Script iniciado com sucesso!", 3) addEventHandler ( "onPlayerLogin", root, function ( _, acc ) setTimer ( Carregar_FS, 50, 1, acc ) end ) function Carregar_FS(conta) if not isGuestAccount(conta) then if conta then local result = dbPoll(dbQuery(connection, 'SELECT * FROM fs WHERE conta = ?', getAccountName(conta)), - 1) local player = getAccountPlayer(conta) if #result ~= 0 then local sono = result[1]['sono'] setElementData(player, "sono", tonumber(sono)) else setElementData(player, "sono", tonumber(100)) end end end end function Iniciar_FS_Resource(res) if res == getThisResource() then for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then Carregar_FS(acc) end end end end addEventHandler("onResourceStart", getRootElement(), Iniciar_FS_Resource ) function Salvar_FS(conta) if conta then local sono = getElementData(source, "sono") or 100 local result = dbPoll(dbQuery(connection, 'SELECT * FROM fs WHERE conta = ?', getAccountName(conta)), - 1) if #result ~= 0 then dbExec(connection, 'UPDATE fs SET sono=? WHERE conta=?', sono, getAccountName(conta)) else dbExec(connection, 'INSERT INTO fs (conta, sono) VALUES(?, ?)', getAccountName(conta), sono) end end end function checksonoCount() for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount(player) if not isGuestAccount(acc) then local sono = getElementData(player,"sono") or 0 setElementData(player, "sono", sono -1) if sono <= 10 then exports["n3xt_dxmessages"]:addBox(player, "Você precisa dormir.", "info") end if sono <= 0 then setElementData(player,"sono",1) setElementFrozen(player, true) triggerClientEvent(player, "exibirEfeitoVisual", resourceRoot, "SonoSystem/img/efeito.png") setPedAnimation(player, "BED", "BED_Loop_A", -1, true, false, false, false) setTimer(function() setElementFrozen(player, false) -- Descongela o jogador triggerClientEvent(player, "removerEfeitoVisual", resourceRoot) setPedAnimation(player, false) end, 100, 0) end end end end setTimer(checksonoCount,100,0) function Desligar_FS(res) if res == getThisResource() then for i, player in ipairs(getElementsByType("player")) do local acc = getPlayerAccount (player) if not isGuestAccount(acc) then Salvar_FS(acc) end end end end addEventHandler("onResourceStop", getRootElement(), Desligar_FS) function Sair_Servidor(quitType) local acc = getPlayerAccount(source) if not isGuestAccount(acc) then if acc then Salvar_FS(acc) end end end addEventHandler("onPlayerQuit", getRootElement(), Sair_Servidor) local screenWidth, screenHeight = guiGetScreenSize() local renderEventHandler function exibirEfeitoVisual(path) if not path then return end local textura = dxCreateTexture(path) if not textura then return end renderEventHandler = addEventHandler("onClientRender", root, function() local playerScreenW, playerScreenH = guiGetScreenSize() local imageW, imageH = 200, 200 local x = (playerScreenW - imageW) / 2 local y = (playerScreenH - imageH) / 2 dxDrawImage(x, y, imageW, imageH, textura) end) end addEvent("exibirEfeitoVisual", true) addEventHandler("exibirEfeitoVisual", resourceRoot, function(path) exibirEfeitoVisual("SonoSystem/img/" .. path) end) function removerEfeitoVisual() if renderEventHandler then removeEventHandler("onClientRender", root, renderEventHandler) renderEventHandler = nil end end addEvent("removerEfeitoVisual", true) addEventHandler("removerEfeitoVisual", resourceRoot, removerEfeitoVisual) Este é o client.lua Edited February 26, 2024 by Lord Henry Códigos convertidos de HTML para Lua. Link to comment
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