Jump to content

[Resuelto] Chat Bot


Recommended Posts

Posted (edited)

Tengo un script que habla con los jugadores como si fuera el cleverbot

Pero al poner "que tal" o alguna frase que no este en el script, sigue soltando "Hola" por cada mensaje que pongo, a que se debe?

--[[ t = type 
0: normal message 
1: action message (/me) 
2: team message 
  
m = message 
]] 
tg = "#ffffffvD-#666666bot:#ffffff " 
function chatBot (m,t) 
    string.lower(m) 
    if m == "hola" or "ola" then 
        outputChatBox(tg.."Hola",source,255,255,255,true) 
    elseif m == "que tal" or "que tal?" then 
        outputChatBox(tg.."Yo estoy bien, y tu?",source,255,255,255,true) 
    else outputChatBox("No te entiendo",source,255,255,255,true) 
end end 
function chatAlert () 
    outputChatBox("[vD.bot] activo, puedes decirle 'Hola' para empezar",source,255,255,255,true) 
end 
addEventHandler("onPlayerChat",root,chatBot) 
addEventHandler("onPlayerJoin",root,chatAlert) 

Edited by Guest
Posted · Hidden
Hidden

Al poner or "ola" estás estableciendo que si "ola" existe como tal, que se ejecute.

Al "ola" existir ya de por sí como una cadena, siempre será verdadero.

Recambialo por or m == "ola".

Posted
Al poner or "ola" estás estableciendo que si "ola" existe como tal, que se ejecute.

Al "ola" existir ya de por sí como una cadena, siempre será verdadero.

Recambialo por or m == "ola".

Me queda otra cosa, como puedo hacer para que "detecte el mensaje" y "si hay en una parte del mensaje "hola" que responda con hola", por ejemplo tuve este problema:

[2014-06-18 19:50:16] [Output] : '~'VeNaD: Hola 
[2014-06-18 19:50:16] [Output] : No te entiendo 
[2014-06-18 19:50:17] [Output] : '~'VeNaD: Hola 
[2014-06-18 19:50:17] [Output] : vD-bot: Hola 
[2014-06-18 19:50:19] [Output] : '~'VeNaD: hola 
[2014-06-18 19:50:19] [Output] : vD-bot: Hola 
[2014-06-18 19:50:24] [Output] : '~'VeNaD: qUe TaL 
[2014-06-18 19:50:24] [Output] : vD-bot: Yo estoy bien, y tu? 
[2014-06-18 19:50:28] [Output] : '~'VeNaD: Que tal? 
[2014-06-18 19:50:28] [Output] : vD-bot: Yo estoy bien, y tu? 

Al decir "Hola xD" el bot tendria que haber respondido con "Hola", como debo hacerle?

tg = "#ffffffvD-#666666bot:#ffffff " 
function chatBot (m,t) 
    if string.lower(m) == "hola" or string.lower(m) == "ola" then 
        outputChatBox(tg.."Hola",source,255,255,255,true) 
    elseif string.lower(m) == "que tal" or string.lower(m) == "que tal?" then 
        outputChatBox(tg.."Yo estoy bien, y tu?",source,255,255,255,true) 
    else outputChatBox("No te entiendo",source,255,255,255,true) 
end end 
function chatAlert () 
    outputChatBox("[vD.bot] activo, puedes decirle 'Hola' para empezar",source,255,255,255,true) 
end 
addEventHandler("onPlayerChat",root,chatBot) 
addEventHandler("onPlayerJoin",root,chatAlert 

Posted
string.find(m,"hola") --asi, no? 
--string.find (s, pattern [, init [, plain]]) 

me da que nose usar esa linea;

tg = "#ffffffvD-#666666bot:#ffffff " 
function chatBot (m,t) 
    if string.lower(m) == string.find(m,"hola") or string.lower(m) == string.find(m,"ola") then 
        outputChatBox(tg.."Hola",source,255,255,255,true) 
    elseif string.lower(m) == "que tal" or string.lower(m) == "que tal?" then 
        outputChatBox(tg.."Yo estoy bien, y tu?",source,255,255,255,true) 
    else outputChatBox("No te entiendo",source,255,255,255,true) 
end end 
function chatAlert () 
    outputChatBox("[vD.bot] activo, puedes decirle 'Hola' para empezar",source,255,255,255,true) 
end 
addEventHandler("onPlayerChat",root,chatBot) 
addEventHandler("onPlayerJoin",root,chatAlert) 

me salta "else"

Posted
if (string.find(string.lower(m), "hola")) 

Tushé, no habia caido yo en eso, al ver que tenia un comparador, me cegué, Ahora si funciona.

Gracias! ;D

tg = "#ffffffvD-#666666bot:#ffffff " 
function chatBot (m,t) 
    if (string.find(string.lower(m), "hola")) or (string.find(string.lower(m), "ola")) then 
        outputChatBox(tg.."Hola",source,255,255,255,true) 
    elseif (string.find(string.lower(m), "que tal?")) or (string.find(string.lower(m), "que tal?"))then 
        outputChatBox(tg.."Yo estoy bien, y tu?",source,255,255,255,true) 
    elseif (string.find(string.lower(m), "adios")) or (string.find(string.lower(m),"chao")) then 
        outputChatBox(tg.."Adios ! \"{SMILIES_PATH}/icon_biggrin.gif\" alt=\"\" title=\"Very Happy\" />",source,255,255,255,true) 
    else outputChatBox(tg.."No te entiendo",source,255,255,255,true) 
end end 
function chatAlert () 
    outputChatBox("[vD.bot] activo, puedes decirle 'Hola' para empezar",source,255,255,255,true) 
end 
addEventHandler("onPlayerChat",root,chatBot) 
addEventHandler("onPlayerJoin",root,chatAlert) 
addEventHandler("onResourceStart",root,chatAlert) 
--[[ 
Help from: 
- venadHD 
- renkon 
]]  

HAHAHHAHAHHAA notificare este bug:

outputChatBox(tg.."Adios ! \"{SMILIES_PATH}/icon_biggrin.gif\" alt=\"\" title=\"Very Happy\" />",source,255,255,255,true) 

Posted
¿No sería mas eficiente hacerlo con tablas?

El problema es que las tablas no tienen la posibilidad de

or 

Ni se utilizar bien las tablas en lua (en este tipo de function)

mE = { 
"hola","hola" 
} 
for men,res in ipairs(mE) do 

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...