Jump to content

(HELP) Trigger Render


Lalalu

Recommended Posts

 

Hello, I have a problem with this code, this creates a Dx on you that other players can see, it is activated with a trigger from the server-side and a setElementData, but when I use it at the same time as someone else the render gets bug, It says that it was already handled..

 

local sX, sY = guiGetScreenSize ( )
local onEmoji4 = {};
local plyEmoji4 = getElementsByType ( "player" )
local showEmoji4 = false

function onEmoji4Render ( )	
	local cx, cy, cz = getCameraMatrix ()
	for i = 1, #plyEmoji4 do
		local p = plyEmoji4[i]
		if ( onEmoji4[p] ) then
			local x, y, z = getPedBonePosition.. --- -- blag blah blah
			  local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah
			   if ( dEmoji4 < 100 ) then
				if ( isLineOfSightClear ( cx, cy... -- blag blah blah
				  if (getElementData (p, "Emoji4") == true) then
					local sx, sy = getScreenFromWorldPosition...-- blag blah blah
					if ( sx ) and ( sy ) then				
					local sEmoji4 = 400  / ...-- blag blah blah							
		            dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) )			
					end 
				 end 
			  end 
		   end 
	    end 
     end
  end

function attachEmoji4 ( Emoji4 )
if not ( Emoji4 and isElement ( Emoji4 ) ) then return end
    onEmoji4[Emoji4] = true
    addEventHandler ( "onClientRender", root, onEmoji4Render )
    setTimer(function()
    removeEventHandler ( "onClientRender", root, onEmoji4Render )
    end, 2000, 1)
end
addEvent( "StartEmoji", true )
addEventHandler( "StartEmoji", root, attachEmoji4 )

 

Link to comment
16 hours ago, Lalalu said:

 

Hello, I have a problem with this code, this creates a Dx on you that other players can see, it is activated with a trigger from the server-side and a setElementData, but when I use it at the same time as someone else the render gets bug, It says that it was already handled..

 

local sX, sY = guiGetScreenSize ( )
local onEmoji4 = {};
local plyEmoji4 = getElementsByType ( "player" )
local showEmoji4 = false

function onEmoji4Render ( )	
	local cx, cy, cz = getCameraMatrix ()
	for i = 1, #plyEmoji4 do
		local p = plyEmoji4[i]
		if ( onEmoji4[p] ) then
			local x, y, z = getPedBonePosition.. --- -- blag blah blah
			  local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah
			   if ( dEmoji4 < 100 ) then
				if ( isLineOfSightClear ( cx, cy... -- blag blah blah
				  if (getElementData (p, "Emoji4") == true) then
					local sx, sy = getScreenFromWorldPosition...-- blag blah blah
					if ( sx ) and ( sy ) then				
					local sEmoji4 = 400  / ...-- blag blah blah							
		            dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) )			
					end 
				 end 
			  end 
		   end 
	    end 
     end
  end

function attachEmoji4 ( Emoji4 )
if not ( Emoji4 and isElement ( Emoji4 ) ) then return end
    onEmoji4[Emoji4] = true
    addEventHandler ( "onClientRender", root, onEmoji4Render )
    setTimer(function()
    removeEventHandler ( "onClientRender", root, onEmoji4Render )
    end, 2000, 1)
end
addEvent( "StartEmoji", true )
addEventHandler( "StartEmoji", root, attachEmoji4 )

 

You must be doing the trigger wrong and instead of triggering a single player it triggers the entire server

post the trigger part

Link to comment
4 hours ago, alex17" said:

You must be doing the trigger wrong and instead of triggering a single player it triggers the entire server

post the trigger part

Hi, this is my trigger:

        function EMOJI_Z1 ()
           triggerClientEvent("StartEmoji", root, source )
            setElementData(source, "Emoji1", true)
              setTimer(setElementData, 2000, 1, source, "Emoji1", false)
               end 
                addEvent ( "EMOJI_Z1", true ) addEventHandler ( "EMOJI_Z1", root, EMOJI_Z1 )

 

Edited by Lalalu
Link to comment

hello @Lalalu welcome to the forum, I made an edit about this topic, I recommend you to try it.

 

