Jump to content

Changing player's team


Bleidex

Recommended Posts

Tested this code with debugscript, but when it do command /ct Bleidex it just doesnt do anything - no errors in debugscript, nothing. getPlayerWildcard is from lil toadys admin panel script.

function getPlayerWildcard ( string ) 
    local player = getPlayerFromName ( string ) 
    if ( player ) then return player end 
    local matches = {} 
    for id, player in ipairs ( getElementsByType ( "player" ) ) do 
        if ( string.find ( string.upper ( getPlayerName ( player ) ), string.upper ( string ), 1, true ) ) then 
            table.insert(matches,player) 
        end 
    end 
    if #matches == 0 then 
        return false, "'" .. string .. "' matches no players." 
    elseif #matches == 1 then 
        return matches[1] 
    else 
        return false, "'" .. string .. "' matches ".. tostring(#matches) .. " players." 
    end 
end 
  
function changeTeam ( sourcePlayer, command, who ) 
    local targetPlayer = getPlayerWildcard ( who ) 
    local targetName = getPlayerName ( targetPlayer ) 
    local targetTeam = getPlayerTeam ( targetPlayer ) 
    local sourceAccount = getPlayerAccount ( sourcePlayer ) 
    local sourceName = getPlayerName ( sourcePlayer ) 
    local accName = getAccountName ( getPlayerAccount ( sourcePlayer ) ) 
        if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then 
        if ( targetPlayer ) then 
            if targetTeam == "Red" then 
                setPlayerTeam ( targetPlayer, "Blue" ) 
                outputChatBox ( sourceName .. "#FFFF00) has changed your team to #0000FFBlue#FFFF00.", targetPlayer, 255, 255, 0, true ) 
                outputChatBox ( sourceName .. "#FFFF00 has changed " .. string.gsub(targetName, "#%x%x%x%x%x%x", "") .. "'s#FFFF00 team to #0000FFBlue#FFFF00.", getRootElement(), 255, 255, 0, true ) 
                outputChatBox ( "You have succesfully changed " .. string.gsub(targetName, "#%x%x%x%x%x%x", "") .. "'s team to #0000FFBlue#FFFF00.", sourcePlayer, 255, 255, 0, true ) 
            elseif targetTeam == "Blue" then 
                setPlayerTeam ( targetPlayer, "Red" ) 
                outputChatBox ( sourceName .. "#FFFF00 has changed your team to #FF0000Red#FFFF00.", targetPlayer, 255, 255, 0, true ) 
                outputChatBox ( sourceName .. "#FFFF00 has changed " .. string.gsub(targetName, "#%x%x%x%x%x%x", "") .. "'s#FFFF00 team to #FF0000Red#FFFF00.", getRootElement(), 255, 255, 0, true ) 
                outputChatBox ( "You have succesfully changed " .. string.gsub(targetName, "#%x%x%x%x%x%x", "") .. "'s team to #Ff0000Red#FFFF00.", sourcePlayer, 255, 255, 0, true ) 
            end 
        else 
            outputChatBox ( "Player not found.", sourcePlayer, 255, 0, 0, false ) 
        end 
    else 
        outputChatBox ( "You don't have enough rights.", sourcePlayer, 255, 0, 0, false ) 
    end 
end 
addCommandHandler ( "changeteam", changeTeam ) 
addCommandHandler ( "ct", changeTeam ) 

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...