[LUA] Как отнять хп у персонажа?

абубачир

Известный
Автор темы
244
116
Нужно сделать так, чтобы каждые 100 мс при нажатии двух клавиш отнималось по 1 хп у персонажа.

Пробовал так, не работает.:
require 'lib.moonloader'
local inicfg = require 'inicfg'

hp = getCharHealth(PLAYER_PED)
keyFirst = VK_LMENU
keySecond = VK_1
useDelay = true
delay = 1000

function main()
    while true do
        wait(1)
        if isKeyControlAvailable() then
            if isKeyDown(keyFirst) and isKeyDown(keySecond) and not isCharDead(PLAYER_PED) then
                if timer == 0 then timer = os.clock() end
                if useDelay and ((os.clock() - timer) < (delay / 1000)) then
                    printString('wait\': ' .. math.floor((os.clock() - timer) / delay * 1e5) ..'%', 100)
                else
                    if not isCharInAnyCar(PLAYER_PED) then
                        lua_thread.create(function()
                            wait(100)
                            setCharHealth(PLAYER_PED, hp-1)
                        end)
                    else
                        setCharHealth(PLAYER_PED, hp-1)
                        --explodeCar(storeCarCharIsInNoSave(PLAYER_PED))
                    end
                    --printString('zemlya puhom!', 1500)
                end
            else
                timer = 0
            end
        end
    end
end

function isKeyControlAvailable()
    if not isSampLoaded() then return true end
    if not isSampfuncsLoaded() then return not sampIsChatInputActive() and not sampIsDialogActive() end
    return not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive()
end


Данный способ вычисления очков здоровья персонажа не работает по непонятной мне причине, списывает сразу 100 хп.
 
Последнее редактирование:

Dark.

Известный
1,745
772
Нужно сделать так, чтобы каждые 100 мс при нажатии двух клавиш отнималось по 1 хп у персонажа.

Пробовал так:
require 'lib.moonloader'
local inicfg = require 'inicfg'

hp = getCharHealth(PLAYER_PED)
keyFirst = VK_LMENU
keySecond = VK_1
useDelay = true
delay = 1000

function main()
    while true do
        wait(1)
        if isKeyControlAvailable() then
            if isKeyDown(keyFirst) and isKeyDown(keySecond) and not isCharDead(PLAYER_PED) then
                if timer == 0 then timer = os.clock() end
                if useDelay and ((os.clock() - timer) < (delay / 1000)) then
                    printString('wait\': ' .. math.floor((os.clock() - timer) / delay * 1e5) ..'%', 100)
                else
                    if not isCharInAnyCar(PLAYER_PED) then
                        lua_thread.create(function()
                            wait(100)
                            setCharHealth(PLAYER_PED, hp-1)
                        end)
                    else
                        setCharHealth(PLAYER_PED, hp-1)
                        --explodeCar(storeCarCharIsInNoSave(PLAYER_PED))
                    end
                    --printString('zemlya puhom!', 1500)
                end
            else
                timer = 0
            end
        end
    end
end

function isKeyControlAvailable()
    if not isSampLoaded() then return true end
    if not isSampfuncsLoaded() then return not sampIsChatInputActive() and not sampIsDialogActive() end
    return not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive()
end
попробуй вместо этого говнокода
Lua:
function isKeyControlAvailable()
    if not isSampLoaded() then return true end
    if not isSampfuncsLoaded() then return not sampIsChatInputActive() and not sampIsDialogActive() end
    return not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive()
isKeyControlAviable заменить на sampIsCoursorActive
 

абубачир

Известный
Автор темы
244
116
попробуй вместо этого говнокода
Lua:
function isKeyControlAvailable()
    if not isSampLoaded() then return true end
    if not isSampfuncsLoaded() then return not sampIsChatInputActive() and not sampIsDialogActive() end
    return not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive()
isKeyControlAviable заменить на sampIsCoursorActive
код не мой, брал с темы на бластхаке .lua suicide
 

damag

Женюсь на официантке в моем любимом баре
Проверенный
1,152
1,194
Lua:
require 'lib.moonloader'
local inicfg = require 'inicfg'

keyFirst = VK_LMENU
keySecond = VK_1
useDelay = true
delay = 1000

