Jump to content

Whisper problem


//_Dragon

Recommended Posts

Line 4-5 — You're just collecting the Hex of the sender, never the recipient's

Line 17 — May I know what that is for?

Line 28 — How do you even want to use hex on the name of a player who doesn't exist when a non-existent player doesn't have name colour.

Here's the corrected code:

function privateMessage(thePlayer,commandName,sendToName,...) 
    local pmWords = { ... } 
    local pmMessage = table.concat( pmWords, " " ) 
    local r, g, b = getPlayerNametagColor(thePlayer) 
    local fromHex = string.format("#%.2X%.2X%.2X", r, g, b) -- converts R, G, B to HEX value 
    if sendToName then 
        if (getPlayerFromParticalName (sendToName)) then 
            toPlayer = (getPlayerFromParticalName (sendToName)) 
            local tr, tg, tb = getPlayerNametagColor(thePlayer) 
            local toHex = string.format("#%.2X%.2X%.2X", tr, tg, tb) -- converts R, G, B to HEX value 
            if not (toPlayer == thePlayer) then 
                if not (pmMessage == "") then 
                    outputChatBox("(WHISPER) To " ..toHex.. getPlayerName(toPlayer) .. ":#FFFFFF " .. pmMessage, thePlayer, 255, 0, 90, true) 
                    outputChatBox("(WHISPER) From " ..fromHex.. getPlayerName(thePlayer) .. ":#FFFFFF " .. pmMessage, toPlayer, 255, 0, 90, true) 
                    setElementData(thePlayer,"pmPartner",toPlayer) 
                    triggerClientEvent(toPlayer,"onBeep",getRootElement ()) 
                    setElementData(toPlayer,"pmPartner",thePlayer) 
                    outputServerLog("(WHISPER) From " ..fromHex.. getPlayerName(thePlayer) .. ":#FFFFFF " .. pmMessage, toPlayer, 255, 0, 90, true) 
                    -- outputServerLog("(WHISPER) From " ..fromHex.. getPlayerName(thePlayer) .. " To " ..toHex.. getPlayerName(toPlayer) .. ":#FFFFFF " .. pmMessage, thePlayer, 255, 0, 90, true) -- what even is this? 
                else 
                    outputChatBox("#E8037E(WHISPER)#FFFFFF Invalid syntax! Usage:#FFFFFF /w [player name] [message]", thePlayer, 255, 255, 255, true) 
                    return false 
                end 
            else 
                outputChatBox("#E8037E(WHISPER)#FFFFFF You cannot whisper yourself", thePlayer, 255, 255, 255, true) 
                return false 
            end 
        else 
            outputChatBox("(WHISPER) Player not found "..sendToName, thePlayer, 255, 0, 90, true) 
            return false 
        end 
    else 
        outputChatBox("#E8037E(WHISPER)#FFFFFF Invalid syntax! Usage:#FFFFFF /w [player name] [message]", thePlayer, 255, 255, 255, true) 
        return false 
    end 
end 
addCommandHandler("w", privateMessage) 
  
function getPlayerFromParticalName(thePlayerName) 
    local thePlayer = getPlayerFromName(thePlayerName) 
    if thePlayer then 
        return thePlayer 
    end 
    for _,thePlayer in ipairs(getElementsByType("player")) do 
        if string.find(string.gsub(getPlayerName(thePlayer):lower(),"#%x%x%x%x%x%x", ""), thePlayerName:lower(), 1, true) then 
            return thePlayer 
        end 
    end 
    return false 
end 

Link to comment
function privateMessage(thePlayer,commandName,sendToName,...) 
    local pmWords = { ... } 
    local pmMessage = table.concat( pmWords, " " ) 
    local r, g, b = getPlayerNametagColor(thePlayer) 
    local fromHex = string.format("#%.2X%.2X%.2X", r, g, b) -- converts R, G, B to HEX value 
    if sendToName then 
        if (getPlayerFromParticalName (sendToName)) then 
            toPlayer = (getPlayerFromParticalName (sendToName)) 
            local tr, tg, tb = getPlayerNametagColor(toPlayer) 
            local toHex = string.format("#%.2X%.2X%.2X", tr, tg, tb) -- converts R, G, B to HEX value 
            if not (toPlayer == thePlayer) then 
                if not (pmMessage == "") then 
                    outputChatBox("(WHISPER) To " ..toHex.. getPlayerName(toPlayer) .. ":#FFFFFF " .. pmMessage, thePlayer, 255, 0, 90, true) 
                    outputChatBox("(WHISPER) From " ..fromHex.. getPlayerName(thePlayer) .. ":#FFFFFF " .. pmMessage, toPlayer, 255, 0, 90, true) 
                    setElementData(thePlayer,"pmPartner",toPlayer) 
                    triggerClientEvent(toPlayer,"onBeep",getRootElement ()) 
                    setElementData(toPlayer,"pmPartner",thePlayer) 
                    outputServerLog("(WHISPER) From " ..fromHex.. getPlayerName(thePlayer) .. ":#FFFFFF " .. pmMessage, toPlayer, 255, 0, 90, true) 
                    -- outputServerLog("(WHISPER) From " ..fromHex.. getPlayerName(thePlayer) .. " To " ..toHex.. getPlayerName(toPlayer) .. ":#FFFFFF " .. pmMessage, thePlayer, 255, 0, 90, true) -- what even is this? 
                else 
                    outputChatBox("#E8037E(WHISPER)#FFFFFF Invalid syntax! Usage:#FFFFFF /w [player name] [message]", thePlayer, 255, 255, 255, true) 
                    return false 
                end 
            else 
                outputChatBox("#E8037E(WHISPER)#FFFFFF You cannot whisper yourself", thePlayer, 255, 255, 255, true) 
                return false 
            end 
        else 
            outputChatBox("(WHISPER) Player not found "..sendToName, thePlayer, 255, 0, 90, true) 
            return false 
        end 
    else 
        outputChatBox("#E8037E(WHISPER)#FFFFFF Invalid syntax! Usage:#FFFFFF /w [player name] [message]", thePlayer, 255, 255, 255, true) 
        return false 
    end 
end 
addCommandHandler("w", privateMessage) 
  
function getPlayerFromParticalName(thePlayerName) 
    local thePlayer = getPlayerFromName(thePlayerName) 
    if thePlayer then 
        return thePlayer 
    end 
    for _,thePlayer in ipairs(getElementsByType("player")) do 
        if string.find(string.gsub(getPlayerName(thePlayer):lower(),"#%x%x%x%x%x%x", ""), thePlayerName:lower(), 1, true) then 
            return thePlayer 
        end 
    end 
    return false 
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...