Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2020-12-08, 11:03


Haverrak12







Wiek: 32
Na forum: 2301 dni
Posty: 8
Nick w MP: hahaha



Respekt: 50

Ostrzeżeń: 60%
Witam zrobi?em sobie ostatnio chat g?osowy i od kilku dni staram si? zrobi? co? takiego ?eby nie s?ysza? kto? kogo? na ca?ym serwerze tylko na dan? odleg?o?? jak by to zrobi?? (u?ywam standardowego skryptu voice co jest w mta)

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-12-08, 11:13


TheSebaPL

Mod-team






Wiek: 22
Na forum: 3239 dni
Posty: 964

Piwa: 3101

Respekt: 640,5
Respekt: 640,5Respekt: 640,5

Haverrak12,



-- variables
local voicePlayers = {}

-- draw (voice reosource)
local g_screenX,g_screenY = guiGetScreenSize()
local BONE_ID = 8
local WORLD_OFFSET = 0.4
local ICON_PATH = "images/voice.png"
local ICON_WIDTH = 0.15*g_screenX
--
local font = dxCreateFont("font.ttf", 12)
local iconHalfWidth = ICON_WIDTH/2

local ICON_DIMENSIONS = 12
local ICON_LINE = 20
local ICON_TEXT_SHADOW = tocolor ( 0, 0, 0, 255 )
local range = 15

--Draw the voice image
addEventHandler ( "onClientRender", root,
    function()
        local index = 0
        local sX, sY, sZ = getElementPosition(localPlayer) 
        for player in pairs(voicePlayers) do

            local rX, rY, rZ = getElementPosition(player)
            local distance = getDistanceBetweenPoints3D(sX, sY, sZ, rX, rY, rZ) 
            setSoundVolume( player, 30-distance )

            local color = tocolor(255, 255, 255, 255)
            if distance <= range then
            dxDrawVoiceLabel ( player, index, color )
            end
            index = index + 1
            while true do
                --is he streamed in?
                if not isElementStreamedIn(player) then
                    break
                end
                --is he on screen?
                if not isElementOnScreen(player) then 
                    break
                end
                local headX,headY,headZ = getPedBonePosition(player,BONE_ID)
                headZ = headZ + WORLD_OFFSET
                --is the head position on screen?
                local absX,absY = getScreenFromWorldPosition ( headX,headY,headZ )
                if not absX or not absY then
                    break
                end
                local camX,camY,camZ = getCameraMatrix()
                --is there anything obstructing the icon?
                if not isLineOfSightClear ( camX, camY, camZ, headX, headY, headZ, true, false, false, true, false, true, false, player ) then
                    break
                end
                dxDrawVoice ( absX, absY, color, getDistanceBetweenPoints3D(camX, camY, camZ, headX, headY, headZ) )
                break
            end
        end
    end
)

function dxDrawVoice ( posX, posY, color, distance )
    if distance <= range then
    distance = 1/distance
    dxDrawImage ( posX - iconHalfWidth*distance, posY - iconHalfWidth*distance-75, ICON_WIDTH*distance, ICON_WIDTH*distance, ICON_PATH, 0, 0, 0, color, false )
end
end

function dxDrawVoiceLabel ( player, index, color )
    local sx, sy = guiGetScreenSize ()
    local scale = (sy / 800)
    local spacing = ( ICON_LINE * scale )
    local icon = ICON_DIMENSIONS * scale
    local px, py = sx-icon, (sy * 0.6 + spacing * index)

    if getPedOccupiedVehicle( localPlayer ) then
        py = (sy * 0.6 - spacing * index)
    end
    dxDrawImage ( px-icon, py, icon*1.2, icon*1.2, ICON_PATH, 0, 0, 0, color, false )

    px = px - spacing
 
    local name = getPlayerName ( player ):gsub("#%x%x%x%x%x%x","")
    local textWidth = dxGetTextWidth(name, 1.2, "default-bold")
    dxDrawText ( name, px + 1 - textWidth, py + 1, px - textWidth, py, ICON_TEXT_SHADOW, 1, font )
    dxDrawText ( name, px - textWidth, py, px - textWidth, py, color, 1, font )
end


-- events
addEventHandler("onClientPlayerVoiceStart",getRootElement(),function()
    if getElementData (localPlayer, "player:mute" ) then
        cancelEvent()
        return 
    end
    if getElementData (source, "mute:player" ) then
        cancelEvent()
        return
    end
    if getElementData (source, "voice:off" ) then
        cancelEvent()
        return
    end
    local localDimension = getElementDimension( localPlayer )
    local localInterior = getElementInterior( localPlayer )
    if source == localPlayer then
        setElementData(source, "voice:mowi", true)

        -- draw
        voicePlayers[source] = true

        -- data to server
        local posX, posY, posZ = getElementPosition(source)
        local nearbyPlayers = getElementsWithinRange(posX, posY, posZ, 30, "player")
        -- senc data
        --triggerServerEvent( "voicechat:setDestination", resourceRoot, nearbyPlayers )
    else
        local sourceDimension = getElementDimension( source )
        local sourceInterior = getElementInterior( source )
        if tonumber(localDimension) ~= tonumber(sourceDimension) or tonumber(localInterior) ~= tonumber(sourceInterior) then
            cancelEvent()
            return
        end

        local sX, sY, sZ = getElementPosition(localPlayer) 
        local rX, rY, rZ = getElementPosition(source)
        local distance = getDistanceBetweenPoints3D(sX, sY, sZ, rX, rY, rZ) 
        if distance <= range then
            voicePlayers[source] = true
        else 
            cancelEvent()
        end 
    end
end)

addEventHandler("onClientPlayerVoiceStop",getRootElement(),function()
    if source == localPlayer then
        setElementData(source, "voice:mowi", false)
    end
    voicePlayers[source] = nil
end)

addEventHandler("onClientPlayerQuit",getRootElement(),function()
    voicePlayers[source] = nil
end)


Podmie? ca?e client.lua

Nie jestem pewny czy na 100% b?dzie dzia?a?o.

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
Haverrak12
Wysłany: 2020-12-09, 15:58


Haverrak12







Wiek: 32
Na forum: 2301 dni
Posty: 8
Nick w MP: hahaha



Respekt: 50

Ostrzeżeń: 60%
TheSebaPL, Dzi?ki! dzia?a bardzo dobrze wr?cz idealnie ale jest jeden ma?y problem gdy kto? co? m?wi i kto? inny si? loguje to wszystko s?ycha? w panelu logowania da rade to jako? w skrypcie panelu logowania zrobi? tak jak np z myszk?? co? tkaiego showCursor(false) tylko z voice ?eby ne by?o w panelu logowania s?ycha? jak kto? inny s? loguje

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-12-09, 16:17


_jvneczek







Wiek: 22
Na forum: 4467 dni
Posty: 1509
Nick w MP: _jvneczek

Piwa: 3960

Respekt: 337,5
Respekt: 337,5Respekt: 337,5Respekt: 337,5

Wystarczy zrobi? ?e osoby kt?re nie s? zalogowane - nie s?ysz? voice chatu, wystarczy zwyk?y if z sprawdzaniem czy gracz jest zalogowany.

Postaw piwo autorowi tego posta
 

 
Tagi: voice :: chat
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Voice chat Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku