Jump to content

Streaming


marcineg

Recommended Posts

I'm want to everyone see dxDrawMaterialLine3D, but i do not want to use loop on players in onClientPreRender.

addEventHandler("onClientPreRender",root,function()		
for _,k in pairs(Element.getAllByType("player")) do
				local pts = k:getData("points")
  				for i=1, #pts do
                dxDrawMaterialLine3D(pts[i][1],pts[i][2],pts[i][3],pts[i+1][1],pts[i+1][2],pts[i+1][3],texture,0.1)
                end
        end
end)

how to optimize this code?

Link to comment
  • Discord Moderators

triggerClientEvent

triggerServerEvent

Tables.

 

This is what you need.I have one script like you need, here it is:

 

--clienet
local lines = {}
addEventHandler("onClientResourceStart",resourceRoot,function()


	setElementData(localPlayer, "endpos",Vector3(getElementPosition(localPlayer)))
	lines[localPlayer] = {}
	lines[localPlayer][1] = {Vector3(getElementPosition(localPlayer)),Vector3(getElementPosition(localPlayer))}
	local x,y = getScreenFromWorldPosition(2796.6591796875 ,-695.8740234375 ,57.99556350708)

	local browser = guiCreateBrowser(x,y,1000,1000,true,false,false)

	

	addEventHandler("onClientPreRender",root,function()
		local x,y,z = getElementPosition(localPlayer)
		for kk,vv in pairs(lines) do
			for k,v in pairs(vv) do
				if v[2] == 1 then
					v[2] = Vector3(getElementPosition(kk))
				end
				if not v[2] or not v[1] then break end
				if not texture then break end
				if not getElementData(localPlayer,"showlines") then return end
				dxDrawLine3D(v[1],v[2],tocolor(170,170,170,255),1500)
			end
		end
	end)

	for k,v in pairs({"w","a","s","d"}) do
		bindKey(v,"down",function()
			setElementData(localPlayer, "startpos",Vector3(getElementPosition(localPlayer)))

			local index = #lines[localPlayer]+1
		
			lines[localPlayer][index] = {getElementData(localPlayer, "endpos"),1}
			setElementData(localPlayer, "lastindex",index)

			if getElementData(localPlayer, "syncLINE") then
				local x,y,z = getElementData(localPlayer, "endpos"):getX(),getElementData(localPlayer, "endpos"):getY(),getElementData(localPlayer, "endpos"):getZ()
				
				local trigged = triggerServerEvent("syncLinesS",resourceRoot,localPlayer,index,x,y,z,1)

			end
		end)

		bindKey(v,"up",function()
			setElementData(localPlayer, "endpos",Vector3(getElementPosition(localPlayer)))
			local index = getElementData(localPlayer, "lastindex")

			lines[localPlayer][index] = {
			lines[localPlayer][index][1],
			Vector3(getElementPosition(localPlayer))}

			if getElementData(localPlayer, "syncLINE") then

				local x,y,z = getElementPosition(localPlayer)
				local x1,y1,z1 = lines[localPlayer][index][1]:getX(),lines[localPlayer][index][1]:getY(),lines[localPlayer][index][1]:getZ()
		
				local trigged =  triggerServerEvent("syncLinesS",resourceRoot,localPlayer,index,x,y,z,x1,y1,z1)

			end
		end)
	end


end)
addCommandHandler("showlines",function() 
	setElementData(localPlayer,"showlines",not getElementData(localPlayer,"showlines")) 
	outputChatBox(" Vonalak mutatása " .. tostring(getElementData(localPlayer,"showlines")))
end,false)


addCommandHandler("lines",function() 
	setElementData(localPlayer,"syncLINE",not getElementData(localPlayer,"syncLINE")) 
	outputChatBox(" sync state " .. tostring(getElementData(localPlayer,"syncLINE")))
end,false)

addEvent("snycLinesCC",true)
addEventHandler("snycLinesCC",getLocalPlayer(),function(p,index,x,y,z,xx,yy,zz)

	if p == localPlayer then return end

	if not lines[p] then
		lines[p] = {}
	end
	if xx == 1 and not yy and not zz then
		nd = 1
	else
		nd = Vector3(xx,yy,zz)
	end
	lines[p][index] = {Vector3(x,y,z),nd}
end)




--server
addEvent("syncLinesS",true)
addEventHandler("syncLinesS",resourceRoot,function(p,index,x,y,z,xx,yy,zz)

	triggerClientEvent(root,"snycLinesCC",root,p,index,x,y,z,xx,yy,zz)
end)

when you start-up the script use /showlinesto enable drawing of the lines, and use / lines to enalbe syncing to other players.

Link to comment
addEventHandler("onClientPreRender",root,function()		
	for _,k in pairs(Element.getAllByType("player", true)) do
		local pts = k:getData("points")
  		for i=1, #pts do
     		dxDrawMaterialLine3D(pts[i][1],pts[i][2],pts[i][3],pts[i+1][1],pts[i+1][2],pts[i+1][3],texture,0.1)
		end
	end
end)

This'll only render lines towards the players who are streamed in for the localPlayer.

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