Jump to content

Get a part of name but it don't output it all..


King12

Recommended Posts

Hello,

I've used this function getPlayerFromPartialName :

  
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 
  

it worked fine with my AddCommandHandler event, but when it outputs the name, you will see the name you wrote.

for example, my name is King12 if I write /setxp Ki 1000 it will output Ki only not my full name..

My codes :

  
addCommandHandler ( "setlevel", 
    function( thePlayer, _, playerName, Level ) 
        local Level = tonumber ( Level ) or 0 
        local ThePlayer = getPlayerFromPartialName(playerName) 
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then       
            if ( ThePlayer ) then 
                setElementData( ThePlayer,"Level",Level ) 
                outputChatBox ( "Succesfully set " ..playerName.. "#00C800's Level to "..Level.." !", getRootElement(), 0, 200, 0, true , source ) 
                triggerClientEvent(ThePlayer, 'LevelSound', ThePlayer ) 
            else 
                outputChatBox ( "Couldn't find '" ..playerName1.. "#00C800'", getRootElement(), 200, 0, 0, true , source )       
            end 
        end  
    end 
) 
  

Link to comment
  
  
addCommandHandler ( "setlevel", 
    function( thePlayer, _, playerName, Level ) 
        local Level = tonumber ( Level ) or 0 
        local ThePlayer = getPlayerFromPartialName(tostring(playerName)) 
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then      
            if ( ThePlayer ) then 
                setElementData( ThePlayer,"Level",Level ) 
                outputChatBox ( "Succesfully set " ..getPlayerName(ThePlayer).. "#00C800's Level to "..Level.." !", getRootElement(), 0, 200, 0, true , source ) 
                triggerClientEvent(ThePlayer, 'LevelSound', ThePlayer ) 
            else 
                outputChatBox ( "Couldn't find '" ..playerName1.. "#00C800'", getRootElement(), 200, 0, 0, true , source )      
            end 
        end  
    end 
) 
  
  

Edited by Guest
Link to comment

try this :

addCommandHandler ( "setlevel", 
    function( thePlayer, _, playerName, Level ) 
        local Level = tonumber ( Level ) or 0 
        local ThePlayer = getPlayerFromPartialName(playerName) 
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then      
            if ( ThePlayer ) then 
                setElementData( ThePlayer,"Level",Level ) 
                outputChatBox ( "Succesfully set " ..getPlayerName ( ThePlayer ).. "#00C800's Level to "..Level.." !", thePlayer, 0, 200, 0, true  ) 
                triggerClientEvent(ThePlayer, 'LevelSound', ThePlayer ) 
            else 
                outputChatBox ( "Couldn't find '" ..playerName.. "#00C800'", thePlayer, 200, 0, 0, true  )      
            end 
        end  
    end 
) 
Edited by Guest
Link to comment
try this :

addCommandHandler ( "setlevel", 
    function( thePlayer, _, playerName, Level ) 
        local Level = tonumber ( Level ) or 0 
        local ThePlayer = getPlayerFromPartialName(playerName) 
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then      
            if ( ThePlayer ) then 
                setElementData( ThePlayer,"Level",Level ) 
                outputChatBox ( "Succesfully set " ..getPlayerName ( playerName ).. "#00C800's Level to "..Level.." !", thePlayer, 0, 200, 0, true  ) 
                triggerClientEvent(ThePlayer, 'LevelSound', ThePlayer ) 
            else 
                outputChatBox ( "Couldn't find '" ..playerName.. "#00C800'", thePlayer, 200, 0, 0, true  )      
            end 
        end  
    end 
) 

Wait? getPlayerName with a text which is not a string? First arguement should be the player element shouldn't it be?

Link to comment
what u mean ! ?

No need to argue.

Please don't reply, you should understand your mistake.

If you use getPlayerName with "ki" it will not work. getPlayerName needs a element which is a player not player's name. Check out wiki. He defined ThePlayer with the function which returns the player name so you can use getPlayerName on it. Your arguement was wrong. You should've used ThePlayer.

Link to comment
No problem, but don't do that mistake again. You should always read the script carefully. Don't reply please. Topic should be locked as problem is solved.

bro u don't see yourself .. ? we are human ! and we do mistake

but u don't see yourself when u mistake .. my mistake i'm don't see this problem .. but your mistakes is real big mistake

next time see yourself Before see my small mistakes

last reply -_-

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