isa_Khamdan Posted October 21, 2013 Share Posted October 21, 2013 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 "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
Dealman Posted October 21, 2013 Share Posted October 21, 2013 I believe it's because you're doing the for loop after you're trying to use the variable v. Therefore, when it runs the code at Line 23 - the variable v has not been set to anything. And therefore, it returns nil. Link to comment
Markeloff Posted October 21, 2013 Share Posted October 21, 2013 v is not defined, make sure what argument you want to use. Link to comment
isa_Khamdan Posted October 21, 2013 Author Share Posted October 21, 2013 (edited) Deleted Edited October 21, 2013 by Guest Link to comment
Dealman Posted October 21, 2013 Share Posted October 21, 2013 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
isa_Khamdan Posted October 21, 2013 Author Share Posted October 21, 2013 So I just need to move the first part down and the second part should be on the bottom? 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