Jump to content

[HELP]Autoteams Mananger bugs


Recommended Posts

Hi, Hi use this script cause i need to create teams in game, and i select this cause have a gui panel, but have a lot of errors, and i dont know what to do. (I added somethings to this autoteams, like carcolor, and command "team") i use this script on race gamemode.

1.When add one team, it change of place every team example:

before add new team:

Fast Fucking War

-Xtreme Pro Racers-

after add new team:

-Xtreme Pro Racers-

Pure Skill

Fast Fucking War

It change order of teams .-. IDK Why and what to do.

Else, doesnt set me the team! i dont know why :c, somebody can help me?

Here are the codes.

client.lua

function createWindow() 
  GUI = {} 
   
  GUI["window"] = guiCreateWindow(0.225,0.225,0.55,0.55,"Team Management",true) 
  GUI["grid"] = guiCreateGridList(0.0162,0.061,0.7896,0.9178,true,GUI["window"]) 
  guiGridListSetSelectionMode(GUI["grid"],2) 
  guiGridListSetSortingEnabled(GUI["grid"], false) 
  addEventHandler("onClientGUIClick", GUI["window"], editCellLostFocus, false ) 
   
  GUI["col_name"] = guiGridListAddColumn(GUI["grid"],"Team Name",0.3) 
  GUI["col_color"] = guiGridListAddColumn(GUI["grid"],"Color",0.15) 
  GUI["col_tag"] = guiGridListAddColumn(GUI["grid"],"Tag",0.15) 
  GUI["col_group"] = guiGridListAddColumn(GUI["grid"],"ACL",0.2) 
  GUI["col_required"] = guiGridListAddColumn(GUI["grid"],"Required",0.15) 
  addEventHandler("onClientGUIClick", GUI["grid"], editCellLostFocus, false ) 
  addEventHandler("onClientGUIDoubleClick", GUI["grid"], editCellContent, false ) 
   
  GUI["btn_load"] = guiCreateButton(0.8165,0.0634,0.1673,0.0728,"Load",true,GUI["window"]) 
  addEventHandler ("onClientGUIClick", GUI["btn_load"], buttonClicked, false ) 
  GUI["btn_save"] = guiCreateButton(0.8183,0.8005,0.1655,0.0728,"Save",true,GUI["window"]) 
  addEventHandler ("onClientGUIClick", GUI["btn_save"], buttonClicked, false ) 
  GUI["btn_close"] = guiCreateButton(0.8183,0.9038,0.1655,0.0728,"Close",true,GUI["window"]) 
  addEventHandler ("onClientGUIClick", GUI["btn_close"], buttonClicked, false ) 
  GUI["btn_add"] = guiCreateButton(0.8183,0.3803,0.1655,0.0728,"Add",true,GUI["window"]) 
  addEventHandler ("onClientGUIClick", GUI["btn_add"], buttonClicked, false ) 
  GUI["btn_delete"] = guiCreateButton(0.8183,0.4671,0.1655,0.0728,"Délète",true,GUI["window"]) 
  addEventHandler ("onClientGUIClick", GUI["btn_delete"], buttonClicked, false ) 
  
  guiWindowSetSizable(GUI["window"], false) 
  guiWindowSetMovable(GUI["window"], false) 
  guiSetVisible(GUI["window"], false) 
  open = false 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()) , createWindow) 
  
function editCellAccepted() 
  if isElement(GUI["theedit"]) then 
    guiGridListSetItemText(GUI["grid"], selectedRow, selectedCol, guiGetText(GUI["theedit"]), false, false) 
    if (selectedCol == GUI["col_color"]) then 
      guiGridListSetItemColor(GUI["grid"], selectedRow, selectedCol, getColorFromString(guiGetText(GUI["theedit"]))) 
    end 
    destroyElement(GUI["theedit"]) 
  end 
  guiSetInputEnabled(false) 
end 
  
function editCellLostFocus() 
  if isElement(GUI["theedit"]) then 
    destroyElement(GUI["theedit"]) 
  end 
  guiSetInputEnabled(false) 
end 
  
