0 Üye ve 1 Ziyaretçi konuyu incelemekte.
teams = {}function toggleClientPanel(player) triggerClientEvent(player, "opendaShitForme", getRootElement() )endfunction onSomeoneLoggedIn() local accountName = getAccountName(getPlayerAccount(source)) if isObjectInACLGroup("user."..accountName,aclGetGroup("Admin")) then unbindKey(source,"k","down", toggleClientPanel) bindKey(source,"k","down", toggleClientPanel) endendaddEventHandler("onPlayerLogin", getRootElement(), onSomeoneLoggedIn)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)endaddEvent("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()endaddEvent("hereIzDaFuckinList", true)addEventHandler("hereIzDaFuckinList", getRootElement(), saveNewTeams)function startedResource() for k,v in pairs(getElementsByType("player")) do local accountName = getAccountName(getPlayerAccount(v)) if isObjectInACLGroup("user."..accountName,aclGetGroup("Admin")) then if (isKeyBound (v,"k") == false) then unbindKey(v,"k","down", toggleClientPanel) bindKey(v,"k","down", toggleClientPanel) end end endendaddEventHandler("onResourceStart",getResourceRootElement(),startedResource)-------------- Events --------------function playerJoined() check(source)endaddEventHandler("onPlayerJoin",getRootElement(),playerJoined)function playerChangedNick(oldNick,newNick) -- Use timer to wait until the nick really has changed setTimer(check,100,1,source)endaddEventHandler("onPlayerChangeNick",getRootElement(),playerChangedNick)function playerQuit() removePlayerFromTeam(source)endaddEventHandler("onPlayerQuit",getRootElement(),playerQuit)-- Check for ACL Groups on login/logoutfunction loggedIn() check(source)endaddEventHandler("onPlayerLogin",getRootElement(),loggedIn)function loggedOut() check(source) unbindKey(source,"k","down", toggleClientPanel)endaddEventHandler("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)endaddEventHandler("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 '"..getPlayerName(player).."' to team '"..name.."'")end----- Removes a player from a team. Also checks if any team-- needs to be removed.---- @param player player: The player element--function removePlayerFromTeam(player) triggerEvent("onPlayerTeamChange", player, getPlayerTeam(player), nil) setPlayerTeam(player,nil) debug("Removed player '"..getPlayerName(player).."' from team") if toboolean(get("noEmptyTeams")) then for k,v in pairs(teams) do local team = v.team if isElement(team) and getElementType(team) == "team" then if countPlayersInTeam(team) == 0 then destroyElement(team) end end end endendfunction vehiclepaint(player,seat) if (seat == 0) then if (getPlayerTeam(player)) then local r,g,b = getTeamColor(getPlayerTeam(player)) --setVehicleColor(source,r,g,b,r,g,b,r,g,b,r,g,b) setPlayerNametagColor(player, r,g,b) else --setVehicleColor(source,255,255,255,255,255,255,255,255,255,255,255,255) setPlayerNametagColor(player, 255,255,255) end endendaddEventHandler("onVehicleEnter",getRootElement(),vehiclepaint)function vehicleModelChange(pickupID, pickupType, vehicleModel) if (pickupType == "vehiclechange") then if getPlayerTeam(source) then local r,g,b = getTeamColor(getPlayerTeam(source)) local vehicle = getPedOccupiedVehicle(source) if getPedOccupiedVehicleSeat(source) == 0 then --setVehicleColor(vehicle,r,g,b,r,g,b,r,g,b,r,g,b) end setPlayerNametagColor(source, r,g,b) else local vehicle = getPedOccupiedVehicle(source) if getPedOccupiedVehicleSeat(source) == 0 then --setVehicleColor(vehicle,255,255,255,255,255,255,255,255,255,255,255,255) end setPlayerNametagColor(source, 255,255,255) end endendaddEventHandler("onPlayerPickUpRacePickup", getRootElement(), vehicleModelChange)----- Converts a string-boolean into a boolean.---- @param string string: The string (e.g. "false")-- [member=6036]return[/member] true/false Returns false if the string is "false" or evaluates to false (nil/false), true otherwise--function toboolean(string) if string == "false" or not string then return false end return trueend-- Little debug function to turn on/off debugsetElementData(getResourceRootElement(),"debug",false)function debug(string) if getElementData(getResourceRootElement(),"debug") then outputDebugString("autoteams: "..string) endend
function createWindow() GUI = {} GUI["window"] = guiCreateWindow(0.225,0.225,0.55,0.55,"Scoreboard Takım Oluşturma | (K) ",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"],"Group",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,"Dön",true,GUI["window"]) addEventHandler ("onClientGUIClick", GUI["btn_load"], buttonClicked, false ) GUI["btn_save"] = guiCreateButton(0.8183,0.8005,0.1655,0.0728,"Kaydet",true,GUI["window"]) addEventHandler ("onClientGUIClick", GUI["btn_save"], buttonClicked, false ) GUI["btn_close"] = guiCreateButton(0.8183,0.9038,0.1655,0.0728,"Çıkış",true,GUI["window"]) addEventHandler ("onClientGUIClick", GUI["btn_close"], buttonClicked, false ) GUI["btn_add"] = guiCreateButton(0.8183,0.3803,0.1655,0.0728,"Ekle",true,GUI["window"]) addEventHandler ("onClientGUIClick", GUI["btn_add"], buttonClicked, false ) GUI["btn_delete"] = guiCreateButton(0.8183,0.4671,0.1655,0.0728,"Kaldır",true,GUI["window"]) addEventHandler ("onClientGUIClick", GUI["btn_delete"], buttonClicked, false ) guiWindowSetSizable(GUI["window"], false) guiWindowSetMovable(GUI["window"], false) guiSetVisible(GUI["window"], false) open = falseendaddEventHandler("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)endfunction editCellLostFocus() if isElement(GUI["theedit"]) then destroyElement(GUI["theedit"]) end guiSetInputEnabled(false)endfunction 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) endendfunction 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) endendfunction 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()) endendaddEvent("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 ) endendaddEvent("hereIsDaListNub", true)addEventHandler("hereIsDaListNub", getRootElement(), loadDaList)