Jump to content

guiSetEnabled Group


Recommended Posts

Posted

Olá neste código tentei privar um botão apenas para uma acl só que não deu certo, o botão não desabilita.

 

-- Server-Side

function Aclpainel(thePlayer)
  accountname = getAccountName(getPlayerAccount(thePlayer))
  if isObjectInACLGroup("user." .. accountname, aclGetGroup("Consolee") or aclGetGroup("SCMD-PMERJ")) then --> Gruop que vai poder abrir o painel !
  triggerClientEvent(thePlayer,"teste",thePlayer)	    
  end
end
-- Client-Side

function Gerenciamento (on_off)
	guiSetEnabled (button, on_off)

end
addEvent("teste", true)
addEventHandler("teste", root, Gerenciamento)

button = guiCreateButton(136, 192, 20, 39, "", false)

Help

Meu comentário foi útil? Deixe um Thanks :D

Posted
-- Client-Side
button = guiCreateButton(136, 192, 20, 39, "", false)

function fToggleButtonEnabled(bool)
	guiSetEnabled(button, bool)
end
addEvent("toggleButtonEnabled", true)
addEventHandler("toggleButtonEnabled", resourceRoot, fToggleButtonEnabled)
-- Server-Side
function aclPanel(thePlayer)
	local accName = getAccountName(getPlayerAccount(thePlayer))
	if isObjectInACLGroup("user." .. accName, aclGetGroup("Console") or aclGetGroup("SCMD-PMERJ")) then
		triggerClientEvent(thePlayer, "toggleButtonEnabled", resourceRoot, true) -- botao ativado
	else	
		triggerClientEvent(thePlayer, "toggleButtonEnabled", resourceRoot, false) -- botao desativado
	end
end

 

  • Like 1
  • Moderators
Posted

Algo parece errado. Não existe nada ativando a função server-side. Desse modo, thePlayer não existe.

@danilin você esqueceu de passar o valor de on_off pelo seu triggerClientEvent.

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

Posted

do modo que o MainSCR Montou não deu certo. acabei só copiando e colando, mais o código que ele monto parecia está funcional :\

 

Meu comentário foi útil? Deixe um Thanks :D

Posted
3 hours ago, danilin said:

do modo que o MainSCR Montou não deu certo. acabei só copiando e colando, mais o código que ele monto parecia está funcional ?

 

Você precisa mostrar o resto do código para podermos verificar se não tem algo errado...

Posted

não tem erro no código, o botão só não habilita/desabilita, Lord arrumei os erros também não foi, tentei também.

-- Server Side
function aclPanel(thePlayer)
	local accName = getAccountName(getPlayerAccount(thePlayer))
	if isObjectInACLGroup("user." .. accName, aclGetGroup("Console") or aclGetGroup("SCMD-PMERJ")) then

	    triggerClientEvent(thePlayer, "teste", root, false) -- botao ativado
	else	
		triggerClientEvent(thePlayer, "teste", root, true) -- botao desativado
	end
end
end
-- Client Side


button = guiCreateButton(136, 192, 20, 39, "", false)
guiSetVisible(button, false)

function open ()
if (guiGetVisible(button) == false) then
guiSetVisible(button, true)
else
guiSetVisible(button, false)
end
end
addCommandHandler("a", open)

function Gerenciamento (on_off)
	if (guiGetEnabled (button) == false) then
	guiSetEnabled(button, true)
	else
	guiSetEnabled(button, false)
end
end
addEvent("teste", true)
addEventHandler("teste", root, Gerenciamento)

que também não funfo

Meu comentário foi útil? Deixe um Thanks :D

Posted (edited)
-- Client-side

local SCREEN 	= { guiGetScreenSize ( ) }
local WIDTH		= 180
local HEIGHT	= 25

addEventHandler( "onClientResourceStart", resourceRoot, function ( )
	theButton = guiCreateButton ( SCREEN[1] - ( WIDTH + 5 ), SCREEN[2] / 2 - HEIGHT / 2, WIDTH, HEIGHT, "Teste", false )
	guiSetVisible ( theButton, false )
end )

