Jump to content

Script not work


Dimos7

Recommended Posts

function privateMessage(thePlayer, sendToName, id, ...) 
    local message = table.concat({...}, "") 
    if id then 
       target = getPlayerFromID(id) 
       if target == false or target == nil then 
          outputChatBox("That id has not conencted", player, 255, 0, 0) 
          return 
       end 
    end 
    if sendToName then 
       if (getPlayerFromPartialName(sendToName)) then 
           toPlayer = (getPlayerFromPartialName(sendToName))  
           if not(toPlayer == thePlayer) then 
              if not message == "" then 
                 outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) 
                 outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) 
                 setElementData(thePlayer, "pmPartner", toPlayer) 
                 setElementData(toPlayer, "pmPartner", thePlayer) 
              else 
                 outputChatBox("Syntax:/pm [part of name]/ [id] [message]", thePlayer, 255, 0, 0) 
                 return false 
              end 
            else 
               outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) 
               return false 
            end 
        else 
           outputChatBox("Player not found.", thePlayer, 255, 0, 0) 
           return false 
        end 
    else 
        outputChatBox("Syntax: /pm [part of name] /[id] [message]", thePlayer, 255, 0, 0) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

getPlayerFromPartialName take a nil value

Edited by Guest
Link to comment
function privateMessage(thePlayer, _, sendToName, ...) 
    local message = table.concat({...}, "") 
    if id then 
       target = getPlayerFromID(id) 
       if target == false or target == nil then 
          outputChatBox("That id has not conencted", player, 255, 0, 0) 
          return 
       end 
    end 
    if sendToName then 
       if (getPlayerFromPartialName(sendToName)) then 
           toPlayer = (getPlayerFromPartialName(sendToName)) 
           if not(toPlayer == thePlayer) then 
              if not message == "" then 
                 outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) 
                 outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) 
                 setElementData(thePlayer, "pmPartner", toPlayer) 
                 setElementData(toPlayer, "pmPartner", thePlayer) 
              else 
                 outputChatBox("Syntax:/pm [part of name]/ [id] [message]", thePlayer, 255, 0, 0) 
                 return false 
              end 
            else 
               outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) 
               return false 
            end 
        else 
           outputChatBox("Player not found.", thePlayer, 255, 0, 0) 
           return false 
        end 
    else 
        outputChatBox("Syntax: /pm [part of name] /[id] [message]", thePlayer, 255, 0, 0) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

Link to comment

still the same

function privateMessage(thePlayer, _, sendToName,  ...) 
    local message = table.concat({...}, "") 
    if id then 
       target = getPlayerFromID(id) 
       if target == false or target == nil then 
          outputChatBox("That id has not conencted", player, 255, 0, 0) 
          return 
       end 
    end 
    if sendToName then 
       if (getPlayerFromPartialName(sendToName)) then 
           toPlayer = (getPlayerFromPartialName(sendToName)) 
           if not(toPlayer == thePlayer) then 
              if not message == "" then 
                 outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) 
                 outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) 
                 setElementData(thePlayer, "pmPartner", toPlayer) 
                 setElementData(toPlayer, "pmPartner", thePlayer) 
              else 
                 outputChatBox("Syntax:/pm [part of name]/ [id] [message]", thePlayer, 255, 0, 0) 
                 return false 
              end 
            else 
               outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) 
               return false 
            end 
        else 
           outputChatBox("Player not found.", thePlayer, 255, 0, 0) 
           return false 
        end 
    else 
        outputChatBox("Syntax: /pm [part of name] /[id] [message]", thePlayer, 255, 0, 0) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

Link to comment

