Jump to content

Script error need help


Recommended Posts

Posted

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

Posted (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 by Guest

If I helped you, please click the like button on the right ;) Thanks!

Posted

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.

If I helped you, please click the like button on the right ;) Thanks!

Posted

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) 
 
Posted
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 

If I helped you, please click the like button on the right ;) Thanks!

Posted

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 

CiTLh.png
Posted

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.

If I helped you, please click the like button on the right ;) Thanks!

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