Jump to content

How to set target on client-side?


Junim

Recommended Posts

Hi guys, i have a question, How to set target on client-side? look my code please!

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

function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function MultarPlayer(_,state)
    if ShowPanelMult == true then
        if state == "down" then
            if isCursorOnElement(x*896, y*388, x*98, y*36) then
                if playerName then
                    local valor = guiGetText(ValorEdit);
                    local motivo = guiGetText(MotivoEdit);
                    local target = getPlayerFromPartialName(name)
                    if (valor  ~= "" and motivo ~= "") then
                        if not tonumber(valor) then outputChatBox("#FFFF00[MULTA_SYSTEM] #FFFFFFNa caixa Valor digite apenas numeros.", 255, 255, 255, true) return end
                        if target then
                            if ShowMessage == false then
                                ShowMessage = true;
                                addEventHandler("onClientRender",target, Message)
                                setTimer(function()
                                    ShowMessage = false;
                                    removeEventHandler("onClientRender",target, Message)
                                end, 7000, 1)
                            end    
                        
                        end
                    end    
                else
                    outputChatBox("#FFFF00[MULTA_SYSTEM] #FFFFFF Primeiro você precisa selecionar o nome de um jogador !",255,255,255,true)    
                end    
            end
        end
    end
end
addEventHandler("onClientClick",root,MultarPlayer)

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

I wanted it to show the message that is in AddEventHandler for the other player (target) but I can not

[SORRY MY ENGLISH I AM FROM BRAZIL]

Link to comment

You could try something like this:

local playerMessages = {}

addEventHandler( "onClientResourceStart", resourceRoot,
	function()
		addEventHandler( "onClientRender",root, Message )
	end
)

addEventHandler( "onClientElementDataChange", root,
	function (dataName)
		if (dataName == "sendPlayerMessage") then
			if localPlayer == source then
				table.insert( playerMessages, getElementData( source, "sendPlayerMessage" ) )
			end
		end
	end
)

function sendMessageToPlayer( p, msg )
	if isElement(p) and type(msg) == "string" then
		return setElementData( p, "sendPlayerMessage", tostring(msg), false )
	end
end

And on the "Message" function you'll handle the table playerMessages to display the message on the screen.

According to my code, you can use sendMessageToPlayer( target, msg ) to send the message.

Edited by DNL291
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...