Jump to content

Help please


Resto

Recommended Posts

Helo all, can anyone tell me what functions i need for /blockpm <name> i used this PM system.

local mycrpmpartner = {}

function thePM(thePlayer,commandName,sendToName,...)
    local pmWords = { ... }
    local pmMessage = table.concat( pmWords, " " )
    if sendToName then
        if getPlayerFromNamePart2(sendToName) then
        local toPlayer = getPlayerFromNamePart2(sendToName)
            if not (toPlayer == thePlayer) then --that () needed
                if not (pmMessage == "") then
                    outputChatBox("#757575[PM] Message to #ff00ff" .. getPlayerName(toPlayer) .. ":#ffffff " .. pmMessage, thePlayer, 255, 255, 255, true)
                    outputChatBox("#FF0000[PM] Message from #ffFFff" .. getPlayerName(thePlayer) .. ":#ffff00 " .. pmMessage, toPlayer, 255, 255, 255, true)
                    mycrpmpartner[thePlayer]=toPlayer
                    mycrpmpartner[toPlayer]=thePlayer
                else
                    outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
                end
            else
                outputChatBox("#FF000[PM] You cannot PM yourself #ff9900!", thePlayer, 255, 255, 255, true)
            end
        else
            outputChatBox("#FF0000[PM] Player not found! #FFFF00[#ff9900"..sendToName.."#FFFF00]", thePlayer, 255, 255, 255, true)
        end
    else
        outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
    end
end
addCommandHandler("pm", thePM)

function getPlayerFromNamePart2 ( name )
    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 ( tostring ( name ):lower ( ), 1, true ) then
                    return player 
                end
        end
    end
end

 

Edited by Resto
Link to comment
local mycrpmpartner = {}

function thePM(thePlayer,commandName,sendToName,...)
    local pmWords = { ... }
    local pmMessage = table.concat( pmWords, " " )
    if sendToName then
        if getPlayerFromNamePart2(sendToName) then
        local toPlayer = getPlayerFromNamePart2(sendToName)
            if not (toPlayer == thePlayer) then --that () needed
                if getElementData(toPlayer, "Player:PMState") == true then outputChatBox("This player blocked the privat messages.", thePlayer) end
                if not (pmMessage == "") then
                    outputChatBox("#757575[PM] Message to #ff00ff" .. getPlayerName(toPlayer) .. ":#ffffff " .. pmMessage, thePlayer, 255, 255, 255, true)
                    outputChatBox("#FF0000[PM] Message from #ffFFff" .. getPlayerName(thePlayer) .. ":#ffff00 " .. pmMessage, toPlayer, 255, 255, 255, true)
                    mycrpmpartner[thePlayer]=toPlayer
                    mycrpmpartner[toPlayer]=thePlayer
                else
                    outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
                end
            else
                outputChatBox("#FF000[PM] You cannot PM yourself #ff9900!", thePlayer, 255, 255, 255, true)
            end
        else
            outputChatBox("#FF0000[PM] Player not found! #FFFF00[#ff9900"..sendToName.."#FFFF00]", thePlayer, 255, 255, 255, true)
        end
    else
        outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
    end
end
addCommandHandler("pm", thePM)

function getPlayerFromNamePart2 ( name )
    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 ( tostring ( name ):lower ( ), 1, true ) then
                    return player 
                end
        end
    end
end

addCommandHandler("blockpm", function(source)
    local PMState = getElementData(source, "Player:PMState")
    if (PMState == false) then
        setElementData(source, "Player:PMState", true)
    else    
        setElementData(source, "Player:PMState", false)    
    end
end
)

 

Link to comment
local mycrpmpartner = {}

function thePM(thePlayer,commandName,sendToName,...)
    local pmWords = { ... }
    local pmMessage = table.concat( pmWords, " " )
    if sendToName then
        if getPlayerFromNamePart2(sendToName) then
        local toPlayer = getPlayerFromNamePart2(sendToName)
            if not (toPlayer == thePlayer) then --that () needed
                if getElementData(toPlayer, "Player:PMState") == true then outputChatBox("This player has block his private messages", thePlayer, 255, 0, 0) end
                if not (pmMessage == "") then
                    outputChatBox("#757575[PM] Message to #ff00ff" .. getPlayerName(toPlayer) .. ":#ffffff " .. pmMessage, thePlayer, 255, 255, 255, true)
                    outputChatBox("#FF0000[PM] Message from #ffFFff" .. getPlayerName(thePlayer) .. ":#ffff00 " .. pmMessage, toPlayer, 255, 255, 255, true)
                    mycrpmpartner[thePlayer]=toPlayer
                    mycrpmpartner[toPlayer]=thePlayer
                else
                    outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
                end
            else
                outputChatBox("#FF000[PM] You cannot PM yourself #ff9900!", thePlayer, 255, 255, 255, true)
            end
        else
            outputChatBox("#FF0000[PM] Player not found! #FFFF00[#ff9900"..sendToName.."#FFFF00]", thePlayer, 255, 255, 255, true)
        end
    else
        outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
    end