addCommandHandler( "open", function ( )
	local isVisible = guiGetVisible ( theButton )
	guiSetVisible ( theButton, not isVisible )
	triggerServerEvent( "checkACL", localPlayer )
end )

addEvent( "toggleButton", true )
addEventHandler( "toggleButton", root, function ( string )
	local bool = string == "enableButton" and true or false
	guiSetEnabled ( theButton, bool )
end )
-- Server-side
addEvent( "checkACL", true )
addEventHandler( "checkACL", root, function ( )
	local account = getPlayerAccount ( source )
	if isGuestAccount ( account ) then
		return false
	end
	
	local accountName = getAccountName ( account )
	if isObjectInACLGroup ( "user." .. accountName, aclGetGroup( "Console" ) ) then
		triggerClientEvent ( source, "toggleButton", source, "enableButton" )
	else
		triggerClientEvent ( source, "toggleButton", source, "disableButton" )
	end
end )

 

Edited by asrzk
  • Thanks 1

Hello, world.


Tutorial sobre interação de BOTs do Discord com o seu servidor - Visitar (Brazilian Portuguese)
Tutorial sobre tabelas - Visitar (Brazilian Portuguese)
Tutorial sobre banco de dados - Visitar (Brazilian Portuguese)
  • Moderators
Posted (edited)
2 hours ago, danilin said:

não tem erro no código, o botão só não habilita/desabilita, Lord arrumei os erros também não foi, tentei também.


-- Server Side
function aclPanel(thePlayer)
	local accName = getAccountName(getPlayerAccount(thePlayer))
	if isObjectInACLGroup("user." .. accName, aclGetGroup("Console") or aclGetGroup("SCMD-PMERJ")) then
		triggerClientEvent(thePlayer, "teste", root, false) -- botao ativado
	else	
		triggerClientEvent(thePlayer, "teste", root, true) -- botao desativado
	end
end
end -- ERRO, 'end' sem escopo em aberto.

 

Nunca use root como terceiro parâmetro de um triggerClientEvent, assim como avisa a Wiki.
Você deveria ler a Wiki para saber como essa função funciona.

Note: To save client CPU, you should avoid setting sourceElement to the root element where possible. Using resourceRoot is usually sufficient if the event is handled by the same resource on the client.

Nota: Para economizar o uso da CPU do cliente, você deve evitar de colocar o parâmetro sourceElement como root onde for possível. Usar resourceRoot é geralmente suficiente se o evento é ativado pelo mesmo resource no cliente.

Essa função funciona assim:

-- theClient = O cliente (jogador) onde a função será ativada.
-- "teste" = Nome do evento que será executado no client. Precisa estar obrigatoriamente entre aspas.
-- sourceElement = O elemento ativador dessa função, que será o source no client. Geralmente é o mesmo que theClient, mas também pode ser um veículo, etc.
-- parametro1 = o valor do primeiro parâmetro da função no client. Pode ser qualquer valor exceto outra função.

triggerClientEvent (theClient, "teste", sourceElement, parametro1)

CLIENT

function qualquerCoisa (argumento1) -- argumento1 é o valor que foi passado no 'parametro1' do triggerClientEvent
	outputChatBox ("Evento 'teste' ativado no client com argumento: "..tostring(argumento1))
end
addEvent ("teste", true) -- Cria o evento "teste" e permite que ele seja transmitido para os outros scripts.
addEventHandler ("teste", getRootElement(), qualquerCoisa) -- Ao chamar o evento "teste", executa a função qualquerCoisa.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Exemplo:

Server-side:

function verificaACL (thePlayer)
	local accountName = getAccountName (getPlayerAccount (thePlayer))
	if isObjectInACLGroup ("user."..accountName, aclGetGroup("Console")) or isObjectInACLGroup ("user."..accountName, aclGetGroup("SCMD-PMERJ")) then
		outputChatBox ("Botão liberado.", thePlayer)
		triggerClientEvent (thePlayer, "teste", thePlayer, true)
	else
		outputChatBox ("Botão bloqueado.", thePlayer)
		triggerClientEvent (thePlayer, "teste", thePlayer, false)
	end
