Jump to content

Server triggered com erro


Recommended Posts

Olá a todos. Estou com um problema na seguinte questão: ERROR: Server triggered clientside event updateChatList, but event is not added clientside

Já li um tópico relacionado a este mesmo problema, porém não entendi muito bem ainda como resolver, alguém que poderia me ajudar nessa parte?

 

clientside

local showMyIcon = true
local chattingPlayers = {}
local drawDistance = 1000
local transicon = false
local chatIconFor = {}

local screenSizex, screenSizey = guiGetScreenSize()
local guix = screenSizex * 0.1
local guiy = screenSizex * 0.1
local globalscale = 1
local globalalpha = .85

gChatting = false
 
function chatCheckPulse()
    local chatState = isChatBoxInputActive() or isConsoleActive()
 
    if chatState ~= gChatting then
        if chatState then
            triggerServerEvent("playerChatting", getLocalPlayer())
        else
            triggerServerEvent("playerNotChatting", getLocalPlayer())
        end
        gChatting = chatState
    end
    setTimer( chatCheckPulse, 150, 1)
end
addEventHandler ( "onClientResourceStart", getRootElement(), chatCheckPulse )
addEventHandler ( "onPlayerJoin", getRootElement(), chatCheckPulse )

function showTextIcon()
    local playerx,playery,playerz = getElementPosition ( getLocalPlayer() )
    for player, truth in pairs(chattingPlayers) do
        
        if (player == getLocalPlayer()) then
            if(not showMyIcon) then
                return
            end
        end
    
        if(truth) then
            local chatx, chaty, chatz = getElementPosition( player )
            if(isPedInVehicle(player)) then
                chatz = chatz + .5
            end
            local dist = getDistanceBetweenPoints3D ( playerx, playery, playerz, chatx, chaty, chatz )
            if dist < drawDistance then
                if( isLineOfSightClear(playerx, playery, playerz, chatx, chaty, chatz, true, false, false, false )) then
                    local screenX, screenY = getScreenFromWorldPosition ( chatx, chaty, chatz+1.2 )
                    
                    local scaled = screenSizex * (1/(2*(dist+5))) *.85
                    local relx, rely = scaled * globalscale, scaled * globalscale
                
                    guiSetAlpha(chatIconFor[player], globalalpha)
                    guiSetSize(chatIconFor[player], relx, rely, false)
                    
                    if(screenX and screenY) then
                        guiSetPosition(chatIconFor[player], screenX, screenY, false)
                        guiSetVisible(chatIconFor[player], true)
                    end
                end
            end
        end
    end
end
addEventHandler ( "onClientRender", getRootElement(), showTextIcon )

function updateList(newEntry, newStatus)
    chattingPlayers[newEntry] = newStatus
    if(not chatIconFor[newEntry]) then
        chatIconFor[newEntry] = guiCreateStaticImage(0, 0, guix, guiy, "chat.png", false )
    end
    guiSetVisible(chatIconFor[newEntry], false)
end
addEvent("updateChatList", true )
addEventHandler ( "updateChatList", getRootElement(), updateList )

 

serverside

addEvent("playerChatting", true )
addEvent("playerNotChatting", true )
addEvent("updateChatList", true )

function playerChatting()
        
    triggerClientEvent("updateChatList", getRootElement(), source, true)
end

function playerNotChatting()
        
    triggerClientEvent("updateChatList", getRootElement(), source, false)
end

addEventHandler("playerChatting", getRootElement(), playerChatting)
addEventHandler("playerNotChatting", getRootElement(), playerNotChatting)
addEventHandler ("onPlayerQuit", getRootElement(), playerNotChatting )

 

Link to comment
21 minutes ago, MaligNos said:

Adicione isso no seu client e remova a linha 17 do seu script server-side


addEventHandler("onClientPlayerQuit", getRootElement(),
	function()
		triggerServerEvent("playerNotChatting", source)
	end
)

 

O mesmo erro continua sendo acusado, acredito que o problema não seja no playerNotChatting

Link to comment

O erro é que no triggerClientEvent, o resource ainda não está disponivel no seu cliente (você está no download)

Tente:

-- cliente
addEventHandler("onClientResourceStart", resourceRoot,
    function ()
		triggerServerEvent ( "onClientDownloaded", localPlayer )
    end
)

addEventHandler("onClientPlayerQuit", getRootElement(),
	function()
		triggerServerEvent("playerNotChatting", source)
	end
)
-- server
addEvent( "onClientDownloaded", true )
addEventHandler( "onClientDownloaded", root,
	function()
		addEventHandler("playerChatting", client, playerChatting)
		addEventHandler("playerNotChatting", client, playerNotChatting)
	end
)

