PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: ??Empie?? on 05 November, 2003, 16:33:37

Title: Trickerbot priority trouble
Post by: ??Empie?? on 05 November, 2003, 16:33:37
I've implemented this (good old) trickerbot from ptazeck into my own script, but if there are 2 or more triggerwords in 1 sentence it always chooses a particulair one.

I want some words to have top priority, but I havent got a clue how the script chooses which of the triggers to respond to if there are more then one in a sentence.

Could anyone please help me :)

Here's a copy of the script:

-- TrickerBot2.lua, created by Ptaczek Dec-24, 2002
-- Just see how to implement the NMDC TriggerBot in LUA :)

-- changes
-- Feb-24, 2003, v2.0 Modification for DataArrival return value.

botname = "TrickerBot"
trigs = {
lol="Yeah, that was funny [USER]. Haha.",
bye="See ya [USER]",
vandel="Vandel!?!? WHERE??!",
ptokax="Oh Yeah, PtokaX ;)",
fuck="Watch IT [USER]! One more line of code and i could kick your ass!",
["shut up"]="Make me!",
["+ops"]="Open your eyes guys and look at the userlist!"
}


function Main()
frmHub:RegBot(botname)
end

function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
-- get the msg only using regular expression
s,e,msg = strfind(data, "%b<> ([ -z]*)")

-- look in the table
for key, value in trigs do
if( strfind( strlower(msg), key) ) then
answer, x = gsub(value, "%b[]", user.sName)
SendToAll( data ) -- send the original data
SendToAll( botname, answer ) -- send bot's answer
return 1 -- tell the hub we have processed the data
end
end
end
end
Title:
Post by: pHaTTy on 05 November, 2003, 16:39:59
it responds to the first in the line for example

Hi bollox

now Hi will reply Hello or so
and bollox will reply bollox what

so Hi was first so it will reply hello

if Bollox hi it will reply bollox what

phatty
Title:
Post by: OpiumVolage on 05 November, 2003, 17:00:16
he reply to the first he find in the trigs table:
for key, value in trigs do

Problem is that i don't know if we can sort this table as it's an associative table. Try to change the order when you define the triggers:

this:

trigs = {
lol="Yeah, that was funny [USER]. Haha.",
bye="See ya [USER]" }

could behave differently that:

trigs = {
bye="See ya [USER]",
lol="Yeah, that was funny [USER]. Haha." }

But not really confident :)
Title:
Post by: ??Empie?? on 05 November, 2003, 17:04:35
Actually, it doesnt.

I'll use your example:

if I say Hi Bollox

and the script replies hello

then I say Bollox Hi

then the script will reply hello to, as if Hi overrules the Bollox...

thats the weirdness. I dont know what overrules what... I've tested on te the following possibilities:

the trigger thats first in line is first: negative
the trigger thats first in script: negative
the trigger that is shortest: negative
the trigger that is first in alphabeth: negative

so Im clueless  ?(

@ OpiumVolage
Thats not it too.. it just seems to have its own will in finding what trigger has top priority  :(
Title:
Post by: pHaTTy on 05 November, 2003, 17:06:26
dumb question : but did you insert bollox as a trigger?
Title:
Post by: OpiumVolage on 05 November, 2003, 17:14:51
here is the problem, with the order defined before:
trigs = {
lol="Yeah, that was funny [USER]. Haha.",
bye="See ya [USER]",
vandel="Vandel!?!? WHERE??!",
ptokax="Oh Yeah, PtokaX ;)",
fuck="Watch IT [USER]! One more line of code and i could kick your ass!",
["shut up"]="Make me!",
["+ops"]="Open your eyes guys and look at the userlist!"
}

for key, value in trigs do print(key) end

Results:

lol
vandel
+ops
bye
ptokax
fuck
shut up
Title:
Post by: ??Empie?? on 07 November, 2003, 01:38:30
I now tried it with a new set of triggers... Long, short, in order, not in order, but I still cant find out how ptokax desides its priority...

It cant be this difficult you'd say. PtokaX somewhere must choose on which trigger to react first by a certain mechanism, but I cant find it... :(

If nobody can help, this will go in my book of unsolved riddles, but I still hope somebody can tell me how it works :)