function editCellContent() 
  selectedRow, selectedCol = guiGridListGetSelectedItem(GUI["grid"]) 
   
  if (selectedRow ~= -1 and selectedCol ~= -1) then 
    local text = guiGridListGetItemText( GUI["grid"], selectedRow, selectedCol ) 
    local x,y = getCursorPosition() 
  
    if isElement(GUI["theedit"]) then 
      destroyElement(GUI["theedit"]) 
    end 
    GUI["theedit"] = guiCreateEdit ( x, y, 0.125, 0.025, text, true) 
    addEventHandler("onClientGUIAccepted", GUI["theedit"], editCellAccepted, true) 
    addEventHandler("onClientGUIBlur", GUI["theedit"], editCellLostFocus, true) 
    guiSetInputEnabled(true) 
  end 
end 
  
function buttonClicked()  
  if (source == GUI["btn_close"]) then 
    wannaTogglePanel() 
  end 
  if (source == GUI["btn_load"]) then 
    triggerServerEvent( "gimmeTheFuckinList", getLocalPlayer()) 
  end 
  if (source == GUI["btn_add"]) then 
      local row = guiGridListAddRow ( GUI["grid"] ) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_name"], "-", false, false ) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_color"], "#FFFFFF", false, false ) 
    guiGridListSetItemColor(GUI["grid"], row, GUI["col_color"], getColorFromString("#FFFFFF")) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_tag"], "-", false, false ) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_group"], "-", false, false ) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_required"], "tag", false, false ) 
  end 
  if (source == GUI["btn_delete"]) then 
    local thebadbadrow = guiGridListGetSelectedItem(GUI["grid"]) 
    guiGridListRemoveRow (GUI["grid"], thebadbadrow) 
  end 
  if (source == GUI["btn_save"]) then 
    local rowCount = guiGridListGetRowCount(GUI["grid"]) 
    local i = 0 
    local theteams = {} 
    while i <= rowCount - 1 do 
      local teamname = guiGridListGetItemText(GUI["grid"], i, GUI["col_name"]) 
      theteams[teamname] = {} 
      theteams[teamname].name = teamname 
          theteams[teamname].color = guiGridListGetItemText(GUI["grid"], i, GUI["col_color"]) 
      theteams[teamname].tag = guiGridListGetItemText(GUI["grid"], i, GUI["col_tag"]) 
      theteams[teamname].aclGroup = guiGridListGetItemText(GUI["grid"], i, GUI["col_group"]) 
      theteams[teamname].required = guiGridListGetItemText(GUI["grid"], i, GUI["col_required"]) 
      i = i + 1 
    end 
    triggerServerEvent( "hereIzDaFuckinList", getLocalPlayer(), theteams) 
  end 
end 
  
function wannaTogglePanel() 
  open = not open 
  showCursor ( open ) 
  guiSetVisible(GUI["window"], open) 
  if isElement(GUI["theedit"]) then 
    guiSetVisible(GUI["theedit"], open) 
  end 
  if (open == true) then 
    triggerServerEvent( "gimmeTheFuckinList", getLocalPlayer()) 
  end 
end 
addEvent("opendaShitForme", true) 
addEventHandler("opendaShitForme", getRootElement(), wannaTogglePanel) 
  
function loadDaList(theteams) 
  guiGridListClear(GUI["grid"]) 
    for name,data in pairs(theteams) do 
      local row = guiGridListAddRow ( GUI["grid"] ) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_name"], data.name, false, false ) 
     
    local color = {getColorFromString(data.color)} 
        if not color[1] then 
            color = {255,255,255} 
        end 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_color"], data.color, false, false ) 
    guiGridListSetItemColor(GUI["grid"], row, GUI["col_color"], unpack(color)) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_tag"], data.tag, false, false ) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_group"], data.aclGroup, false, false ) 
    guiGridListSetItemText(GUI["grid"], row, GUI["col_required"], data.required, false, false ) 
  end 
end 
addEvent("hereIsDaListNub", true) 
addEventHandler("hereIsDaListNub", getRootElement(), loadDaList) 
  

Config.xml

    "Fast Fucking War" tag="-ffw-" color="#FF9e00" aclGroup="-" required="-ffw-">
    "Pure Skills" tag="~Ps|" color="#00FF00" aclGroup="-" required="~Ps|">
    "-Xtreme Pro Racers-" tag="-|XpR|-" color="#777777" aclGroup="-" required="-|XpR|-">

meta.xml

    "Autoteams Manager" author="fabienwang" type="script" version="1.2" /> 
    

