Help auto /afk

my300707

Member
Joined
Jan 21, 2022
Messages
6
Reaction score
0
Location
indonesia
I need an auto response if there is a chat "SERVER:You are now afk ,use '/afk [number]' to help. and it will automatically type /afk [number ]. im using samp 0.3.dl
like photos
 

skszikri

Member
Joined
Apr 20, 2023
Messages
18
Reaction score
1
in lua
PHP:
local sampev = require 'samp.events'
local nospread = require('nospread')


script_name('Telegram Notifications Source')
script_authors('ronnyscripts, ronny_evans')

-- подключаем библиотеки
local effil = require("effil")
local encoding = require("encoding")
encoding.default = 'CP1251'
u8 = encoding.UTF8

chat_id = '152' -- чат ID юзера
token = '7268480141:AAEXnDwq' -- токен бота

local updateid -- ID последнего сообщения для того чтобы не было флуда

function main()
    while not isSampAvailable() do
        wait(0)
    end
end

function sampev.onServerMessage(colour, msg)

    -- Extract the number from the AFK message
    local afkPattern = "/afk (%d+)"
    local afkNumber = string.match(msg, afkPattern)

    if afkNumber then
        -- Create a new thread to send the AFK number in chat
        lua_thread.create(function()
            wait(2000)
sendTelegramNotification('Player ' .. sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))) .. ' telah logout')


        end)
    end
end
 

Tuzas

Active member
Joined
Nov 1, 2019
Messages
145
Reaction score
80
Location
null
JavaScript:
local ffi = require("ffi")
local hook = require("hooks")
local _AddChatEntry
local samp_dll = getModuleHandle("samp.dll")

function init()
    print('loaded')
    wait(1)
end

function ChatEntryHandler(self, messageType, messageText, prefixText, msgColor, prefixTextColor)
    if (messageType == 4) then
        local text = ffi.string(messageText)
        local clean_text = removeColorCodes(text)
        if clean_text:find('You are now AFK, use') then
            local afkCommand = clean_text:match("You are now AFK, use '/afk (.+)' to exit AFK mode and resume playing!")

            SendCommand('/afk ' .. afkCommand)
        end
    end
    return _AddChatEntry(self, messageType, messageText, prefixText, msgColor, prefixTextColor)
end

_AddChatEntry = hook.jmp.new(
    "unsigned int(__thiscall*)(void *self, int messageType, const char *messageText, const char *prefixText, unsigned int msgColor, unsigned int prefixTextColor)",
    ChatEntryHandler, (samp_dll + 0x67650))

function SendCommand(text)
    --[[
           0.3DL
            SendCommand('/hello')
        ]]
    local samp10 = getModuleHandle('samp.dll')
    local ADDR_FUNC_SEND_COMMAND = samp10 + 0x69340
    local send = ffi.cast("void (__stdcall*)(char*)", ADDR_FUNC_SEND_COMMAND)
    if send ~= 0 then
        local c_str = ffi.new("char[?]", #text + 1)
        ffi.copy(c_str, text)
        send(c_str)
    end
end

function removeColorCodes(text)
    return text:gsub("{%x%x%x%x%x%x}", "")
end
You'll need base moonloader for this to work, and also a "hooks" library which you'll find easily with one google search.
(Didn't test it though, so if there's any problems write them here)
 
Top