Jump to content

onClientPlayerVoiceStart


Recommended Posts

  • Scripting Moderators
31 minutes ago, N3xT said:

I'm not talking about dx functions, a lot of developers thinks that using anything but dx functions inside a render is wrong and might harm your server and things like that, I'm not saying that's true nor false. depends on the way you use the render but do you think using a function like getElementPosition inside a render is wrong? totally not.

when I told you race nametags are using the same method I meant getting the position of the player and calculating the scale of the text and we've been using it for years now and I've never seen anybody complain about it, you can check race gamemode and you'll get the full picture of what I'm talking about.

and yeah, the same goes for timers.

Shouldn't it hurt only a player? Unless it triggers triggerServerEvent. Since server sync all players position and it's something normal for it - correct me if am wrong.

Link to comment
5 hours ago, N3xT said:

I'm not talking about dx functions, a lot of developers thinks that using anything but dx functions inside a render is wrong and might harm your server and things like that, I'm not saying that's true nor false. depends on the way you use the render but do you think using a function like getElementPosition inside a render is wrong? totally not.

when I told you race nametags are using the same method I meant getting the position of the player and calculating the scale of the text and we've been using it for years now and I've never seen anybody complain about it, you can check race gamemode and you'll get the full picture of what I'm talking about.

and yeah, the same goes for timers.

I am not complaining either about using onClientRender, I am just saying that it should get used wisely and in this case you are recommending him to use it in such a way that would require using a loop, then checking for each one's information and then insert in another table if that passes the check. Now Imagine having 100+ players in his server, imagine doing the same calculations 100 times on every frame that means 6000 times in a second, do you call that efficient way to use onClientRender? I guess not.

Please stop getting examples of nametags usages because those things NEED onClientRender otherwise they won't even work.

And no. Timers are not like onClientRender.

 

@majqq

It won't really affect the server itself, but the client will get loaded to all players so basically all players will lag (if something is wrong with the code)

But don't worry your server shouldn't go down if you are  not using a trigger.

 

Now let's please stick to the original topic and see if @slapz0r still needs help.

Edited by HassoN
Link to comment
11 hours ago, HassoN said:

Please stop getting examples of nametags usages because those things NEED onClientRender otherwise they won't even work

I guess you didn't check them otherwise you would have understood what I'm talking about.

 

addEventHandler ( "onClientRender", g_Root,
	function()
		local x,y,z = getCameraMatrix()
		for player in pairs(nametags) do
			while true do
				if not isPedInVehicle(player) or isPedDead(player) then break end
				local vehicle = getPedOccupiedVehicle(player)
				local px,py,pz = getElementPosition ( vehicle )
				local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz )
				if pdistance <= NAMETAG_DISTANCE then
					local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 )
					if not sx or not sy then break end
					local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE))
					local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF)
					alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA)
					scale = math.evalCurve(maxScaleCurve,scale)
					local textscale = math.evalCurve(textScaleCurve,scale)
					local textalpha = math.evalCurve(textAlphaCurve,alpha)
					local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale)
					local r,g,b = 255,255,255
					local team = getPlayerTeam(player)
					if team then
						r,g,b = getTeamColor(team)
					end
					local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2
					dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false )
				end
				break
			end
		end
	end
)

 

And you can do the same like that:

 

local playersUsingMic = {}
local x, y = guiGetScreenSize ( )
local sx, sy = 1600, 900

function onStartVoiceChat()
	local myIndex = getMyValue(source)
	if (not myIndex or not playersUsingMic[myIndex]) then
		local p_id = getElementData (source, "ID") or "0"
		table.insert(playersUsingMic, {source, p_id})
	end
end
addEventHandler("onClientPlayerVoiceStart", root, onStartVoiceChat)

function onStopVoiceChat()
	local myIndex = getMyValue(source)
	if ( myIndex ) then
		table.remove(playersUsingMic, myIndex)
	end
end
addEventHandler("onClientPlayerVoiceStop", root, onStopVoiceChat)
	
function drawText()
	if (#playersUsingMic > 0) then
		for i, v in ipairs(playersUsingMic) do
			local x, y, z = getElementPosition(v[1])
			local x2, y2, z2 = getElementPosition(localPlayer)
			local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
			if (distance <= 15) then
				-- Your dx functions
			end
		end
	end
end
addEventHandler("onClientRender", root, drawText)


function getMyValue(player)
	for i, v in ipairs(playersUsingMic) do
		if v[1] == player then
			return i
		end
	end
end

 

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