LiOneLMeSsIShoT Posted November 30, 2013 Share Posted November 30, 2013 in this script when i do /pm nothing happen function privateMessage(thePlayer,commandName,arg,sendToName,...) local pmWords = { ... } local pmMessage = table.concat( pmWords, " " ) local ID = tonumber(arg) if ID then target = exports.ID_System:getPlayerFromID(ID) else target = getPlayerFromName(arg) end if target then if target ~= player then if sendToName then if (getPlayerFromParticalName (sendToName)) then toPlayer = (getPlayerFromParticalName (sendToName)) if not (toPlayer == thePlayer) then if not (pmMessage == "") then outputChatBox("#0044FF[PM]#FFFFFF Message to #FFFFFF" .. getPlayerName(toPlayer) .. "#FFFFFF: " .. pmMessage, thePlayer, 255, 255, 255, true) outputChatBox("#0044FF[PM]#FFFFFF Message from #FFFFFF" .. getPlayerName(thePlayer) .. "#FFFFFF: " .. pmMessage, toPlayer, 255, 255, 255, true) else outputChatBox("#0044FF[PM]#FFFFFF Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", thePlayer, 255, 255, 255, true) return false end else outputChatBox("#0044FF[PM]#FFFFFF You cannot PM yourself#FFFFFF!", thePlayer, 255, 255, 255, true) return false end else outputChatBox("#0044FF[PM]#FFFFFF Player not found! #FFFF00(#FFFFFF"..sendToName.."#FFFF00)", thePlayer, 255, 255, 255, true) return false end else outputChatBox("#0044FF[PM]#FFFFFF Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", thePlayer, 255, 255, 255, true) return false end end 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 no error Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 (edited) Try the following. Server-side addCommandHandler("pm", function(thePlayer, commandName, sendTo, ...) local pmMessage = table.concat({...}, " ") if (not sendTo) or (not ...) or (not pmMessage) or (#pmMessage == 0) then outputChatBox("#0044FF[PM]#FFFFFF Invalid syntax! Usage:#FFFFFF /" .. commandName .. " [partial player name] [message]", thePlayer, 255, 255, 255, true) return end local target if (tonumber(sendTo)) then target = exports.ID_System:getPlayerFromID(tonumber(sendTo)) else target = getPlayerFromPartialName(sendTo, thePlayer) end if (target) then if (target == thePlayer) then outputChatBox("#0044FF[PM]#FFFFFF Message to #FFFFFF" .. getPlayerName(target) .. "#FFFFFF: " .. pmMessage, thePlayer, 255, 255, 255, true) outputChatBox("#0044FF[PM]#FFFFFF Message from #FFFFFF" .. getPlayerName(thePlayer) .. "#FFFFFF: " .. pmMessage, target, 255, 255, 255, true) else outputChatBox("#0044FF[PM]#FFFFFF You cannot PM yourself#FFFFFF!", thePlayer, 255, 255, 255, true) end else outputChatBox("#0044FF[PM]#FFFFFF Player not found! #FFFF00(#FFFFFF" .. sendTo .. "#FFFF00)", thePlayer, 255, 255, 255, true) end end, false, false ) function getPlayerFromPartialName(name, sourcePlayer) if (not name or type(name) ~= "string") then return end if (sourcePlayer) then if (name == "*") or (string.gsub(getPlayerName(sourcePlayer), "#%x%x%x%x%x%x", ""):lower() == name:lower()) then return sourcePlayer end end local match = {} for _,player in ipairs(getElementsByType("player")) do local matchName = string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "") if (string.find(matchName:lower(), name:lower(), 0)) then table.insert(match, player) end return (#match > 1 and false or match[1]) end end Edited November 30, 2013 by Guest Link to comment
LiOneLMeSsIShoT Posted November 30, 2013 Author Share Posted November 30, 2013 Alright i have no one in my server now because local...and i can't pm myself so can you make me able to pm myself to test? Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 It's not hard to switch a non-equal operator to equal... I am certainly not going to do that for you since you can just do it yourself. Copy the code again, by the way. Link to comment
LiOneLMeSsIShoT Posted November 30, 2013 Author Share Posted November 30, 2013 I have edited it : addCommandHandler("pm", function(thePlayer, commandName, sendTo, ...) local sendTo = tonumber(sendTo) local pmMessage = table.concat({...}, " ") local target if (sendTo) then target = exports.ID_System:getPlayerFromID(sendTo) else target = getPlayerFromPartialName(sendTo, thePlayer) end if (target) then if (target ~= thePlayer) then if (#pmMessage > 0) then outputChatBox("#0044FF[PM]#FFFFFF Message to #FFFFFF" .. getPlayerName(toPlayer) .. "#FFFFFF: " .. pmMessage, thePlayer, 255, 255, 255, true) outputChatBox("#0044FF[PM]#FFFFFF Message from #FFFFFF" .. getPlayerName(thePlayer) .. "#FFFFFF: " .. pmMessage, toPlayer, 255, 255, 255, true) else outputChatBox("#0044FF[PM]#FFFFFF Invalid syntax! Usage:#FFFFFF /" .. commandName .. " [partial player name] [message]", thePlayer, 255, 255, 255, true) end end else outputChatBox("#0044FF[PM]#FFFFFF Player not found! #FFFF00(#FFFFFF" .. sendTo .. "#FFFF00)", thePlayer, 255, 255, 255, true) end end, false, false ) function getPlayerFromPartialName(name, sourcePlayer) if (sourcePlayer) then if (name == "*") or (string.gsub(getPlayerName(sourcePlayer), "#%x%x%x%x%x%x", ""):lower() == name:lower()) then return sourcePlayer end end local match = {} for _,player in ipairs(getElementsByType("player")) do local matchName = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") if (matchName:find(name:lower(), 0)) then table.insert(match, player) end return (#match > 1 and false or match[1]) end end then got error in 31: :31: attempt to index local 'name' (a nil value) Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 Line no. 14, fix it. Undo line no. 31. Link to comment
qaisjp Posted November 30, 2013 Share Posted November 30, 2013 first: on line 8, change "sendTo" to: `tonumber(sendTo)` then remove line 3 Link to comment
LiOneLMeSsIShoT Posted November 30, 2013 Author Share Posted November 30, 2013 first:on line 8, change "sendTo" to: `tonumber(sendTo)` then remove line 3 The Same Error .. Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 addCommandHandler("pm", function(thePlayer, commandName, sendTo, ...) local pmMessage = table.concat({...}, " ") if (not sendTo) or (not ...) or (not pmMessage) or (#pmMessage == 0) then outputChatBox("#0044FF[PM]#FFFFFF Invalid syntax! Usage:#FFFFFF /" .. commandName .. " [partial player name] [message]", thePlayer, 255, 255, 255, true) return end local target if (tonumber(sendTo)) then target = exports.ID_System:getPlayerFromID(tonumber(sendTo)) else target = getPlayerFromPartialName(sendTo, thePlayer) end if (target) then if (target == thePlayer) then outputChatBox("#0044FF[PM]#FFFFFF Message to #FFFFFF" .. getPlayerName(target) .. "#FFFFFF: " .. pmMessage, thePlayer, 255, 255, 255, true) outputChatBox("#0044FF[PM]#FFFFFF Message from #FFFFFF" .. getPlayerName(thePlayer) .. "#FFFFFF: " .. pmMessage, target, 255, 255, 255, true) else outputChatBox("#0044FF[PM]#FFFFFF You cannot PM yourself#FFFFFF!", thePlayer, 255, 255, 255, true) end else outputChatBox("#0044FF[PM]#FFFFFF Player not found! #FFFF00(#FFFFFF" .. sendTo .. "#FFFF00)", thePlayer, 255, 255, 255, true) end end, false, false ) function getPlayerFromPartialName(name, sourcePlayer) if (not name or type(name) ~= "string") then return end if (sourcePlayer) then if (name == "*") or (string.gsub(getPlayerName(sourcePlayer), "#%x%x%x%x%x%x", ""):lower() == name:lower()) then return sourcePlayer end end local match = {} for _,player in ipairs(getElementsByType("player")) do local matchName = string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "") if (string.find(matchName:lower(), name:lower(), 0)) then table.insert(match, player) end return (#match > 1 and false or match[1]) end end Link to comment
LiOneLMeSsIShoT Posted November 30, 2013 Author Share Posted November 30, 2013 Works Fine ...Thank You myonlake you always fix the problems in my scripts and Tapl too ... Thanks guys! Link to comment
LiOneLMeSsIShoT Posted November 30, 2013 Author Share Posted November 30, 2013 but when i pm myself it says nothing ... whatever else outputchatbox ("you cannot pm yourself") added and no error Link to comment
TAPL Posted November 30, 2013 Share Posted November 30, 2013 Line 18 was edited to make you able to test it with yourself: if (target == thePlayer) then If you done the test or you want pm another player then just change it to: if (target ~= thePlayer) then Link to comment
myonlake Posted November 30, 2013 Share Posted November 30, 2013 In addition to that I've tested the script and it works just fine. If you have the right code then it should work for you as well. Link to comment
LiOneLMeSsIShoT Posted December 1, 2013 Author Share Posted December 1, 2013 Alright. Thanks 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