Send command if chat message appear.

Joined
Apr 30, 2019
Messages
10
Likes
0
Points
1
1
#1
What I do wrong? I want command to trigger if chat message appear. On lua.

Code:
function onAddChatMessage(text)
    if (text == '*Bodyguard Name Surname wants to protect you for $200, type /accept bodyguard to accept.') then
        sendCommand('/accept bodyguard')
    end
    return false
end
 
OP
OP
M
Joined
Apr 30, 2019
Messages
10
Likes
0
Points
1
1
#4
So I made like this and it still doesn't send message on "key words" in samp chat.
Code:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(100)
        if string.find(text, "test this") ~= 0 then
            sendCommand('/saythis')
        end
        return false
    end
end
 
Last edited:
OP
OP
M
Joined
Apr 30, 2019
Messages
10
Likes
0
Points
1
1
#5
this way still doesn't work, no clue.
Code:
function onAddChatMessage(text)
    if string.find(text, "test this") ~= 0 then
        sampSendChat(string.format("/thiscommand"))
    end
    return false
end
 
OP
OP
M
Joined
Apr 30, 2019
Messages
10
Likes
0
Points
1
1
#6
ah right, I should make in two functions? This way in log file it says -Loaded successfully.
if I use string.find then it shows error.
Code:
require"lib.moonloader"
require"lib.sampfuncs"

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
end

function onAddChatMessage(text)
    if (text == 'when I say this') then
        sendCommand('/sendthis')
    end
    return false
end
 
OP
OP
M
Joined
Apr 30, 2019
Messages
10
Likes
0
Points
1
1
#7
This is how it looks in cleo, but need on .lua
Code:
{$CLEO .cs}
0000: NOP

:Init
wait 100
if
    SAMP.Available
jf @Init
0AC8: [email protected] = allocate_memory_size 250
0AC8: [email protected] = allocate_memory_size 250
jump @WaitForCap

:WaitForCap
wait 0
for [email protected] = 98 to 99
    0B75: samp get_chat_string [email protected] text_to [email protected] prefix_to [email protected] color_to [email protected] prefix_color_to [email protected]
    0C26: strupr in [email protected] out [email protected]
    if
        0C18: [email protected] = strstr string1 [email protected] string2 "when I say this"
    then
        0AF9: samp say_msg "/sendthis"
        wait 60000
        Break
    end
end
jump @WaitForCap
 
Top