Edit: Source Code: (Server-Side)
function getPlayerFromPartialName(who) --Useful Function | Author: TAPL local who = who and who:gsub("#%x%x%x%x%x%x", ""):lower() or nil if who then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(who, 1, true) then return player end end end end --x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x-- function createATeam(source, commandName, teamName) team = getPlayerTeam(source) if team then outputChatBox("You are already in a team", source, 255, 0, 0) return end if teamName then local newTeam = createTeam(teamName) if newTeam then setPlayerTeam(source, newTeam) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount, "isTeamLeader", true) --XML local xmlFile = xmlLoadFile("teams.xml", "root") local team = xmlCreateChild(xmlFile, "team") local success = xmlNodeSetAttribute(team, "name", teamName) if success then xmlSaveFile(xmlFile) elseif not success then outputChatBox("XML FATAL ERROR: Failed to save a team in the XML Team file") destroyElement(team) end --END XML outputChatBox("Successfully created team with name: "..teamName, source, 0, 255, 0) end else outputChatBox("Please enter a team name", thePlayer, 255, 0, 0) end end addCommandHandler("create", createATeam) function inviteToTeam(thePlayer, cmd, who) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") == true then local target = getPlayerFromPartialName(who) if target then if target ~= thePlayer then if not getElementData(target, "invited_to_team") then local teamName = getTeamName(team) setElementData(target, "invited_to_team", true) setElementData(target, "team_invited_to", teamName) setElementData(target, "inviters_name", thePlayer) outputChatBox("Invited player "..target.." to team !", thePlayer, 0, 255, 0) outputChatBox("You were invited to the team"..teamName.." !", target, 0, 255, 0) outputChatBox("Type '/team accept' or '/team deny'", target, 0, 255, 0) elseif getElementData(target, "invited_to_team") then outputChatBox("The player is already invited to a team", thePlayer, 255, 0, 0) return end else outputChatBox("You cannot invite yourself", thePlayer, 255, 0, 0) end else outputChatBox("Failed to fetch target", thePlayer, 255, 0, 0) end else outputChatBox("Access forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("invite", inviteToTeam) function inviteHandling(thePlayer, cmd, arg) if arg then if getElementData(thePlayer, "invited_to_team") == true then if arg == "accept" then local team = getPlayerTeam(thePlayer) if getPlayerTeam(thePlayer) == nil then local inviterElement = getElementData(thePlayer, "inviters_name") local theTeam = getElementData(thePlayer, "team_invited_to") local thePlayersName = getPlayerName(thePlayer) local inviter = getPlayerFromName(inviterElement) local teamName = getTeamName(theTeam) setPlayerTeam(thePlayer, theTeam) outputChatBox(thePlayersName.." has joined !", inviter, 0, 255, 0) setElementData(thePlayer, "invited_to_team", false) elseif team then outputChatBox("You are already in a team ! Leave it before joining another.", thePlayer, 255, 0, 0) end elseif arg == "deny" then local inviterElement = getElementData(thePlayer, "inviters_name") local thePlayersName = getPlayerName(thePlayer) local inviter = getPlayerFromName(inviterElement) setElementData(thePlayer, "invited_to_team", false) setElementData(thePlayer, "team_invited_to", false) outputChatBox(thePlayersName.." has declined the invitation !", inviter, 255, 0, 0) outputChatBox("Invitation declined", thePlayer, 0, 255, 0) end else outputChatBox("You are not invited to any team", thePlayer, 255, 0, 0) end else outputChatBox("Argument 2 is missing. arg2 = accept/deny", thePlayer, 255, 0, 0) end end addCommandHandler("team", inviteHandling) function setAnotherPlayerLeader(thePlayer, cmd, who) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") == true then target = getPlayerFromPartialName(who) if target then if target ~= thePlayer then if getPlayerTeam(target) == team then local targetAccount = getPlayerAccount(target) setAccountData(targetAccount, "isTeamAdmin", true) local targetPlayerName = getPlayerName(target) outputChatBox(targetPlayerName.." added as leader !", thePlayer, 0, 255, 0) local teamName = getTeamName(team) outputChatBox("You were added as a leader in team: "..teamName.." !", target, 0, 255, 0) else outputChatBox("Player not in team", thePlayer, 255, 0, 0) end else outputChatBox("You cannot permit yourself", thePlayer, 255, 0, 0) end else outputChatBox("Failed to fetch target", thePlayer, 255, 0, 0) end else outputChatBox("Access Forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("permit", setAnotherPlayerLeader) function kickFromTeam(thePlayer, cmd, who) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") == true or getAccountData(playerAccount, "isTeamAdmin") == true then target = getPlayerFromPartialName(who) if target then if target ~= thePlayer then if getPlayerTeam(target) == team then local targetAccount = getPlayerAccount(target) if not getAccountData(targetAccount, "isTeamLeader") then setPlayerTeam(target, nil) local targetPlayerName = getPlayerName(target) outputChatBox("Kicked "..targetPlayerName.." from team !", thePlayer, 0, 255, 00) outputChatBox("You were kicked from the team ! D:", target, 255, 0, 0) else outputChatBox("You cannot kick the leader !", thePlayer) end else outputChatBox("Player not in team", thePlayer, 255, 0, 0) end else outputChatBox("You cannot kick yourself", thePlayer, 255, 0, 0) end else outputChatBox("Failed to fetch target", thePlayer, 255, 0, 0) end else outputChatBox("Access Forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("tkick", kickFromTeam) function leaveTeam(thePlayer) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if not getAccountData(playerAccount, "isTeamLeader") then if getAccountData(playerAccount, "isTeamAdmin") then setAccountData(playerAccount, "isTeamAdmin", false) end setPlayerTeam(thePlayer, nil) local teamName = getTeamName(team) outputChatBox("You left the team "..teamName.." !", thePlayer, 0, 255, 0) local teamPlayers = getPlayersInTeam(team) local playerName = getPlayerName(thePlayer) for playerKey, playerValue in ipairs(teamPlayers) do outputChatBox(playerName.." left the team ! D:", playerValue, 255, 0, 0) end else outputChatBox("You can not leave as a leader", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("leave", leaveTeam) function deleteTeam(thePlayer) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") then local teamPlayers = getPlayersInTeam(team) for playerKey, playerValue in ipairs(teamPlayers) do if playerValue ~= thePlayer then accTeamMembers = getPlayerAccount(playerValue) if getAccountData(accTeamMembers, "isTeamAdmin") then setAccountData(accTeamMembers, "isTeamAdmin", false) end setPlayerTeam(playerValue, nil) outputChatBox("Kicked from team because it was deleted \"{SMILIES_PATH}/icon_sad.gif\" alt=\"\" title=\"Sad\" />", playerValue, 255, 0, 0) end end --XML local teamName = getTeamName(team) local xmlFile = xmlLoadFile("teams.xml") local children = xmlNodeGetChildren(xmlFile) for i,node in pairs(children) do local attributes = xmlNodeGetAttributes(node) if attributes == teamName then xmlDestroyNode(node) end end --END XML destroyElement(team) setAccountData(playerAccount, "isTeamLeader", false) setPlayerTeam(thePlayer, nil) outputChatBox("The team has been deleted", thePlayer, 0, 255, 0) else outputChatBox("Access Forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end