Jump to content

Help with Gridlist


Citryon25

Recommended Posts

I am creating a system where the player can send a message that will be displayed in a gridlist in a panel, but the messages that have been sent are not displayed, only when it's me that I send.

 

 

 

SCRIPT:  [CLIENT-SIDE]

 
GUIEditor = {
    label = {}
}
 
        janela_oc = guiCreateWindow((screenW - 315) / 2, (screenH - 352) / 2, 315, 352, "Chamar Policia", false)
        guiWindowSetSizable(janela_oc, false)
        guiSetProperty(janela_oc, "CaptionColour", "FF0718F8")

        edit_oc = guiCreateEdit(101, 38, 149, 27, "", false, janela_oc)
        GUIEditor.label[3] = guiCreateLabel(29, 42, 76, 29, "Ocorrência:", false, janela_oc)
        guiSetFont(GUIEditor.label[3], "default-bold-small")
        GUIEditor.label[4] = guiCreateLabel(29, 87, 144, 15, "Conte o que aconteceu:", false, janela_oc)
        guiSetFont(GUIEditor.label[4], "default-bold-small")
        memo_oc = guiCreateMemo(29, 111, 252, 191, "", false, janela_oc)
        enviar_oc = guiCreateButton(35, 312, 105, 25, "Enviar", false, janela_oc)
        guiSetProperty(enviar_oc, "NormalTextColour", "FF43D00B")
        fechar_ocs = guiCreateButton(157, 312, 105, 25, "Fechar", false, janela_oc)
        guiSetProperty(fechar_ocs, "NormalTextColour", "FFEF0000")
		
		guiSetVisible(janela_oc, false)
		
		        janela_ocs = guiCreateWindow((screenW - 411) / 2, (screenH - 439) / 2, 411, 439, "Ocorrências", false)
        guiWindowSetSizable(janela_ocs, false)
        guiSetProperty(janela_ocs, "CaptionColour", "FF2C1EE0")

        grid_ocs = guiCreateGridList(23, 32, 367, 284, false, janela_ocs)
        guiGridListAddColumn(grid_ocs, "Jogador", 0.5)
        guiGridListAddColumn(grid_ocs, "Ocorrência", 0.5)
        guiGridListAddColumn(grid_ocs, "Descrição", 0.5)
        ver_oc = guiCreateButton(51, 343, 114, 35, "Ver Ocorrência", false, janela_ocs)
        guiSetProperty(ver_oc, "NormalTextColour", "FF3BEB12")
        del_oc = guiCreateButton(234, 343, 132, 35, "Remover Ocorrência", false, janela_ocs)
        guiSetProperty(del_oc, "NormalTextColour", "FFDC0000")
        limpar_oc = guiCreateButton(142, 388, 124, 37, "Limpar Ocorrências", false, janela_ocs)
        guiSetProperty(limpar_oc, "NormalTextColour", "FFD75406")
		
		guiSetVisible(janela_ocs, false)
		
		        veroc = guiCreateWindow((screenW - 377) / 2, (screenH - 362) / 2, 377, 362, "Ver Ocorrência", false)
        guiWindowSetSizable(veroc, false)
        guiSetProperty(veroc, "CaptionColour", "FF0A2FD0")

        ocd = guiCreateEdit(99, 74, 176, 33, "", false, veroc)
        guiEditSetReadOnly(ocd, true)
        GUIEditor.label[1] = guiCreateLabel(22, 84, 67, 18, "Ocorrência:", false, veroc)
        guiSetFont(GUIEditor.label[1], "default-bold-small")
        memo = guiCreateMemo(93, 133, 240, 148, "", false, veroc)
        guiMemoSetReadOnly(memo, true)
        GUIEditor.label[2] = guiCreateLabel(22, 139, 67, 18, "Descrição:", false, veroc)
        guiSetFont(GUIEditor.label[2], "default-bold-small")
        voltar_btn = guiCreateButton(131, 305, 124, 37, "Voltar", false, veroc)
        guiSetProperty(voltar_btn, "NormalTextColour", "FFD86B01")
        joglabel = guiCreateLabel(28, 32, 184, 32, "Jogador:", false, veroc)
        guiSetFont(joglabel, "default-bold-small")
		guiSetVisible(veroc, false)
	
addCommandHandler("190",
function()
guiSetVisible(janela_oc, true)
showCursor(true)
end
)

function fecharOc()
guiSetVisible(janela_oc, false)
showCursor(false)
end
addEventHandler("onClientGUIClick", fechar_ocs, fecharOc)
	
function criarOcorrencia()  -- SEND REPORT FOR 'janela_ocs'
if getElementData (getLocalPlayer(), "chamou", true) then outputChatBox ('#c1c1c1Aguarde #ff00005 #c1c1c1minutos para chamar policia novamente.',255,255,255,true) return end
	if guiGetVisible(janela_oc) == true then
		if guiGetText(edit_oc) and guiGetText(memo_oc) then
			local playerName = getPlayerName(getLocalPlayerlayer())
			local oc = guiGetText(edit_oc)
			local desc = guiGetText(memo_oc)
			local row_oc = guiGridListAddRow(grid_ocs, playerName:gsub('#%x%x%x%x%x%x', ''), oc, desc)
			guiSetVisible(janela_oc, false)
			showCursor(false)
			convertTextToSpeech("Você enviou uma ocorrência", "pt")
			setElementData(getLocalPlayer(), "chamou", true)
			setTimer (setElementData, 300000, 1, getLocalPlayer(), "chamou", false)
		end
	end
end
addEventHandler("onClientGUIClick", enviar_oc, criarOcorrencia)

function verOcorrencia()
if guiGetVisible(janela_ocs) == true then
local playerName = guiGridListGetItemText ( grid_ocs, guiGridListGetSelectedItem (grid_ocs), 1 )
local oc = guiGridListGetItemText ( grid_ocs, guiGridListGetSelectedItem (grid_ocs), 2 )
local desc = guiGridListGetItemText ( grid_ocs, guiGridListGetSelectedItem (grid_ocs), 3 )
guiSetVisible(janela_ocs, false)
guiSetVisible(veroc, true)
guiSetText(joglabel, "Jogador: ".. playerName)
guiSetText(ocd, oc)
guiSetText(memo, desc)
end
end
addEventHandler("onClientGUIClick", ver_oc, verOcorrencia)

 

Link to post

Hello. I can't see any triggerServerEvent. Client side scripts run only on the clients computer and are NOT synced to the others. You have to call server side, find the player who has to get the message and then triggerClientEvent to it, so it's synced for him.

 

triggerClientEvent(theTargetPlayersPlayerElement, "TheEventNameOfTheClientEvent", resourceRoot, Optional, Arguments)

 

Link to post
51 minutes ago, StormFighter said:

Hello. I can't see any triggerServerEvent. Client side scripts run only on the clients computer and are NOT synced to the others. You have to call server side, find the player who has to get the message and then triggerClientEvent to it, so it's synced for him.

 


triggerClientEvent(theTargetPlayersPlayerElement, "TheEventNameOfTheClientEvent", resourceRoot, Optional, Arguments)

 

 

But then I would just use a trigger on the serverside? Could you give me an example of how it would work in the code, please?

Link to post
10 hours ago, Citryon25 said:

 

But then I would just use a trigger on the serverside? Could you give me an example of how it would work in the code, please?

Yes. Then you use a trigger on server side, with the target player as the target of the trigger. So like:

function sendMsg(targetPlayer, theMessage) -- You send the targetPlayer and the msg with the client sided trigger as additional arguments
	targetPlayer = getPlayerFromName(targetPlayer) -- Find the target player who has to get the msg
  	triggerServerEvent(targetPlayer, "forwardMsg", resourceRoot, theMessage) -- Trigger a client sided event at that player to put the msg in it's gridlist
end
addEvent("someEventNameYouWantHere", true) -- Add the event
addEventHandler("theSameEventNameAsInAddEvent", resourceRoot, sendMsg) -- Handle the event

 

Link to post

Thanks for your response. I need it to get the message from a memo (Visible in the function 'criarOcorrencia') and send it to a gridlist and not to a specific player only.  So in case I would use the getElementsByType function getting all players from the server and a trigger to create the row?

Link to post

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