server.lua

  
 
teams = {}
 
function toggleClientPanel(player)
  triggerClientEvent(player, "opendaShitForme", getRootElement() )
end
 
function onSomeoneLoggedInOwner()
  local accountName = getAccountName(getPlayerAccount(source))
  if isObjectInACLGroup("user."..accountName,aclGetGroup("Owner")) then
    unbindKey(source,"o","down", toggleClientPanel)
    bindKey(source,"o","down", toggleClientPanel)   
  end
end
addEventHandler("onPlayerLogin", getRootElement(), onSomeoneLoggedInOwner)
 
function onSomeoneLoggedInMananger()
  local accountName = getAccountName(getPlayerAccount(source))
  if isObjectInACLGroup("user."..accountName,aclGetGroup("ClanMananger")) then
    unbindKey(source,"o","down", toggleClientPanel)
    bindKey(source,"o","down", toggleClientPanel)   
  end
end
addEventHandler("onPlayerLogin", getRootElement(), onSomeoneLoggedInMananger)
 
function onSomeoneLoggedInAdmin()
  local accountName = getAccountName(getPlayerAccount(source))
  if isObjectInACLGroup("user."..accountName,aclGetGroup("Admin")) then
    unbindKey(source,"o","down", toggleClientPanel)
    bindKey(source,"o","down", toggleClientPanel)   
  end
end
addEventHandler("onPlayerLogin", getRootElement(), onSomeoneLoggedInAdmin)
 
function sendGridtoClient()
  local theteams = {}
    local rootNode = xmlLoadFile("config.xml")
    local children = xmlNodeGetChildren(rootNode)
    for _,node in pairs(children) do
        local attributes = xmlNodeGetAttributes(node)
        local name = attributes.name
        theteams[name] = attributes
    end
    xmlUnloadFile(rootNode)
    triggerClientEvent(source, "hereIsDaListNub", getRootElement(), theteams)
end
addEvent("gimmeTheFuckinList", true)
addEventHandler("gimmeTheFuckinList", getRootElement(), sendGridtoClient)
 
function saveNewTeams(theteams)
  local thexml = xmlCreateFile("config.xml", "teams")
  for name,settings in next,theteams do
    local child = xmlCreateChild(thexml, "team")
    xmlNodeSetAttribute(child, "name", name)
    xmlNodeSetAttribute(child, "tag", settings.tag)
    xmlNodeSetAttribute(child, "color", settings.color)
    xmlNodeSetAttribute(child, "aclGroup", settings.aclGroup)
    xmlNodeSetAttribute(child, "required", settings.required)
  end
  xmlSaveFile(thexml)
  xmlUnloadFile(thexml)
 
  initiate()
end
addEvent("hereIzDaFuckinList", true)
addEventHandler("hereIzDaFuckinList", getRootElement(), saveNewTeams)
------------
-- Events --
------------
 
function playerJoined()
  check(source)
end
addEventHandler("onPlayerJoin",getRootElement(),playerJoined)
 
function playerChangedNick(oldNick,newNick)
    -- Use timer to wait until the nick really has changed
    setTimer(check,100,1,source)
end
addEventHandler("onPlayerChangeNick",getRootElement(),playerChangedNick)
 
function playerQuit()
    removePlayerFromTeam(source)
end
addEventHandler("onPlayerQuit",getRootElement(),playerQuit)
 
-- Check for ACL Groups on login/logout
function loggedIn()
    check(source)
end
addEventHandler("onPlayerLogin",getRootElement(),loggedIn)
 
function loggedOut()
    check(source)
  unbindKey(source,"o","down", toggleClientPanel)
end
addEventHandler("onPlayerLogout",getRootElement(),loggedOut)
 
 
---
-- Reads the settings and creates the teams if enabled.
--
function initiate()
  teams = {}
 
    for k,v in pairs(getElementsByType("team")) do
    local players = getPlayersInTeam (v)
        for playerKey, playerValue in ipairs ( players ) do
            setPlayerTeam( playerValue, nil)
        end
        destroyElement(v)
    end
   
    local rootNode = xmlLoadFile("config.xml")
    local children = xmlNodeGetChildren(rootNode)
    if children == false then
        outputDebugString("children == false")
        return
    end
    for _,node in pairs(children) do
        local attributes = xmlNodeGetAttributes(node)
        local name = attributes.name
        teams[name] = attributes
        if not toboolean(get("noEmptyTeams")) then
          local color = {getColorFromString(attributes.color)}
          if not color[1] then
              color = {255,255,255}
          end
            teams[name].team = createTeam(name,unpack(color))
        end
    end
    for k,v in pairs(getElementsByType("player")) do
        check(v)
    end
    xmlUnloadFile(rootNode)
