Jump to content

[HELP] I need help with a custom PM system.


Recommended Posts

Hello. I am attempting to make a custom PM system but I am having some issues. I get no errors but it sends the pm to me no matter what... I am confused.

*EDIT* So I figured this out the PM works... it sends right but it sends to global when there is no one in the server with that name. or partial name... still really confused.

  
function privateMessageTwo(player, command, sentTo, ...) 
    if (command == "pm") then 
        local messageTable = {...} 
        local message = table.concat(messageTable, " ") 
        local sendTo = getPlayerFromPartialName(sentTo, player) 
        if (sendTo ~= "") then 
            if (message ~= "") then 
                outputChatBox("#00FF00[PM FROM]#FFFFFF"..getPlayerName(player).."#BDBDBD: "..message, sendTo, 255, 255, 255, true) 
                outputChatBox("#00FF00[PM TO]#FFFFFF"..getPlayerName(sendTo).."#BDBDBD: "..message, player, 255, 255, 255, true) 
            else 
                outputChatBox("Failed No Message") 
            end 
        else 
            outputChatBox("Failed No Name") 
        end 
    else 
        outputChatBox("Failed No Command") 
    end 
end 
addCommandHandler("pm", privateMessageTwo) 
  
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 
  

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