Jump to content

I have got some problems in my Code


Recommended Posts

kufurtablo = {} 
function kufur:ekle( kufur ) 
    table.insert( kufurtablo, kufur ) 
end 
  
function playerChat ( message, messageType ) 
if messageType == 0 then 
for k,v in ipairs(kufurtablo) do 
if string.find((string.gsub)message,v) then 
cancelEvent() 
banPlayer ( source, Serial = true, reason = "Bad word", seconds = 12000 ) 
outputChatBox ( getPlayerName(source).." has banned 2 minutes for saying bad word..", getRootElement(), 0, 255, 0, true ) 
end 
end 
end 
end 

This is my code and this is my another .lua file.

function onResourceStart(res) 
kufur:ekle ("fuck") 
end 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),onResourceStart) 

I havent got error when i debug it but it doesnt works.

Link to comment
function playerChat ( message, messageType ) 
if messageType == 0 then 
for k,v in ipairs(kufurtablo) do 
if string.find((string.gsub)message,v) then 
cancelEvent() 
banPlayer ( source, Serial = true, reason = "Bad word", seconds = 12000 ) 

o.O

here is what you want

addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
if string.find(msg:lower, '[bad word whatever]', 0) then 
--the code if a bad word was found 
end 
end 
end 
) 

here:

'[bad word whatever]'

enter the bad words separated by a space

and your banPlayer function is wrong

  
banPlayer ( player bannedPlayer, [ bool IP = true, bool Username = false, bool Serial = false,  
player responsiblePlayer = nil, string reason = nil, int seconds = 0 ]  

so:

banPlauer(source, false, false, true, nil, 'Bad Word', 12000) 

Link to comment
function playerChat ( message, messageType ) 
if messageType == 0 then 
for k,v in ipairs(kufurtablo) do 
if string.find((string.gsub)message,v) then 
cancelEvent() 
banPlayer ( source, Serial = true, reason = "Bad word", seconds = 12000 ) 

o.O

here is what you want

addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
if string.find(msg:lower, '[bad word whatever]', 0) then 
--the code if a bad word was found 
end 
end 
end 
) 

here:

'[bad word whatever]'

enter the bad words separated by a space

and your banPlayer function is wrong

  
banPlayer ( player bannedPlayer, [ bool IP = true, bool Username = false, bool Serial = false,  
player responsiblePlayer = nil, string reason = nil, int seconds = 0 ]  

so:

banPlauer(source, false, false, true, nil, 'Bad Word', 12000) 

But i want find the badword in table kufurtablo{ }

Link to comment
kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( v ) 
if ( string.find ( str, v ) ) then 
banPlayer(source, false, false, true, nil, 'Bad Word', 12000) 
break 
         end 
      end 
   end 
end 
) 

Link to comment
kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( v ) 
if ( string.find ( str, v ) ) then 
banPlayer(source, false, false, true, nil, 'Bad Word', 12000) 
break 
         end 
      end 
   end 
end 
) 

Its work if i say with caps lock

Link to comment
kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( v ) 
if ( string.find ( str, v ) ) then 
banPlayer(source, false, false, true, nil, 'Bad Word', 12000) 
break 
         end 
      end 
   end 
end 
) 

Its work if i say with caps lock

You are wrong, it works with caps and without caps, proof:

I said: son Of a BiTch and it worked.

Link to comment
kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( v ) 
if ( string.find ( str, v ) ) then 
addBan( nil, nil, getPlayerSerial(source), nil, 'Bad word', 12000 ) 
break 
         end 
      end 
   end 
end 
) 

Link to comment

Post errors warnings.

I didn't pay attention but how is this:

kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( v ) 
if ( string.find ( str, v ) ) then 
banPlayer(source, false, false, true, nil, 'Bad Word', 12000) 
break 
         end 
      end 
   end 
end 
) 

here

function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( v ) 
if ( string.find ( str, v ) ) then 
  

str is the lower of v then how you are checking if v is found in str i am not sure if iam right but shouldn't it be like this:

kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( msg ) 
if ( string.find ( str, v ) ) then 
banPlayer(source, false, false, true, nil, 'Bad Word', 12000) 
break 
         end 
      end 
   end 
end 
) 

Link to comment

Yeah..... my mistake :P, btw, use addBan, banPlayer won't work.

kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( msg ) 
if ( string.find ( str, v ) ) then 
addBan( nil, nil, getPlayerSerial(source), nil, 'Bad word', 12000 ) 
break 
         end 
      end 
   end 
end 
) 

Link to comment
Yeah..... my mistake :P, btw, use addBan, banPlayer won't work.
kufurtablo = { 
"son of a bitch", 
} 
  
addEventHandler('onPlayerChat', root, 
function(msg, msgType) 
if msgType == 0 then 
for i,v in pairs(kufurtablo) do 
local str = string.lower ( msg ) 
if ( string.find ( str, v ) ) then 
addBan( nil, nil, getPlayerSerial(source), nil, 'Bad word', 12000 ) 
break 
         end 
      end 
   end 
end 
) 

Hmm, why wont it work?

Sorry but i just want to understand why :)

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