Всем привет! Как сделать случайное число? В триггерах есть функция случайного числа, но она каждый раз одна и та же, а мне нужна каждый раз разная.

Принятый ответ

Похожие вопросы:

ответ
Нашел.
ответ
Вот смотрите, раз не верите.
Кнопка Вверх.
Каму нужен ответ (От меня) на мой вопрос: Пишите в ЛС (Личное сообщение).
ответ
Поменяй random real на random integer
Random real возвращает и дробную часть
ответ
Sumert, хорошая идея

код

native UnitAlive takes unit id returns boolean

function CountAliveUnitsInGroupEnum takes nothing returns nothing
    if UnitAlive(GetEnumUnit()) then
        set bj_groupCountUnits = bj_groupCountUnits + 1
    endif
endfunction

function CreateUnitsForPlayer takes player p returns nothing
    local integer first = 1 //первый элемент массива
    local integer last = 3 //последний элемент
    local integer random = GetRandomInt(first, last) //случайное число от первого элемента до последнего, т.е. от 1 до 3

    local integer units_index = GetRandomInt(1, 3) //случайное число от 1 до 3

    local group g = CreateGroup() //создаем группу

    local integer i = random //счетчик цикла
    loop
        call GroupEnumUnitsInRect(g, udg_locations[i], null) //добавляем в группу всех юнитов из области
        set bj_groupCountUnits = 0 //обнуляем счетчик
        call ForGroup(g, function CountAliveUnitsInGroupEnum) // считаем юнитов в группе

        if bj_groupCountUnits == 0 then //проверяем сколько вышло
            call CreateUnit(p, udg_buildings[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 270.)

            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)
            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)
            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)
            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)

            exitwhen true
        else // если юнитов больше 0, тогда
            call GroupClear(g) // очищаем группу
        endif

        set i = i + 1
        if i > last then
            set i = first
        endif
        
        exitwhen i == random
    endloop

    //избавляемся от утечек
    call GroupClear(g)
    call DestroyGroup(g)
    set g = null
endfunction
ответ
это подойдет?

`
ОЖИДАНИЕ РЕКЛАМЫ...
0
19
7 лет назад
0
Похожие вопросы:

ответ
Нашел.
ответ
Вот смотрите, раз не верите.
Кнопка Вверх.
Каму нужен ответ (От меня) на мой вопрос: Пишите в ЛС (Личное сообщение).
ответ
Поменяй random real на random integer
Random real возвращает и дробную часть
ответ
Sumert, хорошая идея

код

native UnitAlive takes unit id returns boolean

function CountAliveUnitsInGroupEnum takes nothing returns nothing
    if UnitAlive(GetEnumUnit()) then
        set bj_groupCountUnits = bj_groupCountUnits + 1
    endif
endfunction

function CreateUnitsForPlayer takes player p returns nothing
    local integer first = 1 //первый элемент массива
    local integer last = 3 //последний элемент
    local integer random = GetRandomInt(first, last) //случайное число от первого элемента до последнего, т.е. от 1 до 3

    local integer units_index = GetRandomInt(1, 3) //случайное число от 1 до 3

    local group g = CreateGroup() //создаем группу

    local integer i = random //счетчик цикла
    loop
        call GroupEnumUnitsInRect(g, udg_locations[i], null) //добавляем в группу всех юнитов из области
        set bj_groupCountUnits = 0 //обнуляем счетчик
        call ForGroup(g, function CountAliveUnitsInGroupEnum) // считаем юнитов в группе

        if bj_groupCountUnits == 0 then //проверяем сколько вышло
            call CreateUnit(p, udg_buildings[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 270.)

            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)
            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)
            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)
            call CreateUnit(p, udg_units[units_index], GetRectCenterX(udg_locations[i]), GetRectCenterY(udg_locations[i]), 0.)

            exitwhen true
        else // если юнитов больше 0, тогда
            call GroupClear(g) // очищаем группу
        endif

        set i = i + 1
        if i > last then
            set i = first
        endif
        
        exitwhen i == random
    endloop

    //избавляемся от утечек
    call GroupClear(g)
    call DestroyGroup(g)
    set g = null
endfunction
ответ
это подойдет?

Принятый ответ
2
5
7 лет назад
2
Прошу прощения, нашел!
3
18
7 лет назад
3
В настройках редактора нужно отключить фиксированный случайный разброс.
Чтобы оставить комментарий, пожалуйста, войдите на сайт.