local sX, sY = guiGetScreenSize ( )
local onEmoji4 = {};
local plyEmoji4 = getElementsByType ( "player" )
local showEmoji4 = false
local isEventAdded = false

function onEmoji4Render ( )
    local cx, cy, cz = getCameraMatrix ()
    for i = 1, #plyEmoji4 do
        local p = plyEmoji4[i]
        if ( onEmoji4[p] ) then
            local x, y, z = getPedBonePosition.. --- -- blag blah blah
              local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah
               if ( dEmoji4 < 100 ) then
                if ( isLineOfSightClear ( cx, cy... -- blag blah blah
                  if (getElementData (p, "Emoji4") == true) then
                    local sx, sy = getScreenFromWorldPosition...-- blag blah blah
                    if ( sx ) and ( sy ) then
                    local sEmoji4 = 400  / ...-- blag blah blah
                    dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) )
                    end 
                 end 
              end 
           end 
        end 
     end
  end
function attachEmoji4 ( Emoji4 )
if not ( Emoji4 and isElement ( Emoji4 ) ) then return end
    if(isEventAdded) then return end -- if event added don't go 
    onEmoji4[Emoji4] = true
    addEventHandler ( "onClientRender", root, onEmoji4Render )
    isEventAdded = true -- mark as added
    setTimer(function()
    removeEventHandler ( "onClientRender", root, onEmoji4Render )
    isEventAdded = false -- mark as deleted
    end, 2000, 1)
end
addEvent( "StartEmoji", true )
addEventHandler( "StartEmoji", root, attachEmoji4 )
local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah

and something caught my eye I'm seeing non-Lua codes, can you explain a bit?


In addition, the code I sent you above will fix the eventHandler problem.

Edited by Shady1
  • Thanks 1
Link to comment
7 hours ago, Lalalu said:

Hi, this is my trigger:

        function EMOJI_Z1 ()
           triggerClientEvent("StartEmoji", root, source )
            setElementData(source, "Emoji1", true)
              setTimer(setElementData, 2000, 1, source, "Emoji1", false)
               end 
                addEvent ( "EMOJI_Z1", true ) addEventHandler ( "EMOJI_Z1", root, EMOJI_Z1 )

 

There is the problem. use it like this

 

triggerClientEvent( source, "StartEmoji", source )

  • Thanks 1
Link to comment

try this

local sX, sY = guiGetScreenSize ( )
local onEmoji4 = {};
local plyEmoji4 = getElementsByType ( "player" )
local showEmoji4 = false

function onEmoji4Render ( )	
	local cx, cy, cz = getCameraMatrix ()
	
	for p in pairs (onEmoji4) do
		if ( isElement(p) ) then
			local x, y, z = getPedBonePosition.. --- -- blag blah blah
			  local dEmoji4 = getDistanceBetweenPoints3D ( cx... -- blag blah blah
			   if ( dEmoji4 < 100 ) then
				if ( isLineOfSightClear ( cx, cy... -- blag blah blah
				  if (getElementData (p, "Emoji4") == true) then
					local sx, sy = getScreenFromWorldPosition...-- blag blah blah
					if ( sx ) and ( sy ) then				
						local sEmoji4 = 400  / ...-- blag blah blah							
						dxDrawImage ( sx - ( sEmoji4 / 2 ), sy - ( sEmoji4 / 2 ), sEmoji4, sEmoji4, "T_UI_Message_Icon_Aisatsu_BC.webp", 0, 0, 0, tocolor ( 255, 255, 255, 255 ) )			
					end 
				 end 
			  end 
		   end 
	    end 
	end
end

function attachEmoji4 ( Emoji4 )
	if not Emoji4 or not isElement ( Emoji4 ) then return end
	
    onEmoji4[Emoji4] = true
    addEventHandler ( "onClientRender", root, onEmoji4Render )
	
    setTimer(function()
		removeEventHandler ( "onClientRender", root, onEmoji4Render )
    end, 2000, 1)
end
addEvent( "StartEmoji", true )
addEventHandler( "StartEmoji", root, attachEmoji4 )

 

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