Jump to content

Problem with spectators!


Recommended Posts

ho rimediato questo script, ma il problema è che vorrei farlo di colore blu, e non arancione.

client:

local x, y = guiGetScreenSize () 
local localPlayer = getLocalPlayer() 
local dxDraw = {} 
local dxDrawOutline = {} 
  
  
local spectatorSettings = { 
xOffset = (x/6.3), 
yOffset = y - (y/1.4)} 
  
  
local showSpectators = true 
  
function changeSpectatorsEnabled() 
    showSpectators = not showSpectators 
end 
bindKey("F2","down",changeSpectatorsEnabled) 
  
local spectators = {} 
addEvent('addSpectator', true) 
addEvent('removeSpectator', true) 
  
addEventHandler('onClientResourceStart', root, 
    function() 
        triggerServerEvent ('addClient', localPlayer) 
    end) 
  
addEventHandler('addSpectator', root, 
    function(spectator) 
        table.insert(spectators, spectator) 
    end) 
  
addEventHandler('removeSpectator', root, 
    function(spectator) 
        for i, val in ipairs(spectators) do 
            if (val == spectator) then 
                table.remove(spectators, i) 
            end 
        end 
    end) 
  
function elementCheck (elem) 
    if elem then 
        if isElement (elem) then 
            if (getElementType (elem) == 'player') then 
                return true 
            end 
        end 
    end 
    return false 