* remova as linhas 15,16,17

Edited by MaligNos
  • Thanks 1
Link to comment

Só sei que nada sei  Sócrates

Tente:

addEvent("playerChatting", true )
addEvent("playerNotChatting", true )
addEvent("updateChatList", true )

function playerChatting()
    triggerClientEvent(this, "updateChatList", getRootElement(), source, true)
end

function playerNotChatting()
    triggerClientEvent(this, "updateChatList", getRootElement(), source, false)
end


addEvent( "onClientDownloaded", true )
addEventHandler( "onClientDownloaded", root,
	function()
		addEventHandler("playerChatting", client, playerChatting)
		addEventHandler("playerNotChatting", client, playerNotChatting)
	end
)

 

  • Thanks 1
Link to comment

Depois posso tentar pensar em algo melhor, mas aqui uma solução "porca"

local clientOk = {}

addEvent( "onClientDownloaded", true )
addEventHandler( "onClientDownloaded", resourceRoot,
	function()
		clientOk[client] = true
	end
)

addEvent("playerChatting", true )
addEvent("playerNotChatting", true )

function updatePlayerChatting()
	for _,p in ipairs(getElementsByType("player")) do
		if (clientOk[p]) then
			triggerClientEvent(p, "updateChatList", getRootElement(), source, eventName == "playerChatting" and true or false)
		end
	end
end

addEventHandler("playerChatting", getRootElement(), updatePlayerChatting)
addEventHandler("playerNotChatting", getRootElement(), updatePlayerChatting)

addEventHandler("onPlayerQuit", root,
	function()
		clientOk[source] = nil
	end
)

 

  • Like 1
Link to comment
29 minutes ago, RikeBR said:

Blz, eu testei aqui e continua a mesma coisa, ele só aparece para o player, mas mesmo assim, vlw!

Ué. Tente com esse:

local clients = {}

addEvent( "onClientDownloaded", true )
addEventHandler( "onClientDownloaded", resourceRoot,
	function()
		table.insert(clients, client)
	end
)

addEvent("playerChatting", true )
addEvent("playerNotChatting", true )

function playerChatting()
    triggerClientEvent(clients, "updateChatList", getRootElement(), source, true)
end

function playerNotChatting()
    triggerClientEvent(clients, "updateChatList", getRootElement(), source, false)
end

addEventHandler("playerChatting", getRootElement(), updatePlayerChatting)
addEventHandler("playerNotChatting", getRootElement(), updatePlayerChatting)

addEventHandler("onPlayerQuit", root,
	function()
		for i,p in ipairs(clients) do
			if (p == source) then
				table.remove(clients, i)
			end
		end
	end
)

 

  • Thanks 1
Link to comment
29 minutes ago, MaligNos said:

Ué. Tente com esse:


local clients = {}

addEvent( "onClientDownloaded", true )
addEventHandler( "onClientDownloaded", resourceRoot,
	function()
		table.insert(clients, client)
	end
)

addEvent("playerChatting", true )
addEvent("playerNotChatting", true )

function playerChatting()
    triggerClientEvent(clients, "updateChatList", getRootElement(), source, true)
end

function playerNotChatting()
    triggerClientEvent(clients, "updateChatList", getRootElement(), source, false)
end

addEventHandler("playerChatting", getRootElement(), updatePlayerChatting)
addEventHandler("playerNotChatting", getRootElement(), updatePlayerChatting)

addEventHandler("onPlayerQuit", root,
	function()
		for i,p in ipairs(clients) do
			if (p == source) then
				table.remove(clients, i)
			end
		end
	end
)

 

Troque na linha 4 resourceRoot por root, ou mude o seu client para:

addEventHandler("onClientResourceStart", resourceRoot,
    function ()
		triggerServerEvent ( "onClientDownloaded", resourceRoot )
    end
)

 

  • Thanks 1
Link to comment
9 minutes ago, RikeBR said:

Bom, fiz exatamente como tu mandou, tentei algumas outras coisas e ele continua não funcionando, no debugscript 3 acusa o seguinte erro:

Obs: server-side

https://i.imgur.com/YaHikhn.png

CTRL+ C e CTRL+V  :D

Troque as linhas 22 e 23

addEventHandler("playerChatting", getRootElement(), playerChatting)
addEventHandler("playerNotChatting", getRootElement(), playerNotChatting)

 

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