Jump to content

I need support in scripting for teams


#[B]lack

Recommended Posts

"how do I perform the sum of the returned values of the teams, they return in number but when performing the sum to be displayed in the DX occurs error can anyone else?"

 

local dende = "dende"
local acari = "acari"
local cidadealta = "cidadealta"


function parte (_,state)
if parte1 == false then
showCursor(true)
addEventHandler("onClientRender", root, part1)
parte1 = true
else
showCursor(false)
removeEventHandler("onClientRender", root, part1)
parte1 = false
end
end
bindKey("F7", "down", parte)
 

local screenW2,screenH2 = guiGetScreenSize()
local resW2, resH2 = 1366,768
local x, y =  (screenW2/resW2/2), (screenH2/resH2/2)

local parte1 = false


local comandovermelho = countPlayersInTeam(dende)
local comandovermelho2 = countPlayersInTeam(acari)
local comandovermelho3 = countPlayersInTeam(cidadealta)

local resultado = (tonumber(comandovermelho) + tonumber(comandovermelho2) + tonumber(comandovermelho3))

function part1 ()
      if(countPlayersInTeam(comandovermelho) > 0)then
        dxDrawText("Valor:"..resultado, 656, 500, 719, 311, tocolor(0, 255, 0, 255), 1.40, "default-bold", "left", "top", false, false, false, true, false)

      else
        dxDrawText("Online:".. countPlayersInTeam(comandovermelho), 656, 320, 719, 311, tocolor(255, 0, 0, 255), 1.40, "default-bold", "left", "top", false, false, false, true, false)
      end
    end
 

local x,y = guiGetScreenSize()
 
function isCursorOnElement(x,y,w,h)
    local mx,my = getCursorPosition ()
    local fullx,fully = guiGetScreenSize()
    cursorx,cursory = mx*fullx,my*fully
    if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then
        return true
    else
        return false
    end
end

Link to comment

Well, first of all, countPlayersInTeam takes a team element, not team name. Use getTeamFromName to get a team element from name.

local dende = "dende"
local acari = "acari"
local cidadealta = "cidadealta"
-- [...]
local comandovermelho = countPlayersInTeam(getTeamFromName(dende)) -- fixed this for ya
local comandovermelho2 = countPlayersInTeam(getTeamFromName(acari)) -- fixed this for ya
local comandovermelho3 = countPlayersInTeam(getTeamFromName(cidadealta)) -- fixed this for ya

Another thing you did is

-- this snippet does not include the fix from above
local comandovermelho = countPlayersInTeam(dende)
-- [...]
if(countPlayersInTeam(comandovermelho) > 0)then

comandovermelho is not a team element, but the return from countPlayersInTeam, in this case, a false (boolean) as you've tried to count players in a team name rather than the actual team (the team element). Use the fixed comandovermelho from the snippet above, and the if-statement line should read

if (comandovermelho > 0) then

 

Edited by MrTasty
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...