Jump to content

Little help needed


isa_Khamdan

Recommended Posts

Hello ,

I am getting this error in line 23 so how can I fix it?

I want to cancle all outputchatmessage for people in this acl group or if they used bad words from table.

it's working but it show this error :S

"attempt to index global "v" (a nill value)"

chatTime = {} 
lastChatMessage = {} 
addEventHandler("onPlayerChat", getRootElement(), 
    function(text, msgtype) 
    local result = SQLS3D.qury("SELECT * FROM Tags_System") 
    if ( type ( result ) == "table" and #result == 0 or not result ) then return end 
    local account = getAccountName(getPlayerAccount(source)) 
    local name = getPlayerName(source) 
        local new = "" 
        local iter = 0 
        msg = string.gsub(text,"ـ","") 
        for word in msg:gmatch("%S+") do 
            iter = iter + 1 
            for i,swr in ipairs(words) do    
                local src = word:lower():gsub("%s","") 
                local src = src:gsub("#%x%x%x%x%x%x","") 
                local src = src:gsub("%c","") 
                local src = src:gsub("%p","") 
                local pat = swr:lower():gsub("%s","") 
  
                if src:find(pat) or isObjectInACLGroup ("user."..account, aclGetGroup ( "Nick" ) ) then 
                    cancelEvent() 
                    outputChatBox('#'..v["color1"]..' ' ..v["name"]..' '.. getPlayerName ( source ) .. ' : #'..v["color2"]..''..text..'', getRootElement(), r, g, b, true ) 
                break 
                end 
  
            end 
            if iter == 1 and word:len() > 2 then 
                word = word:gsub("%a",string.upper,1) 
            end 
            new = new..word.." " 
        end 
        if new ~= "" then msg = new end 
        text = msg 
        if chatTime[source] and chatTime[source] + tonumber(1000) > getTickCount() then 
            cancelEvent() 
            outputChatBox("Stop spamming main chat!", source, 255, 0, 0) 
            return 
        else 
                chatTime[source] = getTickCount() 
        end 
        if lastChatMessage[source] and lastChatMessage[source] == text then cancelEvent() return outputChatBox("Stop repeating yourself!", source, 255, 0, 0) end 
        lastChatMessage[source] = text 
        local r, g, b = getPlayerNametagColor(source) 
        cancelEvent() 
        for k, v in ipairs(Tag) do 
            if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), aclGetGroup(v["tag"])) then 
                    cancelEvent() 
                    outputChatBox('#'..v["color1"]..' ' ..v["name"]..' '.. getPlayerName ( source ) .. ' : #'..v["color2"]..''..text..'', getRootElement(), r, g, b, true ) 
        break 
         
  
    end 
        end 
    end 
) 

Link to comment

And we already told you what's wrong with it. So the need for full code should not be necessary. It's better if you fix it yourself instead of us doing it for you. :)

Part 1: The variable v has not been defined, hence why Line 23 is giving you a warning - saying that v returned nil.

for word in msg:gmatch("%S+") do 
            iter = iter + 1 
            for i,swr in ipairs(words) do    
                local src = word:lower():gsub("%s","") 
                local src = src:gsub("#%x%x%x%x%x%x","") 
                local src = src:gsub("%c","") 
                local src = src:gsub("%p","") 
                local pat = swr:lower():gsub("%s","") 
  
                if src:find(pat) or isObjectInACLGroup ("user."..account, aclGetGroup ( "Nick" ) ) then 
                    cancelEvent() 
                    outputChatBox('#'..v["color1"]..' ' ..v["name"]..' '.. getPlayerName ( source ) .. ' : #'..v["color2"]..''..text..'', getRootElement(), r, g, b, true ) -- This is where the error is caused. 
                break 
                end 
            end 
            if iter == 1 and word:len() > 2 then 
                word = word:gsub("%a",string.upper,1) 
            end 
            new = new..word.." " 
        end 

Part 2: The reason is because v is defined after that code. v is first defined at Line 45.

for k, v in ipairs(Tag) do 
            if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), aclGetGroup(v["tag"])) then 
                    cancelEvent() 
                    outputChatBox('#'..v["color1"]..' ' ..v["name"]..' '.. getPlayerName ( source ) .. ' : #'..v["color2"]..''..text..'', getRootElement(), r, g, b, true ) 
        break 

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