Hey there, im using a script for a indication of active voice. So, it should work like this: whenever a player press Z, the dxDrawText changes color. Whenever the player stop talking(pressing Z), the dxDrawText change to the original color.
The bug is, im only getting the first color transition, and it keeps like this till I restart the script.
Can some one help?
local drawDistance = 30
local isPlayerIdVisible = true
voiceOn = {}
g_StreamedInPlayers = {}
function onVoice()
if source ~= localPlayer then
if isElementStreamedIn(source) then
voiceOn[source] = true
else
voiceOn[source] = false
end
end
end
addEventHandler("onClientPlayerVoiceStart", root, onVoice)
function offVoice()
if source ~= localPlayer then
voiceOn[source] = false
end
end
addEventHandler("onClientPlayerVoiceStop", root, offVoice)
function onClientRender()
local cx, cy, cz, lx, ly, lz = getCameraMatrix()
for k, player in pairs(g_StreamedInPlayers) do
if isElement(player) and isElementStreamedIn(player) then
do
local vx, vy, vz = getPedBonePosition(player, 4)
local dist = getDistanceBetweenPoints3D(cx, cy, cz, vx, vy, vz)
if dist < drawDistance and isLineOfSightClear(cx, cy, cz, vx, vy, vz, true, false, false) then
if getElementData(player, 'invisible') then return end
local x, y = getScreenFromWorldPosition(vx - 0.10, vy, vz + 0.30)
if x and y then
local ID = getElementData(player, "ID") or "N/A"
local w = dxGetTextWidth(ID, 0.1, "arial")
local h = dxGetFontHeight(1, "arial")
local color = tocolor(255, 255, 255)
dxDrawText("("..ID..")", x - 1 - w / 1, y - 1 - h - 2, w, h, CorTag, 1.20, "arial", "left", "top", false, false, false, false, false)
if voiceOn[player] == true then
CorTag = tocolor(139, 0, 255)
end
if voiceOn[player]==false then
Cortag = tocolor(255, 255, 255)
end
end
end
end
else
table.remove(g_StreamedInPlayers, k)
end
end
end
addEventHandler("onClientRender", getRootElement(), onClientRender)