Dimos7 Posted April 25, 2015 Share Posted April 25, 2015 (edited) function privateMessage(thePlayer, sendToName, id, ...) local message = table.concat({...}, "") if id then target = getPlayerFromID(id) if target == false or target == nil then outputChatBox("That id has not conencted", player, 255, 0, 0) return end end if sendToName then if (getPlayerFromPartialName(sendToName)) then toPlayer = (getPlayerFromPartialName(sendToName)) if not(toPlayer == thePlayer) then if not message == "" then outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name]/ [id] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] /[id] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) getPlayerFromPartialName take a nil value Edited April 25, 2015 by Guest Link to comment
WhoAmI Posted April 25, 2015 Share Posted April 25, 2015 function privateMessage(thePlayer, _, sendToName, ...) local message = table.concat({...}, "") if id then target = getPlayerFromID(id) if target == false or target == nil then outputChatBox("That id has not conencted", player, 255, 0, 0) return end end if sendToName then if (getPlayerFromPartialName(sendToName)) then toPlayer = (getPlayerFromPartialName(sendToName)) if not(toPlayer == thePlayer) then if not message == "" then outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name]/ [id] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] /[id] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) Link to comment
Dimos7 Posted April 25, 2015 Author Share Posted April 25, 2015 still the same function privateMessage(thePlayer, _, sendToName, ...) local message = table.concat({...}, "") if id then target = getPlayerFromID(id) if target == false or target == nil then outputChatBox("That id has not conencted", player, 255, 0, 0) return end end if sendToName then if (getPlayerFromPartialName(sendToName)) then toPlayer = (getPlayerFromPartialName(sendToName)) if not(toPlayer == thePlayer) then if not message == "" then outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name]/ [id] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] /[id] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) Link to comment
WhoAmI Posted April 25, 2015 Share Posted April 25, 2015 Did you add getPlayerFromPartialName function name before? function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end end end Link to comment
Dimos7 Posted April 25, 2015 Author Share Posted April 25, 2015 function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end end end function privateMessage(thePlayer, sendToName, ...) local message = table.concat({...}, "") if sendToName then if (getPlayerFromPartialName(sendToName)) then toPlayer = (getPlayerFromPartialName(sendToName)) if not(toPlayer == thePlayer) then if not message == "" then outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) Now every name i put no find the player wtf Link to comment
WhoAmI Posted April 25, 2015 Share Posted April 25, 2015 function getPlayerFromPartialName(name) local name = name and string.lower(string.gsub(name, "#%x%x%x%x%x%x", "")) or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = string.lower(string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")) if string.find(name_, name, 1, true) then return player end end end return false end function privateMessage(thePlayer, _, sendToName, ...) local message = table.concat({...}, "") if sendToName then toPlayer = getPlayerFromPartialName(sendToName) outputChatBox ( isElement ( toPlayer ) and tostring( getElementType ( player ) ) or "false" ); if isElement ( toPlayer ) then if toPlayer ~= thePlayer then if not message == "" then outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) Tell me if it outputs "player" or "false" in chatbox. Link to comment
WhoAmI Posted April 25, 2015 Share Posted April 25, 2015 Are you sure that you are typing correct part of name? Link to comment
WhoAmI Posted April 25, 2015 Share Posted April 25, 2015 function getPlayerFromPartialName(name) local name = name and string.lower(string.gsub(name, "#%x%x%x%x%x%x", "")) or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = string.lower(string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")) if string.find(name_, name, 1, true) then return player end end end return false end function privateMessage(thePlayer, _, sendToName, ...) local message = table.concat({...}, "") if sendToName then toPlayer = getPlayerFromPartialName(sendToName) outputChatBox ( isElement ( toPlayer ) and tostring( getElementType ( toPlayer ) ) or "false" ); if isElement ( toPlayer ) then if toPlayer ~= thePlayer then if not message == "" then outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) What it outputs now? Link to comment
Dimos7 Posted April 25, 2015 Author Share Posted April 25, 2015 Now say player put make ouput that syntax think Link to comment
WhoAmI Posted April 25, 2015 Share Posted April 25, 2015 function getPlayerFromPartialName(name) local name = name and string.lower(string.gsub(name, "#%x%x%x%x%x%x", "")) or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = string.lower(string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")) if string.find(name_, name, 1, true) then return player end end end return false end function privateMessage(thePlayer, _, sendToName, ...) local message = table.concat({...}, " ") if sendToName then toPlayer = getPlayerFromPartialName(sendToName) if isElement ( toPlayer ) then if toPlayer ~= thePlayer then if message ~= "" and #message > 0 then outputChatBox("PM to"..getPlayerName(toPlayer)..":"..message, thePlayer, 255, 255, 0) outputChatBox("PM from"..getPlayerName(thePlayer)..":"..message, toPlayer, 255, 255, 0) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) Link to comment
Dimos7 Posted April 25, 2015 Author Share Posted April 25, 2015 Now ouput false and player not found Link to comment
WhoAmI Posted April 25, 2015 Share Posted April 25, 2015 That's not possible. Probaby you are calling command in bad way. Link to comment
Dimos7 Posted April 25, 2015 Author Share Posted April 25, 2015 who can be wrongly use it on your slef /pm name Test? 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