выполнять команду при приближении к игроку

iAplle

Новичок
Автор темы
12
0
Версия MoonLoader
.026-beta
Как я могу выполнить команду, когда подхожу к игроку? Вы можете дать мне базу?
 

Scrix

Известный
232
293
test:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    act = 0
    sampRegisterChatCommand("test", funcact)
    while true do
    wait (0)
        if act == 1 then
            for k, v in pairs(getAllChars()) do
                _, id = sampGetPlayerIdByCharHandle(v)
                _, Pid = sampGetPlayerIdByCharHandle(PLAYER_PED)
                if Pid ~= id then
                    x, y, z = getCharCoordinates(v)
                    xp, yp, zp = getCharCoordinates(PLAYER_PED)
                    distant = getDistanceBetweenCoords3d(x,y,z,xp,yp,zp)
                    if distant <= 10.0 then
                        sampAddChatMessage("Рядом игрок "..id, -1)
                    end
                end
            end
        end
    end
end

function funcact()
    if act == 0 then
        act = 1
        sampAddChatMessage("Включено", -1)
    else
        act = 0
        sampAddChatMessage("Выключено", -1)
    end
end
 

7jizzle

Участник
238
14
test:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    act = 0
    sampRegisterChatCommand("test", funcact)
    while true do
    wait (0)
        if act == 1 then
            for k, v in pairs(getAllChars()) do
                _, id = sampGetPlayerIdByCharHandle(v)
                _, Pid = sampGetPlayerIdByCharHandle(PLAYER_PED)
                if Pid ~= id then
                    x, y, z = getCharCoordinates(v)
                    xp, yp, zp = getCharCoordinates(PLAYER_PED)
                    distant = getDistanceBetweenCoords3d(x,y,z,xp,yp,zp)
                    if distant <= 10.0 then
                        sampAddChatMessage("Рядом игрок "..id, -1)
                    end
                end
            end
        end
    end
end

function funcact()
    if act == 0 then
        act = 1
        sampAddChatMessage("Включено", -1)
    else
        act = 0
        sampAddChatMessage("Выключено", -1)
    end
end

Так лучше
Lua:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    act = 0
    sampRegisterChatCommand("test", funcact)
    while true do
    wait (0)
        if act then
            for k, v in pairs(getAllChars()) do
                _, id = sampGetPlayerIdByCharHandle(v)
                _, Pid = sampGetPlayerIdByCharHandle(PLAYER_PED)
                if Pid ~= id then
                    x, y, z = getCharCoordinates(v)
                    xp, yp, zp = getCharCoordinates(PLAYER_PED)
                    distant = getDistanceBetweenCoords3d(x,y,z,xp,yp,zp)
                    if distant <= 10.0 then
                        sampAddChatMessage("Рядом игрок "..id, -1)
                    end
                end
            end
        end
    end
end

function funcact()
    act = not act
    sampAddChatMessage(act and "Включено" or "Выключено", -1)
end