Jump to content

Help ( прикрепить текст к пикапу )


Recommended Posts

Киньте наброски пожалуйста, как прикрепить текст к пикапу. Вообщем у меня имеется интерфейс и кнопка "создать", при нажатие создается пикап на определенном месте. Пикап создается, вот с 3д текстом проблема. Пытался передать клиенту через событие и ничего, бывало что появлялся текст на 0000000.1 миллисекунд:D 

.server

function createHouse ( house )
	if ( house and type ( house ) == "table" ) then
		local houseName = house [ "houseName" ]
		local houseName = houseName:gsub ( "%p", "" )
		local houseData =
			{
				name = houseName,
				owner = house [ "houseOwner" ],
				originalPrice = house [ "houseOriginalPrice" ],
				price = house [ "housePrice" ],
				forSale = house [ "houseForSale" ],
				position = fromJSON ( house [ "housePosition" ] ),
				dimension = tonumber ( house [ "id" ] ),
				interior = tonumber ( house [ "houseInterior" ] ),
				interiorState = house [ "houseInteriorState" ],
				music = house [ "streamURL" ]
			}
		local dimension = tonumber ( house [ "id" ] )
		local pickupModel = ( houseData [ "forSale" ] == "Yes" and 1273 or 1272 )
		local x, y, z = unpack ( houseData [ "position" ] or { 0, 0, 0 } )
		local housePickup = createPickup ( x, y, z, 3, pickupModel, 0 )
		local houseColshape = createColTube ( x, y, z - 1, 0.9, 2 )
		setElementData ( houseColshape, "houseName", houseName, false )
		addEventHandler ( "onColShapeHit", houseColshape, onHouseColshapeHit )
		addEventHandler ( "onColShapeLeave", houseColshape, onHouseColshapeLeave )

		housesCreated [ houseName ] =
			{
				position = house [ "position" ],
				pickup = housePickup,
				colshape = houseColshape,
				data = houseData,
				playersInside = { }
			}
		houseIDS [ tonumber ( house [ "id" ] ) ] = houseName
		return housesCreated [ houseName ]
	end 
	
	return false
end

 

.client ( чет намудрил тут )

function nameText()
	if isElement(pickup) then
		local cx,cy,cz = getCameraMatrix()
		local px,py,pz = getElementPosition(pickup)
		local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz)
		local posx,posy = getScreenFromWorldPosition(px,py,pz+0.025*distance+0.40)
		if posx and distance <= 15 then
			dxDrawBorderedText("Текст",posx-(0.5),posy-(20),posx-(0.5),posy-(20),tocolor(255,175,0,255),1,1,"default-bold","center","top",false,false,false)
		end
	end
end
addEventHandler("onClientHUDRender",root,nameText)

function dxDrawBorderedText(text,left,top,right,bottom,color,scale,outlinesize,font,alignX,alignY,clip,wordBreak,postGUI,colorCoded)
	local outlinesize = math.min(scale,outlinesize)
	if outlinesize > 0 then
		for offsetX=-outlinesize,outlinesize,outlinesize do
			for offsetY=-outlinesize,outlinesize,outlinesize do
				if not (offsetX == 0 and offsetY == 0) then
					dxDrawText(text:gsub("#%x%x%x%x%x%x",""), left+offsetX, top+offsetY, right+offsetX, bottom+offsetY, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI)
				end
			end
		end
	end
	dxDrawText(text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded)
end

 

Link to comment

В .client

local All3DText = {}


for _, source in ipairs(getElementsByType("pickup", true)) do -- Этот участок кода необходим если планируешь перезапускать текущий ресурс
	local text = getElementData(source, "3DText")
	if(text) then
		All3DText[source] = text
	end
end

addEventHandler("onClientElementStreamIn", getRootElement(),
    function()
		if getElementType(source) == "pickup" then
			local text = getElementData(source, "3DText")
			if(text) then
				All3DText[source] = text
			end
		end
    end
);

addEventHandler("onClientElementStreamOut", getRootElement(),
	function()
		if getElementType(source) == "pickup" then
			local text = getElementData(source, "3DText")
			if(text) then
				All3DText[source] = nil
			end
		end
    end
);

function dxDrawBorderedText(text,left,top,right,bottom,color,scale,outlinesize,font,alignX,alignY,clip,wordBreak,postGUI,colorCoded)
	local outlinesize = math.min(scale,outlinesize)
	if outlinesize > 0 then
		for offsetX=-outlinesize,outlinesize,outlinesize do
			for offsetY=-outlinesize,outlinesize,outlinesize do
				if not (offsetX == 0 and offsetY == 0) then
					dxDrawText(text:gsub("#%x%x%x%x%x%x",""), left+offsetX, top+offsetY, right+offsetX, bottom+offsetY, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI)
				end
			end
		end
	end
	dxDrawText(text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded)
end

function nameText()
	local cx,cy,cz = getCameraMatrix()
	for pickup, text in pairs(All3DText) do
		local px,py,pz = getElementPosition(pickup)
		local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz)
		local posx,posy = getScreenFromWorldPosition(px,py,pz+0.025*distance+0.40)
		if posx and distance <= 15 then
			dxDrawBorderedText(text,posx,posy,posx,posy,tocolor(255,175,0,255),1,1,"default-bold","center","top",false,false,false)
		end
	end
end
addEventHandler("onClientHUDRender",root,nameText)

В .server

setElementData(housePickup, "3DText", "Мой 3D текст")

 

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