end
addCommandHandler ("a", verificaACL)

Client-side:

x, y = guiGetScreenSize ()
botao = guiCreateButton (x/2 - 50, y/2 - 15, 100, 30, "TESTE", false)
guiSetVisible (botao, false)

function mostrarBotao (state)
	outputChatBox ("Evento 'teste' ativado no client com argumento: "..tostring(state))
	guiSetVisible (botao, true)
	guiSetEnabled (botao, state)
end
addEvent ("teste", true)
addEventHandler ("teste", getRootElement(), mostrarBotao)

OBS: Use o comando /a para fazer o botão aparecer na tela.

Edited by Lord Henry
  • Like 1
  • 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.

Posted
18 minutes ago, Lord Henry said:

Nunca use root como terceiro parâmetro de um triggerClientEvent, assim como avisa a Wiki.
Você deveria ler a Wiki para saber como essa função funciona.

Note: To save client CPU, you should avoid setting sourceElement to the root element where possible. Using resourceRoot is usually sufficient if the event is handled by the same resource on the client.

Nota: Para economizar o uso da CPU do cliente, você deve evitar de colocar o parâmetro sourceElement como root onde for possível. Usar resourceRoot é geralmente suficiente se o evento é ativado pelo mesmo resource no cliente.

Essa função funciona assim:

SERVER


-- theClient = O cliente (jogador) onde a função será ativada.
-- "teste" = Nome do evento que será executado no client. Precisa estar obrigatoriamente entre aspas.
-- sourceElement = O elemento ativador dessa função, que será o source no client. Geralmente é o mesmo que theClient, mas também pode ser um veículo, etc.
-- parametro1 = o valor do primeiro parâmetro da função no client. Pode ser qualquer valor exceto outra função.

triggerClientEvent (theClient, "teste", sourceElement, parametro1)

CLIENT


function qualquerCoisa (argumento1) -- argumento1 é o valor que foi passado no 'parametro1' do triggerClientEvent
	outputChatBox ("Evento 'teste' ativado no client com argumento: "..tostring(argumento1))
end
addEvent ("teste", true) -- Cria o evento "teste" e permite que ele seja transmitido para os outros scripts.
addEventHandler ("teste", getRootElement(), qualquerCoisa) -- Ao chamar o evento "teste", executa a função qualquerCoisa.

 

Server-side:


function verificaACL (thePlayer)
	local accountName = getAccountName (getPlayerAccount (thePlayer))
	if isObjectInACLGroup ("user."..accountName, aclGetGroup("Console")) or isObjectInACLGroup ("user."..accountName, aclGetGroup("SCMD-PMERJ")) then
		outputChatBox ("Botão liberado.", thePlayer)
		triggerClientEvent (thePlayer, "teste", thePlayer, true)
	else
		outputChatBox ("Botão bloqueado.", thePlayer)
		triggerClientEvent (thePlayer, "teste", thePlayer, false)
	end
end
addCommandHandler ("a", verificaACL)

Client-side:


x, y = guiGetScreenSize ()
botao = guiCreateButton (x/2 - 50, y/2 - 15, 100, 30, "TESTE", false)
guiSetElementVisible (botao, false)

function mostrarBotao (state)
	outputChatBox ("Evento 'teste' ativado no client com argumento: "..tostring(argumento1))
	guiSetVisible (botao, true)
	guiSetEnabled (botao, state)
end
addEvent ("teste", true)
addEventHandler ("teste", getRootElement(), mostrarBotao)

OBS: Use o comando /a para fazer o botão aparecer na tela.

Vou dar gostei pra agradecer a ajuda do lord pois o Danilin costuma não ser agradecido pelas ajudas que recebe..

  • Like 1

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