end
addEventHandler("onResourceStart",getResourceRootElement(),initiate)
 
---------------
-- Functions --
---------------
 
---
-- Checks the player's nick and ACL Groups and sets his team if necessary.
--
-- @param   player   player: The player element
--
function check(player)
    if not isElement(player) or getElementType(player) ~= "player" then
        debug("No player")
        return
    end
    local nick = getPlayerName(player)
   
    --set player white
    setPlayerNametagColor(player, 255,255,255)
   
    local accountName = getAccountName(getPlayerAccount(player))
    for name,data in pairs(teams) do
        local tagMatch = false
        local aclGroupMatch = false
        if data.tag ~= nil and string.find(nick,data.tag,1,true) then
            tagMatch = true
        end
        if data.aclGroup ~= nil and accountName and isObjectInACLGroup("user."..accountName,aclGetGroup(data.aclGroup)) then
            aclGroupMatch = true
        end
        if data.required == "both" then
            if tagMatch and aclGroupMatch then
                addPlayerToTeam(player,name)
        --Check Vehicle color (and set it to team color)
        if isPedInVehicle(player) then
          local vehicle = getPedOccupiedVehicle(player)
          if getPedOccupiedVehicleSeat(player) == 0 then
            if getPlayerTeam(player) then
                local r,g,b = getTeamColor(getPlayerTeam(player))
                setVehicleColor(vehicle,r,g,b,r,g,b,r,g,b,r,g,b)
                setPlayerNametagColor(player, r,g,b)
            else
              setVehicleColor(vehicle,255,255,255,255,255,255,255,255,255,255,255,255)
            end
          end
        end
                return
            end
        else
            if tagMatch or aclGroupMatch then
                addPlayerToTeam(player,name)
        --Check Vehicle color (and set it to team color)
        if isPedInVehicle(player) then
          local vehicle = getPedOccupiedVehicle(player)
          if getPedOccupiedVehicleSeat(player) == 0 then
            if getPlayerTeam(player) then
                local r,g,b = getTeamColor(getPlayerTeam(player))
                setVehicleColor(vehicle,r,g,b,r,g,b,r,g,b,r,g,b)
                setPlayerNametagColor(player, r,g,b)
            else
              setVehicleColor(vehicle,255,255,255,255,255,255,255,255,255,255,255,255)
            end
          end
        end
                return
            end
        end
    end
    removePlayerFromTeam(player)
   
--Check Vehicle color (and set it to team color)
    if isPedInVehicle(player) then
      local vehicle = getPedOccupiedVehicle(player)
      if getPedOccupiedVehicleSeat(player) == 0 then
      if getPlayerTeam(player) then
            local r,g,b = getTeamColor(getPlayerTeam(player))
            setVehicleColor(vehicle,r,g,b,r,g,b,r,g,b,r,g,b)
            setPlayerNametagColor(player, r,g,b)
      else
        setVehicleColor(vehicle,255,255,255,255,255,255,255,255,255,255,255,255)
      end
      end
    end
   
end
 
---
-- Adds a player to the team appropriate for the name.
-- It is not checked if the team is really defined in the table, since
-- it should only be called if it is.
--
-- Creates the team if it doesn't exist.
--
-- @param   player   player: The player element
-- @param   string   name: The name of the team
--
function addPlayerToTeam(player,name)
    local oldteam = getPlayerTeam(player)
    local team = teams[name].team
    if not isElement(team) or getElementType(team) ~= "team" then
      local color = {getColorFromString(teams[name].color)}
      if not color[1] then
          color = {255,255,255}
      end
       
        team = createTeam(teams[name].name,unpack(color))
        teams[name].team = team
    elseif team == oldteam then
        return
    end
    triggerEvent("onPlayerTeamChange", player, oldteam, team)
    setPlayerTeam(player,team)
    debug("Added player '"..
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...