Jump to content

conteo de jugadores en una ColSphere


BorderLine

Recommended Posts

Posted

Mi pregunta es, como, o de que manera puedo hacer para hacer un conteo de cuantos jugadores hay dentro de la zona definida chatSphere. El punto es, agregar el numero al outputChatBox para saber cuantas personas leyeron el dicho mensaje.

Mi codigo

local chatRadius = 70 
  
function sendMessageToNearbyPlayers ( message, messageType ) 
    if ( messageType == 0 ) then 
        local posX, posY, posZ = getElementPosition ( source ) 
  
        local chatSphere = createColSphere ( posX, posY, posZ, chatRadius ) 
        local nearbyPlayers = getElementsWithinColShape ( chatSphere, "player" ) 
        destroyElement ( chatSphere ) 
  
         for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
                local team = getPlayerTeam(source) 
                if (team) then 
                         red, green, blue = getTeamColor( team ) 
                    end    
            outputChatBox( "{Local}"..getPlayerName ( source )..": #ffffff".. message, nearbyPlayer, red, green, blue, true ) 
        end 
        cancelEvent ( ) 
    end 
end 
addEventHandler ( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) 

Posted

para contar la cantidad de jugadores tendrias que usar #nearbyPlayers el "#" hace que retorne un numero representando la cantidad de elementos que hay en la tabla.

Posted

no, segun lo que vi en tu script nearbyPlayer representa a 1 jugador de esa tabla, nearbyPlayers (con la S al final) es la tabla con todos por lo tanto seria #nearbyPlayers en lugar de #nearbyPlayer, quedaria asi

  
outputChatBox( "[Local]["..#nearbyPlayers.."]"..getPlayerName ( source )..": #ffffff".. message, nearbyPlayer, red, green, blue, true ) 
  

(solo cambie #nearbyPlayer por #nearbyPlayers)

Posted

devuelve un numero, pero los numeros tambien funcionan con outputChatBox, por ejemplo outputChatBox(1) es lo mismo que outputChatBox("1")

Posted

en la wiki dice eso pero a mi me funcionó también de la manera que yo dije, acabo de probarlo con esto:

numero = 1234 
outputChatBox("el numero es "..numero) 

number es un numero en lugar de un string y sin embargo el mensaje sale bien.

  • Recently Browsing   0 members

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