Jump to content

Help please


Recommended Posts

Posted

Hello, can somebody fix this script for me, when i do /invite playername it show on chatbox player dont exist but he exist, anyway here is the code.

  
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 ) 

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

( ( Not Tested ) )

  
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 not 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 ) 

Posted
( ( Not Tested ) )
  
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 not 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 ) 

What did you edited, also the source is defined difficult by MTA.

To Visit Us

Press Here: mtasa://5.9.206.180:22002

b648040241b8f01.png

0d0a7bb38ca13e5.png

Posted

addCommandHandler has no 'source'.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted
addCommandHandler has no 'source'.

yes, but he define it:

function assignNewTeam ( source, _, playername, teamname  ) 

I would have written it as player, because a source can be a lot.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

I was answering to this guy:

( ( Not Tested ) )
  
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 not 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 ) 

What did you edited, also the source is defined difficult by MTA.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted
I was answering to this guy:

ah sorry.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Nobody can fix?

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

What is the problem with it?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Everytime i invite player to team and the player exist it write the player dont exist.

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

Try this:

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 = getPlayerFromNamePart(playername) 
    if not player then 
        outputChatBox("Sorry, player doesn't exist!",source,255,0,0) 
        return 
    end 
    local theTeam = getTeamFromName ( teamname ) 
    if theTeam then 
        setPlayerTeam ( source, theTeam ) 
    end 
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 = getPlayerFromNamePart(playername) 
    if not 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 ) 
  

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

Working fine thanks.

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