Jump to content

Blocking


Drakath

Recommended Posts

Can anyone give me an advice of how to make an ability to block a player, so he won't be able to send you a private message?

function privateMessage(thePlayer,commandName,sendToName,...) 
    local pmWords = { ... } 
    local pmMessage = table.concat( pmWords, " " ) 
    if sendToName then 
        if (getPlayerFromParticalName (sendToName)) then 
        toPlayer = (getPlayerFromParticalName (sendToName)) 
            if not (toPlayer == thePlayer) then 
                if not (pmMessage == "") then 
                    outputChatBox("#FFFFFF[PM] Message to #ff9900" .. getPlayerName(toPlayer) .. "#FFFFFF: " .. pmMessage, thePlayer, 255, 255, 255, true) 
                    outputChatBox("#FFFFFF[PM] Message from #ff9900" .. getPlayerName(thePlayer) .. "#FFFFFF: " .. pmMessage, toPlayer, 255, 255, 255, true) 
                else 
                    return false 
                end 
            else 
                return false 
            end 
        else 
            return false 
        end 
    else 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 
  

Link to comment
I am trying to say that if he typed /ignore playerName then it will ignore him. If he sended him you can canel the event or return and output to who send to him.
It's not what I'm asking. I want to know how do I store the blocked players. I do not want to use account data.

Anubhav, please read what he's saying.

@Drakath: How bout tables ?

Link to comment

Are you using MySQL or account data to store the datas? You can store the blocked people using their db id ( SQL ) or their serial, then all you need to is to check the serial / db id and let them send the PM if they are not blocked.

Link to comment

Could store the blocked players in an XML file, which is stored within the resource folder client-side. Load it and store the names in a table client-side.

For efficiency you could have it only update when the player;

A) Blocks a new player.

B) Unblocks a player.

C) Resource is started.

Link to comment

I had this idea in mind but I'm not sure how will I make the unblock function. And about the tables, I have the blocked players names stored in a table by using table.insert but how do I check if player who sent the pm is in the table?

Link to comment

You need to loop through the table.

  
for _,v in ipairs(myTable) do  
if v == getPlayerName (toPlayer) then -- use getPlayerName (v) if you're storing him as a player 
break -- don't send him pm 
else 
-- send the pm  
end 
end 
end  

To unblock him

  
addCommandHandler ("unblock", 
function ( commandName,  sendToName) 
if sendToName then 
local toPlayer = (getPlayerFromParticalName (sendToName)) 
for _,v in ipairs(myTable) do  
if v == getPlayerName (toPlayer) then -- use getPlayerName (v) if you're storing him as a player 
 table.remove (myTable, v ) -- use getPlayerName (v) if you're storing him as a player 
break 
end 
end 
end 
end  
end )  

Edited by Guest
Link to comment
  • Moderators
I had this idea in mind but I'm not sure how will I make the unblock function. And about the tables, I have the blocked players names stored in a table by using table.insert but how do I check if player who sent the pm is in the table?

Here is a generic function I just made. just give the table and the element you want to check if it's in that table:

-- /!\ doesn't work with nested tables /!\ -- 
function isElementInTable( table, elementToFind ) 
    for k, element in ipairs( table ) do 
        if element == elementToFind then 
            return true 
        end 
    end 
    return false 
end 

Link to comment
Saml1er, what if I block multiple players? I think your function will remove every blocked player and I want to remove only the player who is defined.

There's a check.

  
if v == getPlayerName (toPlayer) then 

This will remove the player specified in the command only.

Link to comment

You need to specify the position in the table you want to remove for table.remove . Just do

myTable [ toPlayer ] = nil  

or you can remove it with a for loop:

for k, players in ipairs(myTable) do 
    if players == toPlayer then -- I don't know how are you saving it in the table, name or the element 
        table.remove(myTable, k) 
        break 
    end 
end 

Edited by Guest
Link to comment
function lolok(ply) 
    local playername = getPlayerName(ply) 
    for _,v in ipairs(blocked) do 
        if v == playername then  
        outputChatBox("block") 
            break 
            else 
    outputChatBox("Message sent",255,255,255,true) 
         end 
     end 
end 
addEvent("xD", true) 
addEventHandler("xD", root, lolok) 

When player is blocked it outputs block as it should but if player is not blocked then nothing happens. Why?

Link to comment
function lolok(ply) 
    local playername = getPlayerName(ply) 
    for _,v in ipairs(blocked) do 
        if v == playername then  
        outputChatBox("block") 
            break 
            else 
    outputChatBox("Message sent",255,255,255,true) 
         end 
     end 
end 
addEvent("xD", true) 
addEventHandler("xD", root, lolok) 

When player is blocked it outputs block as it should but if player is not blocked then nothing happens. Why?

You're missing an "end". If you're saving the player's name in the table then it should definitely work.

function lolok(ply) 
    local playername = getPlayerName(ply) 
    for _,v in ipairs(blocked) do 
        if v == playername then  
        outputChatBox("block") 
            break 
            else 
    outputChatBox("Message sent",255,255,255,true) 
         end 
     end 
end 
end 
addEvent("xD", true) 
addEventHandler("xD", root, lolok) 

Link to comment
I'm not missing any ends...

That's impossible. You must use an end when you use break anways you can do it without break ( just remove break from the code you posted just now ) well but I wanted to break the loop when we get the blocked player or send the pm btw did you test the code ? :wink:

Link to comment
function lolok ( ply ) 
    local blocked = false 
    local playername = getPlayerName ( ply ) 
    for _, v in ipairs ( blocked ) do 
        if ( v == playername ) then 
            blocked = true 
            break 
        end 
    end 
  
    if ( not blocked ) then 
        outputChatBox ( "Message sent", 255, 255, 255, true ) 
    end 
end 
addEvent ( "xD", true ) 
addEventHandler ( "xD", root, lolok ) 

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