Resto Posted May 11, 2018 Share Posted May 11, 2018 (edited) 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 May 11, 2018 by Resto Link to comment
itHyperoX Posted May 11, 2018 Share Posted May 11, 2018 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
Resto Posted May 11, 2018 Author Share Posted May 11, 2018 Really thanks for your help but i need functions or example /blockpm <player> not for all players Link to comment
Dimos7 Posted May 11, 2018 Share Posted May 11, 2018 (edited) 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 May 11, 2018 by Dimos7 Link to comment
Resto Posted May 12, 2018 Author Share Posted May 12, 2018 Doesnt work and your setElementData in blockpm ? wat Link to comment
Dimos7 Posted May 12, 2018 Share Posted May 12, 2018 (edited) yes try chage the roPlayer with thePlayer and thePlayer with toPlayer Edited May 12, 2018 by Dimos7 Link to comment
Storm-Hanma Posted May 12, 2018 Share Posted May 12, 2018 3 hours ago, Resto said: wat? Dimos mean replace the roplayer words with theplayer & theplayer with toplayer Hope you got it lolxd Link to comment
MIKI785 Posted May 14, 2018 Share Posted May 14, 2018 (edited) Really nice subject.. very informative of the content... 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 May 14, 2018 by MIKI785 1 Link to comment
Resto Posted May 14, 2018 Author Share Posted May 14, 2018 (edited) Sorry. So i need clear table when player quit? Edited May 14, 2018 by Resto Link to comment
MIKI785 Posted May 15, 2018 Share Posted May 15, 2018 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. 1 Link to comment
Resto Posted May 15, 2018 Author Share Posted May 15, 2018 (edited) 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 May 15, 2018 by Resto 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