Jump to content

Team script


Recommended Posts

Posted

Hello, i'm trying to set player team by a command like example /invite [playername] [teamname] for set player team and /dismiss [playername] [teamname] for remove player from team.

i searched on the wiki and i found this https://wiki.multitheftauto.com/wiki/SetPlayerTeam

but it set team only for me not for other players

function assignNewTeam ( source, commandName, teamName ) 
  local theTeam = createTeam ( teamName )   
  if theTeam then                           
    setPlayerTeam ( source, theTeam )     
  end 
end 
addCommandHandler ( "invite", assignNewTeam ) 
  
function unassignTeam ( source, commandName ) 
  local theTeam = getPlayerTeam ( source )   
  if theTeam then                           
    setPlayerTeam ( source, nil )     
  end 
end 
addCommandHandler ( "dismiss", unassignTeam ) 

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted (edited)

try this:

--Thanks TAPL for Useful Function!!! 
function getPlayerFromNamePart(name) 
    if name then  
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player  
            end 
        end 
    end 
    return false 
end 
  
function assignNewTeam ( source, _, playername, teamname  ) 
    if not playername then 
        outputChatBox("Please enter in the player's name that you would like to remove from team!",source,255,0,0) 
        return 
    end 
    local player = getPlayerFromName(playername) 
    if not player then 
        player = getPlayerFromNamePart(playername) 
    end 
    if not player or isElement(player) then 
        outputChatBox("Sorry, player doesn't exist!",source,255,0,0) 
        return 
    end 
    local theTeam = getTeamFromName ( teamname ) 
    if not theTeam then 
        theTeam = createTeam ( teamName ) 
    end                         
    setPlayerTeam ( source, theTeam ) 
end 
addCommandHandler ( "invite", assignNewTeam ) 
  
function unassignTeam ( source, _, playername, teamname ) 
    if not playername then 
        outputChatBox("Please enter in the player's name that you would like to remove from team!",source,255,0,0) 
        return 
    end 
    local player = getPlayerFromName(playername) 
    if not player then 
        player = getPlayerFromNamePart(playername) 
    end 
    if not player or isElement(player) then 
        outputChatBox("Sorry, player doesn't exist!",source,255,0,0) 
        return 
    end 
    local theTeam = getPlayerTeam ( player ) 
    if not theTeam then 
        outputChatBox("Player isn't on a team!",source,255,0,0) 
        return 
    end 
    setPlayerTeam ( player, nil ) 
end 
addCommandHandler ( "dismiss", unassignTeam ) 

Edited by Guest

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

Ok i'm gonna try but what about

function assignNewTeam ( source, commandName, teamName ) 
  local theTeam = createTeam ( teamName )   
  if theTeam then                           
    setPlayerTeam ( source, theTeam )     
  end 
end 
addCommandHandler ( "invite", assignNewTeam ) 

thanks for help :)

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted (edited)

Sorry i didn't saw it :)

Edited by Guest

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Server side or client side?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Ok.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Working perfect Thanks alot :D

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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