end
addCommandHandler("pm", thePM)

function getPlayerFromNamePart2 ( name )
    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 ( tostring ( name ):lower ( ), 1, true ) then
                    return player 
                end
        end
    end
end

addCommandHandler("blockpm", function(thePlayer, command)
    local toPlayer = getPlayerFromNamePart2(thePlayer)
	local PMState = getElementData(toPlayer, "Player:PMState")
    if toPlayer ~= thePlayer then
	    if (PMState == false) then
	        setElementData(toPlayer, "Player:PMState", thePlayer, true)
	    else
	       setElementData(toPlayer, "Player:PMState", thePlayer, false)
	    end
    else
        outputChatBox("You can't block yourself!", thePlayer, 255, 0, 0)
    end
end)

try this

Edited by Dimos7
Link to comment

Really nice subject.. very informative of the content... o.O

Aaaaaaanyway, I'm not really sure what Dimos7 was trying to do but I'd do something similar to this:

local mycrpmpartner = {} --what's this for??
local blockList = {} --simple table for out block list

function thePM(thePlayer,commandName,sendToName,...)
    local pmWords = { ... }
    local pmMessage = table.concat( pmWords, " " )
    if sendToName then
        if getPlayerFromNamePart2(sendToName) then
        local toPlayer = getPlayerFromNamePart2(sendToName)
            if not (toPlayer == thePlayer) then --that () needed
                if not (pmMessage == "") then
                    if blockList[toPlayer] and blockList[toPlayer][thePlayer] then --the table is present for the recipient AND the recipient has us blocked.
            	        outputChatBox("Blocked", thePlayer)
            	        return false --bye bye
                    end
                    outputChatBox("#757575[PM] Message to #ff00ff" .. getPlayerName(toPlayer) .. ":#ffffff " .. pmMessage, thePlayer, 255, 255, 255, true)
                    outputChatBox("#FF0000[PM] Message from #ffFFff" .. getPlayerName(thePlayer) .. ":#ffff00 " .. pmMessage, toPlayer, 255, 255, 255, true) --These colour codes at the start are attritious btw.
                    mycrpmpartner[thePlayer]=toPlayer
                    mycrpmpartner[toPlayer]=thePlayer
                else
                    outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
                end
            else
                outputChatBox("#FF000[PM] You cannot PM yourself #ff9900!", thePlayer, 255, 255, 255, true)
            end
        else
            outputChatBox("#FF0000[PM] Player not found! #FFFF00[#ff9900"..sendToName.."#FFFF00]", thePlayer, 255, 255, 255, true)
        end
    else
        outputChatBox("#FF0000[PM]Use:#ff9900 /pm [part of name] [message]", thePlayer, 255, 255, 255, true)
    end
end
addCommandHandler("pm", thePM)

function getPlayerFromNamePart2 ( name )
    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 ( tostring ( name ):lower ( ), 1, true ) then
                    return player 
                end
        end
    end
end

addCommandHandler("blockpm", function (player, cmd, playerToBlock)
    if not blockList[player] then
    	blockList[player] = {} --create a table for our player if there isn't one yet
    end
    playerToBlock = getPlayerFromNamePart2(playerToBlock)
    if not playerToBlock then return end
    blockList[player][playerToBlock] = not blockList[player][playerToBlock] --shouldn't complain about it being nil
    outputChatBox(getPlayerName(playerToBlock) .. " " .. (blockList[player][playerToBlock] == true and "" or "un") .. "blocked", player)
end)

I'm not guaranteeing that it will work, it's only a quick write-up but you should get the idea.

Keep in mind that the blockList table isn't being cleared in any way, so it will keep growing unless you take care of that (eg. onPlayerQuit).

Edited by MIKI785
  • Thanks 1
Link to comment
4 hours ago, MIKI785 said:

You don't *have* to, but it will keep growing if you don't. But don't clear the whole blockList, only the player's table.

So,


addEventHandler("onPlayerQuit", function ()    blockList[source] = nil
end)

should do the job.

Thanks. Working.

Edited by Resto
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...