Jump to content

can't get player from command.


King12

Recommended Posts

Hello, I've used the "getPlayerFromPartialName", but always returns that player wasn't found and no errors in debugscript.

function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function betOnPlayer ( player, cmd, amount, player2 )
	if amount and player2 then
	    local player1 = getPlayerFromPartialName ( player2 )
	    if player1 then
      	  -- code here
            else
	        outputChatBox ( "#ff1111Player not found!", player, 255, 255, 255, true )
	    end
        else
	   outputChatBox ( "#660000Use: #ffffff'/bet [player] [amount]' ..", player, 255, 255, 255, true )
	end
end

 

Link to comment
function betOnPlayer(source, cmd, amount, target)
    if amount then
        iprint("Amount")
        if target then
            local targetPlayer = getPlayerFromPartialName(target)
            outputChatBox("The player name is "..getPlayerName(targetPlayer), source)
            iprint("Target found!")        
            --- Your code here.
        else
            iprint("No target player")
        end
    else
        outputChatBox("/"..cmd.." [Amount] [Target]", source)
    end
end

 

Edited by TheMOG
  • Thanks 1
Link to comment
2 hours ago, TheMOG said:

function betOnPlayer(source, cmd, amount, target)
    if amount then
        iprint("Amount")
        if target then
            local targetPlayer = getPlayerFromPartialName(target)
            outputChatBox("The player name is "..getPlayerName(targetPlayer), source)
            iprint("Target found!")        
            --- Your code here.
        else
            iprint("No target player")
        end
    else
        outputChatBox("/"..cmd.." [Amount] [Target]", source)
    end
end

 

Worked. Thanks. ^_^

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