Jump to content

{getPlayerFromParticalName}


Recommended Posts

السلام عليكم الكود دة لشات الخاص بس مش شغال ممكن حد يقولي فين الغلط

function privateMessage(thePlayer, commandName, sendToName, ...) 
    local message = table.concat({...}, " ")
local toPlayer = getPlayerFromParticalName(sendToName) 
if toPlayer  then
    local pmblocked = getElementData(toPlayer, "pmblocked") 
    if toPlayer ~= thePlayer  then
       if pmblocked ~= 1 then
           if message ~= "" then
           outputChatBox("PM to "..getPlayerName(toPlayer)..": "..message, thePlayer, 255, 255, 0)
        outputChatBox("PM from "..getPlayerName(thePlayer)..": "..message, toPlayer, 255, 255, 0)
        outputServerLog("PM to "..getPlayerName(toPlayer)..": "..message)
        outputServerLog("PM from "..getPlayerName(thePlayer)..": "..message)
        setElementData(thePlayer, "pmPartner", toPlayer)
        setElementData(toPlayer, "pmPartner", thePlayer)
       end
    else
      outputChatBox("This person has disabled his private messages, try again later.", thePlayer, 255, 0, 0)
    end
    else
      outputChatBox("You can not speak to yourself.", thePlayer, 255, 0, 0)
    end
 else
   outputChatBox("Player not found.", thePlayer, 255, 0, 0)
 end
end 
addCommandHandler("pm", 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



function mainChat(message, messageType)
     cancelEvent()
 if messageType == 0 then
    localIC(source, message)
 elseif messageType == 1 then
      meChat(source, "me", message)
    end
end
addEventHandler("onPlayerChat", root, mainChat)

function togglePM(thePlayer)
    local pmEnabled = getElementData(thePlayer, "pmblocked")
  if pmEnabled then
  if ( getElementData(thePlayer,"pmblocked") == 1  )
  then
     setElementData(thePlayer, "pmblocked", 0, false)
  outputChatBox("You enabled incoming private messages.", thePlayer, 0, 255, 0)
  else
  if ( getElementData(thePlayer,"pmblocked") == 0 )
  then
     setElementData(thePlayer, "pmblocked", 1, false)
  outputChatBox("You disabled incoming private messages.", thePlayer, 255, 0, 0)
 end
end
end
end
addCommandHandler("togglepm", togglePM)

 

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