Did you add getPlayerFromPartialName function name before?

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
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 privateMessage(thePlayer, sendToName,  ...) 
    local message = table.concat({...}, "") 
    if sendToName then 
       if (getPlayerFromPartialName(sendToName)) then 
           toPlayer = (getPlayerFromPartialName(sendToName)) 
           if not(toPlayer == thePlayer) then 
              if not message == "" then 
                 outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) 
                 outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) 
                 setElementData(thePlayer, "pmPartner", toPlayer) 
                 setElementData(toPlayer, "pmPartner", thePlayer) 
              else 
                 outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) 
                 return false 
              end 
            else 
               outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) 
               return false 
            end 
        else 
           outputChatBox("Player not found.", thePlayer, 255, 0, 0) 
           return false 
        end 
    else 
        outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

Now every name i put no find the player wtf

Link to comment
function getPlayerFromPartialName(name) 
    local name = name and string.lower(string.gsub(name, "#%x%x%x%x%x%x", "")) or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = string.lower(string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")) 
            if string.find(name_, name, 1, true) then 
                return player 
            end 
        end 
    end 
     
    return false 
end 
  
function privateMessage(thePlayer, _, sendToName,  ...) 
    local message = table.concat({...}, "") 
    if sendToName then 
       toPlayer = getPlayerFromPartialName(sendToName) 
       outputChatBox ( isElement ( toPlayer ) and tostring( getElementType ( player ) ) or "false" ); 
       if isElement ( toPlayer ) then 
           if toPlayer ~= thePlayer then 
              if not message == "" then 
                 outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) 
                 outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) 
                 setElementData(thePlayer, "pmPartner", toPlayer) 
                 setElementData(toPlayer, "pmPartner", thePlayer) 
              else 
                 outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) 
                 return false 
              end 
            else 
               outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) 
               return false 
            end 
        else 
           outputChatBox("Player not found.", thePlayer, 255, 0, 0) 
           return false 
        end 
    else 
        outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

Tell me if it outputs "player" or "false" in chatbox.

Link to comment
function getPlayerFromPartialName(name) 
    local name = name and string.lower(string.gsub(name, "#%x%x%x%x%x%x", "")) or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = string.lower(string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")) 
            if string.find(name_, name, 1, true) then 
                return player 
            end 
        end 
    end 
    
    return false 
end 
  
function privateMessage(thePlayer, _, sendToName,  ...) 
    local message = table.concat({...}, "") 
    if sendToName then 
       toPlayer = getPlayerFromPartialName(sendToName) 
       outputChatBox ( isElement ( toPlayer ) and tostring( getElementType ( toPlayer ) ) or "false" ); 
       if isElement ( toPlayer ) then 
           if toPlayer ~= thePlayer then 
              if not message == "" then 
                 outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) 
                 outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) 
                 setElementData(thePlayer, "pmPartner", toPlayer) 
                 setElementData(toPlayer, "pmPartner", thePlayer) 
              else 
                 outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) 
                 return false 
              end 
            else 
               outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) 
               return false 
            end 
        else 
           outputChatBox("Player not found.", thePlayer, 255, 0, 0) 
           return false 
        end 
    else 
        outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

What it outputs now?

Link to comment
function getPlayerFromPartialName(name) 
    local name = name and string.lower(string.gsub(name, "#%x%x%x%x%x%x", "")) or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = string.lower(string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")) 
            if string.find(name_, name, 1, true) then 
                return player 
            end 
        end 
    end 
    
    return false 
end 
  
function privateMessage(thePlayer, _, sendToName,  ...) 
    local message = table.concat({...}, " ") 
    if sendToName then 
       toPlayer = getPlayerFromPartialName(sendToName) 
       if isElement ( toPlayer ) then 
           if toPlayer ~= thePlayer then 
              if message ~= "" and #message > 0 then 
                 outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) 
                 outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) 
                 setElementData(thePlayer, "pmPartner", toPlayer) 
                 setElementData(toPlayer, "pmPartner", thePlayer) 
              else 
                 outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) 
                 return false 
              end 
            else 
               outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) 
               return false 
            end 
        else 
           outputChatBox("Player not found.", thePlayer, 255, 0, 0) 
           return false 
        end 
    else 
        outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

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