Jump to content

spect count


brad

Recommended Posts

Posted (edited)

hola amigos quisiera saber como hacer que mi spectating cuente los jugadores que ven a un jugaor

este es mi script client

local x, y = guiGetScreenSize () 
  
local localPlayer = getLocalPlayer() 
  
local spectatorSettings = { 
count = 7, -- how many player names to show, before showing "and x more" 
charLimit = 19, -- max limit of characters in player name 
xOffset = 200, -- how far to the left this should be 
yOffset = (y / 2) - 10, -- how far down the screen this should be ~ currently it is almost half way down 
alwaysShow = true -- whether to show anything if there aren't any players spectating you 
} 
  
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() 
    local textX = x - spectatorSettings.xOffset 
    local textY = spectatorSettings.yOffset 
     
    if (not isPlayerDead(localPlayer)) then 
  
    local s_Spectators = 'Spectadores\n' 
        if (#spectators > 0) then 
        for i, v in ipairs(spectators) do 
            if elementCheck (v) then 
            local name = getPlayerName(v) 
                if (string.len(getPlayerName(v)) > spectatorSettings.charLimit) then 
                    name = string.sub(name, 0, spectatorSettings.charLimit)..'..' 
                end 
            if (i > spectatorSettings.count) then 
                s_Spectators = s_Spectators..tostring(#spectators - spectatorSettings.count)..' more' 
                break 
            else     
                s_Spectators = s_Spectators..name..'\n' 
            end 
            else 
                table.remove (spectators, k) 
            end 
        end 
        else 
            if (spectatorSettings.alwaysShow) then 
                s_Spectators = s_Spectators..'None' 
            else 
                s_Spectators = '/' 
            end 
        end 
    dxDrawText (s_Spectators, textX, textY, x, y, tocolor(255, 255, 255, 255), 0.5, 'Bankgothic') 
dxDrawText (s_Spectators, textX, textY, x, y, tocolor(0, 0, 0, 0), 0.5, 'Bankgothic') 
    end 
end 
addEventHandler('onClientRender', root, drawSpectators) 

 

 

este es mi script tipo server

 

local GATHER_FREQUENCY = 1000 -- how often in ms it should run the "spectator" function 
  
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 -- if the target is different from previous one 
                playerData[player].previous = playerData[player].target -- store the old target 
                playerData[player].target = target -- store the new 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 -- if the old target is valid(ie. not false or nil(in which case the camera was fixed)) 
            triggerClientEvent(oldTarget, 'removeSpectator', oldTarget, source) -- trigger for the old target to remove from his list 
        end 
        if (target == source) or (not target) then -- if the new target is invalid or facing the player who invoked the event 
            return 
        end 
        if elementCheck (target) then 
            triggerClientEvent(target, 'addSpectator', target, source) -- else we add the player to the targets list 
        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)  

Gracias a los ke me ayuden :D:D

Edited by Guest
Posted

quiero que mi script de spectador de gamemode race cuente los spectadores que ven a un jugador ejemplo

spectating [3] asi que indicara que a un jugador lo ven 3 spectadores

Posted

bueno esque nose mucho de este soy noob y algo que se eske se podria usar drawText la sintaxis y se le pone la funcion de count no?

Posted

Castillo soy muy archirecontranoob en esto me podrias decir en ke parte del script ponerlo? y con ke argumentos porque el script tiene unos argumentos raros para mi ,gracias y perdon por joder

Posted

Eso es porque screenWidht y screenHeight no existen en tu script, tu screenWidht y screenHeight en el script son "x" y "y".

dxDrawText("Spectating [".. tostring(#spectators) .."]", 825, y-410, x, y, tocolor ( 255, 255, 255, 255 ), 0.5, "bankgothic" ) 

Proba con eso.

Posted

Ok, arregle el error.

local x, y = guiGetScreenSize () 
  
local localPlayer = getLocalPlayer() 
  
local spectatorSettings = { 
count = 7, -- how many player names to show, before showing "and x more" 
charLimit = 19, -- max limit of characters in player name 
xOffset = 200, -- how far to the left this should be 
yOffset = (y / 2) - 10, -- how far down the screen this should be ~ currently it is almost half way down 
alwaysShow = true -- whether to show anything if there aren't any players spectating you 
} 
  
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() 
    local textX = x - spectatorSettings.xOffset 
    local textY = spectatorSettings.yOffset 
    
    if (not isPlayerDead(localPlayer)) then 
  
    local s_Spectators = 'Spectadores ['.. tostring(#spectators) ..']\n' 
        if (#spectators > 0) then 
        for i, v in ipairs(spectators) do 
            if elementCheck (v) then 
            local name = getPlayerName(v) 
                if (string.len(getPlayerName(v)) > spectatorSettings.charLimit) then 
                    name = string.sub(name, 0, spectatorSettings.charLimit)..'..' 
                end 
            if (i > spectatorSettings.count) then 
                s_Spectators = s_Spectators..tostring(#spectators - spectatorSettings.count)..' more' 
                break 
            else    
                s_Spectators = s_Spectators..name..'\n' 
            end 
            else 
                table.remove (spectators, k) 
            end 
        end 
        else 
            if (spectatorSettings.alwaysShow) then 
                s_Spectators = s_Spectators..'None' 
            else 
                s_Spectators = '/' 
            end 
        end 
    dxDrawText (s_Spectators, textX, textY, x, y, tocolor(255, 255, 255, 255), 0.5, 'Bankgothic') 
    dxDrawText (s_Spectators, textX, textY, x, y, tocolor(0, 0, 0, 0), 0.5, 'Bankgothic') 
    --dxDrawText("Spectating [".. tostring(#spectators) .."]", 825, y-410, x, y, tocolor ( 255, 255, 255, 255 ), 0.5, "bankgothic" ) 
    end 
end 
addEventHandler('onClientRender', root, drawSpectators) 

En Spectadores pone el numero ahora, pero si no quieres eso lo borras y quitas los "--" de la linea "Spectating [".. tostring(#spectators) .."]"

Posted

Voy a decir un comentario..

No puedo creer que estes intentando hacer estos scripts cuando todavia seguro que ni podes leerlo..

Trata de hacerlo algo mas basico.

Vos podes copiar otros scripts pero si no entendes lo que se hace, nunca vas a aprender o vas a tardar un monton en aprender.

Posted

prdon y sinceramente perdon jaja estoy necio pero como ago para que yo pueda ver ejemplo yo estoy de spectador a un jugador y tambien quiero ver quien mas esta de spectador del jugador?

osea mi punto es que yo pueda ver a los otros jugadores que estan de spectadores en cada jugador

entiende?

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...