Drakath Posted March 8, 2014 Share Posted March 8, 2014 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
Anubhav Posted March 8, 2014 Share Posted March 8, 2014 Try using return or cancelEvent() Link to comment
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 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. Link to comment
Anubhav Posted March 8, 2014 Share Posted March 8, 2014 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. Link to comment
Karuzo Posted March 8, 2014 Share Posted March 8, 2014 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
pa3ck Posted March 8, 2014 Share Posted March 8, 2014 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
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 pa3ck I said I don't want to use account data. Also I want to prevent them from sending a pm to a particular player, not everyone. Though I will try to do something with tables. Link to comment
Dealman Posted March 8, 2014 Share Posted March 8, 2014 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
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 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
Saml1er Posted March 8, 2014 Share Posted March 8, 2014 (edited) 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 March 8, 2014 by Guest Link to comment
Moderators Citizen Posted March 8, 2014 Moderators Share Posted March 8, 2014 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
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 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. Link to comment
Saml1er Posted March 8, 2014 Share Posted March 8, 2014 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
pa3ck Posted March 8, 2014 Share Posted March 8, 2014 (edited) 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 March 8, 2014 by Guest Link to comment
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 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
pa3ck Posted March 8, 2014 Share Posted March 8, 2014 You don't need a for loop, try this: if not myTable [ toPlayer ] then --Send the PM else --Tell him he is blocked or something. end Link to comment
Saml1er Posted March 8, 2014 Share Posted March 8, 2014 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
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 I'm not missing any ends... Link to comment
Saml1er Posted March 8, 2014 Share Posted March 8, 2014 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 ? Link to comment
Castillo Posted March 8, 2014 Share Posted March 8, 2014 'break' is used for loops, so the 'end' is for the loop, not for the 'break'. Link to comment
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 Removing break didn't help. EDIT: Yeah, I tested the code, it only reacts when I'm blocked but when I'm not, it doesn't do anything. Link to comment
Saml1er Posted March 8, 2014 Share Posted March 8, 2014 Removing break didn't help. Thats weird. Try debugging it. Link to comment
Castillo Posted March 8, 2014 Share Posted March 8, 2014 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
Drakath Posted March 8, 2014 Author Share Posted March 8, 2014 Thank you all. It finally works! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now