Проблема с кодом скрипта

izicapt

Известный
Автор темы
330
102
Версия MoonLoader
.027.0-preview
И снова здрасте.
Пытался написать свой говно код,задумка была в том что когда игрок умерал (именно ваш персонаж) в чат выводилось сообщение *хорошая игра*.
Но в итоге все пошло не поплану

Lua:
function main()
    repeat wait(0) until isSampAvailable()
        sampRegisterChatCommand("Gudgame", function() state = not state)
              sampAddChatMessage((state and 'Включаюсь' or 'Оффаюсь'), -1)
            end)
        sampAddChatMessage('Братан тренируйся лучше'..getCharHealth(PLAYER_PED), -1)
        wait (100)
        sampSendChat ("Молодец!GG Бро!")
    end
end
 
Решение
Lua:
function main()
    local enabled = false
    while not isSampAvailable() do wait(50) end
    sampRegisterChatCommand("gg", function()
        enabled = not enabled
    end)
    while true do wait(50)
        if enabled and isCharDead(PLAYER_PED) then
            sampAddChatMessage("Блять ну ты попс конечно", -1)
            wait(222)
            sampSendChat("Молодец! GG Бро!")
            while isCharDead(PLAYER_PED) do wait(100) end
        end
    end
end

izicapt

Известный
Автор темы
330
102
Lua:
function main()
    while not isSampAvailable() do wait(50) end
    while true do wait(50)
        if isCharDead(PLAYER_PED) then
            sampAddChatMessage("Умер", -1)
            while isCharDead(PLAYER_PED) do wait(100) end
        end
    end
end
Lua:
function main()
    while not isSampAvailable() do wait(50) end
    while true do wait(50)
        if isCharDead(PLAYER_PED) then
            sampAddChatMessage("Умер", -1)
            sampSendChat ("GG")
            while isCharDead(PLAYER_PED) do wait(100) end
        end
    end
end
Так думаешь пойдет?
 

#Northn

Police Helper «Reborn» — уже ШЕСТЬ лет!
Всефорумный модератор
2,635
2,485
Lua:
function main()
    while not isSampAvailable() do wait(50) end
    while true do wait(50)
        if isCharDead(PLAYER_PED) then
            sampAddChatMessage("Умер", -1)
            sampSendChat ("GG")
            while isCharDead(PLAYER_PED) do wait(100) end
        end
    end
end
Так думаешь пойдет?
должно
 

Liquit

Активный
277
91
solution:
local e = require 'lib.samp.events'
local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
function e.onPlayerDeathNotification(killer, killed, reason) -- killer - кто убил, killed - кого убили, reason - плюёт в тебя идом оружия, с которого сделали смертный грех
    if killed == id and killer ~= 65535 then -- если труп ты и есть убивца
        if reason == 0 then -- если закочегарили с фиста
            sampSendChat("Мегахарош!")
        else -- с другой пукалки
            sampSendChat('Чел харош')
        end
    end
    if killer == id then -- если убивца ты
        if reason == 0 then -- если ты его аннигилировал с фиста
            sampSendChat("Прости если харош..")
        end
    end
end
 

izicapt

Известный
Автор темы
330
102
Короч попытался я добавить команду для активации по команде в итоге снова крашится,что делать?
Lua:
function main()
    while not isSampAvailable() do wait(50) end
        sampRegisterChatCommand("GG", func)
        end)
    while true do wait(50)
        if isCharDead(PLAYER_PED) then
            sampAddChatMessage("Блять ну ты попс конечно", -1)
                        wait(222)
                        sampSendChat("Молодец!GG Бро!")
            while isCharDead(PLAYER_PED) do wait(100) end
        end
    end
end

solution:
local e = require 'lib.samp.events'
local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
function e.onPlayerDeathNotification(killer, killed, reason) -- killer - кто убил, killed - кого убили, reason - плюёт в тебя идом оружия, с которого сделали смертный грех
    if killed == id and killer ~= 65535 then -- если труп ты и есть убивца
        if reason == 0 then -- если закочегарили с фиста
            sampSendChat("Мегахарош!")
        else -- с другой пукалки
            sampSendChat('Чел харош')
        end
    end
    if killer == id then -- если убивца ты
        if reason == 0 then -- если ты его аннигилировал с фиста
            sampSendChat("Прости если харош..")
        end
    end
end
Ты конечно молодец,может потом добавлю часть из этого
 

#Northn

Police Helper «Reborn» — уже ШЕСТЬ лет!
Всефорумный модератор
2,635
2,485
Lua:
function main()
    local enabled = false
    while not isSampAvailable() do wait(50) end
    sampRegisterChatCommand("gg", function()
        enabled = not enabled
    end)
    while true do wait(50)
        if enabled and isCharDead(PLAYER_PED) then
            sampAddChatMessage("Блять ну ты попс конечно", -1)
            wait(222)
            sampSendChat("Молодец! GG Бро!")
            while isCharDead(PLAYER_PED) do wait(100) end
        end
    end
end
 

Liquit

Активный
277
91
Lua:
function main()
    local enabled = false
    while not isSampAvailable() do wait(50) end
    sampRegisterChatCommand("gg", function()
        enabled = not enabled
    end)
    while true do wait(50)
        if enabled and isCharDead(PLAYER_PED) then
            sampAddChatMessage("Блять ну ты попс конечно", -1)
            wait(222)
            sampSendChat("Молодец! GG Бро!")
            while isCharDead(PLAYER_PED) do wait(100) end
        end
    end
end
Насколько я понимаю, isCharDead() срабатывает просто когда ты умер, а умереть можно и от падения, тогда ты будешь говорить асфальту какой он крутой, вот..
 
  • Ха-ха
Реакции: izicapt