how to add trigs in a table
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

how to add trigs in a table

Started by DoJIN, 08 February, 2004, 23:56:49

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DoJIN

hub.onChatMessage = function( this, user, text )
      DC():PrintDebug( this:getHubName().."> Chat from "..user:getNick()..": "..text )
      
      local s = string.lower( text )
      if string.find( s, "dick" ) or string.find( s, "fuck" ) then
         this:sendChat( "Watch ur mouth" )
      end
   end

 how do i get this piece of coding go look for the triggers  in a table something like :

trigs = { "fuck", "dick","prick","asshole"}

kepp

#1
This is LUA 5.0,

for i,v in trigs do

if string.find(s,i) then
--// todo


but im not sure
Guarding    

DoJIN

#2
yeah  its lua 5 :-\

the script is for a bcdc++ based script  not for ptokax
thats why its v5.0

but can u give me some sorta example?

kepp

well, i just did,

to use a for loop to go through the table...

for i,v in trigs do

if string.find(s,i) then
--// do some things
end
end


or maybe another solution

trigs = { ["fuck"]=1, ["dick"]=2,["prick"]=3,["asshole"]=4}

local s = string.lower( text ) 
   if string.find( s, trigs[s]) then 
   this:sendChat( "Watch ur mouth" )
   end
end

but im not sure about it
Guarding    

DoJIN

#4
hnmm
 geuss not :-\

LUA Error: attempt to call a nil value

hmm  plop made a script for me that i could run on bcdc++ based clients

i found this in the code   maye this helps

-- the array of forbidden things
trigs = { "fuck", "weingarten","ip.com","ass.org","dns2go","yhub","servemp3.net","mine,nu"}


         else
            for i=1,table.getn(trigs) do
               if string.find(s, trigs) then
                  local ownNick = this:getOwnNick()
                  DC():SendHubMessage( this:getId(), "<"..ownNick.."> !kickuser "..user:getNick().." You have been kicked because of Offensive Language / Advertising.|" )
                  break
               end
            end
         end

ive tried to make a bit of sence off this script but :-\   i think my best shot is here on the forum

and since plop is / was lanning i couldent gat ahold of him

but i hope u can use the code he wrote


kepp

did you try the for loop?
Guarding    

DoJIN

srry was editing my last post ;)

btw  the trigs u made r fr lua v4.0 if im not mistaking     look @ the trigs of the code thats lua v5.0

Sedulus

hrmz..

*not-sober and very sleepy*


you are modding this..?
       hub.onChatMessage = function( this, user, text )
                --DC():PrintDebug( this:getHubName().."> Chat from "..user:getNick()..": "..text )

                local s = string.lower( text )
                -- if string.find( s, "[^a-z]bier+[^a-z]" ) or string.find( s, "[^a-z]biertje[^a-z]" ) then
                --      this:sendChat( "bier? ja lekker! :)" )
                -- end
        end


try this:
       hub.onChatMessage = function( this, user, text )
                local trigs = { "fuck", "weingarten","ip.com","ass.org","dns2go","yhub","servemp3.net","mine.nu"}

                local s = string.lower( text )
                for k,v in trigs do
                    if string.find( s, v, 1, 1 ) then
                        this:sendChat( "Watch your mouth" )
                        break
                    end
                end
        end

DoJIN

#8
well tnx alot  i heard u would prolly know it  but i couldent get a hold of ya

 hmmm ive been trying to get the nick from some1 out of the chat into the response  but i keep getting this:

this:sendChat( "Watch your mouth " )   gives :  nothing    
this:sendChat( "Watch your mouth "..user:getNick()"" ) gives : \startup.lua:199: attempt to call a string value

DoJIN

#9
well ive worked some stuff out myself and some stuff with some help

but  now   im stuck

the is the code now:


   hub.onChatMessage = function( this, user, text )
                local trigs1 = { "fuck", "dick","fag","homo","whore","cunt"}

                local s = string.lower( text )
                for k,v in trigs1 do
                    if string.find( s, v, 1, 1 ) then
                        this:sendChat( "Watch your mouth" ..user:getNick().. "those words could get u banned" )
                        break

      local trigs2 = { "no-ip","dyndns","serverbeer.com"}                  
               
                for k,v in trigs2 do
                    if string.find( s, v, 1, 1 ) then
                        this:sendChat( "+pban" ..user:getNick().. "dont Advertise for other hubs" )
                        break
                    end
                end
        end


and it gives

`end' expected (to close `if' at line 3) near `local'

what am i missing here?

Sedulus

start using [ code ] blocks for your code, and indentation or no one will help you

it's horrible to read unindented code, and it's also the cause of your errors

 for k,v in bla do
    if blah then
      if blah2 then
        do_something
      end
    end
  end
^-- indentation, try it

DoJIN

#11
huh?     urm im just a simple dutchy workin on an idea i have :-\

plz explain in normal english what u meen  :)

SMF spam blocked by CleanTalk