local lastNameIndex = 0 local conversationQueue = {} local charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' local function generateRandomString(length) local result = '' for i = 1, length do local rand = math.random(1, #charset) result = result .. charset:sub(rand, rand) end return result end local function getRandomIndex(list, lastIndex) if #list <= 1 then return 1 end local index = math.random(1, #list) while index == lastIndex do index = math.random(1, #list) end return index end local function getRandomName() local index = getRandomIndex(Config.FakeNames, lastNameIndex) lastNameIndex = index return Config.NamePrefix .. Config.FakeNames[index] end local function getSecondName(firstName) local name = getRandomName() local attempts = 0 while name == firstName and attempts < 20 do name = getRandomName() attempts = attempts + 1 end return name end --- Construieste messageData pentru chat ZSX_UIV2 local function buildMessageData(name, message) local currentTime = os.time() local hour12 = os.date("%I", currentTime) local minute = os.date("%M", currentTime) local ampm = os.date("%p", currentTime) return { -- Falsificam ID-ul sursei cu un numar aleator ca ZSX sa creada ca este un jucator real, nu Server-ul (0 = OOC fortat de obicei) source = math.random(100, 999), icon = Config.ChatIcon, message = message, time = string.format("%s:%s%s", hour12, minute, ampm), IsZSXMessage = true, color = Config.ChatColor, keyValue = generateRandomString(10), player = { name = name }, customHeader = nil } end --- Trimite mesaj catre toti clientii local function sendChatMessage(name, message) local messageData = buildMessageData(name, message) TriggerClientEvent('3210:pushMessage', -1, messageData) end --- Trimite conversatie sau mesaj solo local function sendConversation() if #GetPlayers() == 0 then return end local roll = math.random(1, 100) if roll <= Config.ConversationChance then local conv = Config.Conversations[math.random(1, #Config.Conversations)] local name1 = getRandomName() local name2 = getSecondName(name1) sendChatMessage(name1, conv[1]) for i = 2, #conv do local speaker = (i % 2 == 1) and name1 or name2 local totalDelay = 0 for j = 2, i do totalDelay = totalDelay + math.random(Config.ConversationReplyMin, Config.ConversationReplyMax) end table.insert(conversationQueue, { time = GetGameTimer() + totalDelay, name = speaker, message = conv[i] }) end else local name = getRandomName() local msg = Config.SoloMessages[math.random(1, #Config.SoloMessages)] sendChatMessage(name, msg) end end Citizen.CreateThread(function() while true do local now = GetGameTimer() local i = 1 while i <= #conversationQueue do if now >= conversationQueue[i].time then sendChatMessage(conversationQueue[i].name, conversationQueue[i].message) table.remove(conversationQueue, i) else i = i + 1 end end Citizen.Wait(500) end end) Citizen.CreateThread(function() math.randomseed(GetGameTimer()) while true do local interval = Config.Interval if Config.RandomInterval then interval = math.random(Config.MinInterval, Config.MaxInterval) end Citizen.Wait(interval) sendConversation() end end) -- ═══════════════════════════════════════════════════════════ -- ASCULTATOR DE MESAJE (CHAT GPT BOTI) -- ═══════════════════════════════════════════════════════════ local function checkPlayerMessageForBot(playerId, message) if not playerId or playerId == 0 then return end if type(message) ~= "string" or message == "" then return end local lowerMsg = string.lower(message) local foundReply = nil for _, data in ipairs(Config.AutoReplies) do for _, keyword in ipairs(data.keywords) do if string.find(lowerMsg, keyword) then foundReply = data.reply break end end if foundReply then break end end if foundReply then -- Punem un delay la raspuns SetTimeout(math.random(1500, 3500), function() local botName = getRandomName() sendChatMessage(botName, foundReply) end) end end -- Variantele folosite nativ si third-party de chat resources: AddEventHandler('chatMessage', function(source, name, message) checkPlayerMessageForBot(source, message) end) AddEventHandler('_chat:messageEntered', function(author, color, message) checkPlayerMessageForBot(source, message) end) RegisterNetEvent('chat:server:sendMessage') AddEventHandler('chat:server:sendMessage', function(txt) checkPlayerMessageForBot(source, txt) end) RegisterNetEvent('esx:chatMessage') AddEventHandler('esx:chatMessage', function(name, txt) checkPlayerMessageForBot(source, txt) end) -- Variantele specifice pentru ZSX_UIV2 (Chatul serverului) RegisterNetEvent('ZSX_UIV2:Chat:MessageCreated') AddEventHandler('ZSX_UIV2:Chat:MessageCreated', function(icon, message) checkPlayerMessageForBot(source, message) end) RegisterNetEvent('ZSX_UIV2:Chat:MessageCreatedSource') AddEventHandler('ZSX_UIV2:Chat:MessageCreatedSource', function(icon, message) checkPlayerMessageForBot(source, message) end) print('[3210] Resource started!')