end 
-------------------------------------------------------- 
  
  
function drawSpectators() 
    if showSpectators == true then 
        local textX = x - spectatorSettings.xOffset 
        local textY = spectatorSettings.yOffset 
  
        scale = getScale(x) 
  
        dxDrawText("Spectators: ",textX - 1, textY + 1, x, y, tocolor(0,149,255,255), scale, 'bankgothic') 
        dxDrawText("Spectators: ",textX, textY, x, y, tocolor(0,149,255,255), scale, 'bankgothic') 
  
        if not (isPlayerDead(localPlayer)) then 
            if (#spectators > 0) then 
                for i, v in ipairs(spectators) do 
                    if elementCheck (v) then 
                        local name = getPlayerName(v) 
                        if (i) then 
                            dxDrawOutline[i] = dxDrawText (" "..string.gsub(name,"#%x%x%x%x%x%x",""), textX - 1, (textY + scale) + (dxGetFontHeight(scale,'bankgothic') * i) + 1.5, x, y, tocolor(0,0,0, 255), scale, 'bankgothic') 
                            dxDraw[i] = dxDrawColorText (" "..name, textX, (textY + scale) + (dxGetFontHeight(scale,'bankgothic') * i), x, y, tocolor(255, 255, 255, 255), scale, 'bankgothic') 
                        end 
                    else 
                        table.remove (spectators, k) 
                    end 
                end 
            else 
                dxDrawOutline[1] = dxDrawText (" none", textX - 1, (textY + scale) + dxGetFontHeight(scale,'bankgothic') + 1.5, x, y, tocolor(0,0,0, 255), scale, 'bankgothic') 
                dxDraw[1] = dxDrawColorText (" none", textX, (textY + scale) + dxGetFontHeight(scale,'bankgothic'), x, y, tocolor(255, 255, 255, 255), scale, 'bankgothic') 
            end 
        end 
    end 
end 
addEventHandler('onClientRender', root, drawSpectators) 
  
  
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
        if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth(cap, scale, font) 
            dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
            ax = ax + w 
            color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 
        end 
        last = e + 1 
        s, e, cap, col = str:find(pat, last) 
    end 
    if last <= #str then 
        cap = str:sub(last) 
        local w = dxGetTextWidth(cap, scale, font) 
        dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
    end 
end 
  
  
function getScale(w) 
    local scale = (w*0.5)/1080 
    return scale 
end 

server:

local GATHER_FREQUENCY = 1000 
  
local playerData = {} 
local spectator_players = {} 
  
addEvent('onCameraTargetChange') 
addEvent('removeClient', true) 
addEvent('addClient', true) 
  
function elementCheck (elem) 
    if elem then 
        if isElement (elem) then 
            if (getElementType (elem) == 'player') then 
                return true 
            end 
        end 
    end 
    return false 
end 
  
function repairTable() 
    for i, val in ipairs (spectator_players) do 
        if not elementCheck (val) then 
            if playerData[val] then 
                if playerData[val].target then 
                    if (elementCheck(playerData[val].target) and playerData[val].target ~= val) then 
                        triggerClientEvent(playerData[val].target, 'removeSpectator', playerData[val].target, player) 
                    end 
                end 
            for k, v in ipairs (playerData) do 
                if (k == val) then 
                    table.remove (playerData, k) 
                end 
            end 
            end 
        table.remove (spectator_players, i) 
        end 
    end 
end 
  
function spectators() 
    for i, player in ipairs(spectator_players) do 
        if elementCheck (player) then 
            local target = getCameraTarget(player) 
            if (not playerData[player]) then 
                playerData[player] = {} 
            end 
         
            if (target ~= playerData[player].target) then 
                playerData[player].previous = playerData[player].target 
                playerData[player].target = target 
                triggerEvent('onCameraTargetChange', player, playerData[player].target, playerData[player].previous) 
            end 
        else 
            repairTable() 
        end 
    end 
end 
setTimer(spectators, GATHER_FREQUENCY, 0) 
  
addEventHandler('onCameraTargetChange', root, 
    function(target, oldTarget) 
        if elementCheck (oldTarget) then 
            triggerClientEvent(oldTarget, 'removeSpectator', oldTarget, source) 
        end 
        if (target == source) or (not target) then 
            return 
        end 
        if elementCheck (target) then 
            triggerClientEvent(target, 'addSpectator', target, source) 
        end 
    end 
) 
  
function removeClient() 
    if (playerData[source]) then 
        if (playerData[source].target) then 
            triggerClientEvent(playerData[source].target, 'removeSpectator', playerData[source].target, source) 
        end 
    playerData[source] = nil 
    end 
        for i, val in ipairs(spectator_players) do 
            if (val == source) then 
                table.remove(spectator_players, i) 
            end 
        end 
end 
addEvent ('removeClient') 
addEventHandler ('removeClient', root, removeClient) 
  
function addClient() 
    if elementCheck (source) then 
        table.insert(spectator_players, source) 
    end 
end 
addEvent ('addClient', true) 
addEventHandler ('addClient', root, addClient) 
  
addEventHandler ('onPlayerQuit', root, removeClient) 
  

Help me anterics

-ps for hunterics: non mi serve più quel picker, grazie ugualmente <3

Link to comment

allora . . .prima di tutto questa script ha la funzione dxDrawColorText,e quindi il colore della lista dei player appare tramite i codici,ad esempio #FF0000Hunterix ed esce Hunterix in rosso.

Quindi dal colore che hai messo ti compare :

Spectators: in blu

Players in bianco (perche nessuno ha i codici colore)

Se vuoi tutto di blu devi editare questo :

  
-- linea 72 
  
  dxDraw[i] = dxDrawColorText (" "..name, textX, (textY + scale) + (dxGetFontHeight(scale,'bankgothic') * i), x, y, tocolor(255, 255, 255, 255), scale, 'bankgothic') 
  

Con Questo :

  
-- linea 72 
  
  dxDraw[i] = dxDrawText (" "..string.gsub(name,"#%x%x%x%x%x%x",""), textX , (textY + scale) + (dxGetFontHeight(scale,'bankgothic') * i) , x, y, tocolor(0,149,255,255), scale, 'bankgothic') 
  

Ti consiglio anche di editare il bindKey con il mouse destro,e molto comodo senza dover premere f2.

  
bindKey("mouse2","down",changeSpectatorsEnabled) 
  

Fammi sapere.

Per il pannello non ho tempo ora shokkino,devo finire un sacco di cose prima.

Link to comment
edit #2 tolto spectators dall' user panel e poi startato, lo spectators è blu ma se lo metto nuovamente nell'user panel diventa nuovamente arancio.

vieni su msn hunterics, ho controllato tutto ma non trovo niente :[

evidentemente c'è qualche contrasto con qualche codice dell'userpanel, usi altre funzioni dx oltre a quelle per lo spectators? se si controlla che il nome del testo dello spectators non sia uguale a quello di altri testi in dx...

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