function main()
    while true do
       wait(1)
        if sampIsCursorActive() then
            if isKeyDown(keyFirst) and isKeyDown(keySecond) and not isCharDead(PLAYER_PED) then
                if timer == 0 then timer = os.clock() end
                if useDelay and ((os.clock() - timer) < (delay / 1000)) then
                    printString('wait\': ' .. math.floor((os.clock() - timer) / delay * 1e5) ..'%', 100)
                else
                    if not isCharInAnyCar(PLAYER_PED) then
                        lua_thread.create(function()
                            wait(100)
                           hp = getCharHealth(PLAYER_PED)
                            debil = tonumber(hp) - tonumber(1)
                            setCharHealth(PLAYER_PED, debil)
                        end)
                    else
                        print('вы в машине')
                    end
                end
            else
                timer = 0
            end
        end
    end
end
 
Последнее редактирование:

абубачир

Известный
Автор темы
244
116
Lua:
require 'lib.moonloader'
local inicfg = require 'inicfg'

keyFirst = VK_LMENU
keySecond = VK_1
useDelay = true
delay = 1000

function main()
    while true do
       wait(1)
        if sampIsCursorActive() then
            if isKeyDown(keyFirst) and isKeyDown(keySecond) and not isCharDead(PLAYER_PED) then
                if timer == 0 then timer = os.clock() end
                if useDelay and ((os.clock() - timer) < (delay / 1000)) then
                    printString('wait\': ' .. math.floor((os.clock() - timer) / delay * 1e5) ..'%', 100)
                else
                    if not isCharInAnyCar(PLAYER_PED) then
                        lua_thread.create(function()
                            wait(100)
                           hp = getCharHealth(PLAYER_PED)
                            debil = tonumber(hp) - tonumber(1)
                            setCharHealth(PLAYER_PED, debil)
                        end)
                    else
                        print('вы в машине')
                    end
                end
            else
                timer = 0
            end
        end
    end
end
Спасибо, но я воспринял переменную "debil" как прямое оскорбление, скинь мне на почту ксерокопию паспорта. Встретимся в суде.
 
  • Ха-ха
Реакции: damag

damag

Женюсь на официантке в моем любимом баре
Проверенный
1,152
1,194
Спасибо, но я воспринял переменную "debil" как прямое оскорбление, скинь мне на почту ксерокопию паспорта. Встретимся в суде.
у меня не только такие переменные есть)
и это не оскорбление, я люблю оскорблять код, меня это вдохновляет
 

абубачир

Известный
Автор темы
244
116
у меня не только такие переменные есть)
и это не оскорбление, я люблю оскорблять код, меня это вдохновляет
Да я же шучу. Мне тоже нравится задавать переменные с непонятными названиями
 

winten

Потрачен
409
182
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Lua:
require 'lib.moonloader'
local inicfg = require 'inicfg'

keyFirst = VK_LMENU
keySecond = VK_1
useDelay = true
delay = 1000

function main()
    while true do
       wait(1)
        if sampIsCursorActive() then
            if isKeyDown(keyFirst) and isKeyDown(keySecond) and not isCharDead(PLAYER_PED) then
                if timer == 0 then timer = os.clock() end
                if useDelay and ((os.clock() - timer) < (delay / 1000)) then
                    printString('wait\': ' .. math.floor((os.clock() - timer) / delay * 1e5) ..'%', 100)
                else
                    if not isCharInAnyCar(PLAYER_PED) then
                        lua_thread.create(function()
                            wait(100)
                           hp = getCharHealth(PLAYER_PED)
                            debil = tonumber(hp) - tonumber(1)
                            setCharHealth(PLAYER_PED, debil)
                        end)
                    else
                        print('вы в машине')
                    end
                end
            else
                timer = 0
            end
        end
    end
end
зачем флоат переводить в инт? зачем создавать переменные, которые используются 1 раз? типа можно вместо
Lua:
 hp = getCharHealth(PLAYER_PED)
debil = tonumber(hp) - tonumber(1)
setCharHealth(PLAYER_PED, debil)
вот так
Lua:
setCharHealth(PLAYER_PED, getCharHealth(PLAYER_PED) - 1)
 
  • Нравится
Реакции: абубачир

абубачир

Известный
Автор темы
244
116
зачем флоат переводить в инт? зачем создавать переменные, которые используются 1 раз? типа можно вместо
Lua:
hp = getCharHealth(PLAYER_PED)
debil = tonumber(hp) - tonumber(1)
setCharHealth(PLAYER_PED, debil)
вот так
Lua:
setCharHealth(PLAYER_PED, getCharHealth(PLAYER_PED) - 1)
Я же делал так
Lua:
hp = getCharHealth(PLAYER_PED)
setCharHealth(PLAYER_PED, hp-1)
Но почему не сработало?