lua samp question

halamBalam

Новичок
Автор темы
1
0
Скрипт запускается и нормально работает, но при условии, что я его через команду выключу и обратно включу. В чём может быть дело? И почему, если я удаляю строчки 12, 26-33, то метод sampAddChatMessage() перестаёт работать? (полагаю, что весь код перестаёт работать, а не только метод)

code:
sampev = require "lib.samp.events"
require "lib.moonloader"

local toggle = false
local messageStart = 'сообщение от Дзайбацу'
local messagStop = 'начал задание по доставке груза. Принял:'
local startFlood = false

function main( ... )
    if not isSampLoaded() or not isSampfuncsLoaded() then return end

    sampRegisterChatCommand("st", struck)
    sampAddChatMessage("Struck спамер включён!!", 0xA5FF00)

    while true do
        wait(0)
        while startFlood do
            wait(0)
            sampSendChat("/struck")
            wait(500)
        end
    end
end


function struck()
  if toggle == true then
      toggle = false
      sampAddChatMessage("Struck спамер выключен!", 0xFF2600)
  else
      toggle = true
      sampAddChatMessage("Struck спамер включён!", 0xA5FF00)
end


function sampev.onServerMessage(color, text)
    if toggle == true then
        if string.find (text, messageStart , 1, true) then
            startFlood = true
        end
        if string.find (text, messagStop , 1, true) then
            startFlood = false
        end
    end
end
end
 

Вложения

  • Struck.lua
    1,016 байт · Просмотры: 2
  • Bug
Реакции: Lance_Sterling

wojciech?

Известный
Проверенный
404
360
Lua:
sampev = require "lib.samp.events"
require "lib.moonloader"

local toggle = false
local messageStart = 'сообщение от Дзайбацу'
local messagStop = 'начал задание по доставке груза. Принял:'
local startFlood = false

function main( ... )
    if not isSampLoaded() or not isSampfuncsLoaded() then return end

    sampRegisterChatCommand("st", struck)
    sampAddChatMessage("Struck спамер включён!!", 0xA5FF00)

    while true do
        wait(0)

        if startFlood then
            sampSendChat("/struck")
            wait(500)
        end
    end
end


function struck()
  if toggle == true then
      toggle = false
      sampAddChatMessage("Struck спамер выключен!", 0xFF2600)
  else
      toggle = true
      sampAddChatMessage("Struck спамер включён!", 0xA5FF00)
  end
end


function sampev.onServerMessage(color, text)
    if toggle == true then
        if string.find (text, messageStart , 1, true) then
            startFlood = true
        end
        if string.find (text, messagStop , 1, true) then
            startFlood = false
        end
    end
end
 
  • Bug
Реакции: qdIbp и Lance_Sterling

Lance_Sterling

Известный
995
355
Lua:
sampev = require "lib.samp.events"
require "lib.moonloader"

local toggle = false
local messageStart = 'сообщение от Дзайбацу'
local messagStop = 'начал задание по доставке груза. Принял:'
local startFlood = false

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end

    sampRegisterChatCommand("st", struck)
    sampAddChatMessage("Struck спамер включён!!", 0xA5FF00)

    while true do
        wait(0)
        if startFlood then
            sampSendChat("/struck")
            wait(500)
        end
    end
end


function struck()
  toggle = not toggle
  sampAddChatMessage("Struck спамер "..(toggle and 'включен' or 'выключен').."!", 0xFF2600)
end


function sampev.onServerMessage(color, text)
    if toggle then
        if string.find (text, messageStart , 1, true) then
            startFlood = true
        end
        if string.find (text, messagStop , 1, true) then
            startFlood = false
        end
    end
end
 
  • Bug
Реакции: chapo
D

deleted-user-139653

Гость
я не понял в чем собственно проблема, но вот.
С активацией на команду:

Lua:
local sampev = require("samp.events")

local toggle = false
local startFlood = false
local messageStart = 'сообщение от Дзайбацу'
local messagStop = 'начал задание по доставке груза. Принял:'

function main()
repeat wait(0) until isSampAvailable()

    sampRegisterChatCommand("st", function()
        toggle = not toggle
        sampAddChatMessage("Struck спамер: "..(toggle and '{00FF00}включен' or '{FF0000}выключен').."!", 0xFFFFFF)
    end)

    while true do wait(0)
        if startFlood then
            sampSendChat("/struck")
            wait(500)
        end
    end
end

function sampev.onServerMessage(color, text)
    if toggle then
        if text:find(messageStart) then
            startFlood = true
        end
        if text:find(messagStop) then
            startFlood = false
        end
    end
end

Без активации на команду:

Lua:
local sampev = require("samp.events")

local startFlood = false
local messageStart = 'сообщение от Дзайбацу'
local messagStop = 'начал задание по доставке груза. Принял:'

function main()
repeat wait(0) until isSampAvailable()

    while true do wait(0)
        if startFlood then
            sampSendChat("/struck")
            wait(500)
        end
    end
end

function sampev.onServerMessage(color, text)
    if text:find(messageStart) then
        startFlood = true
    end
    
    if text:find(messagStop) then
        startFlood = false
    end
end
 
  • Bug
Реакции: Lance_Sterling