Skip to content
User Avatar
#3822
Auto-translated
}{0TT@6bI4
In other words, you want to replace all creatures from 1 to k with a certain condition and luck, but you want this to happen
a) Inconsistently
b) Without repetition
c) With all k elements

Then you need an interesting algorithm:
local used_indexes = {}
for i=1, k do
repeat N=random(k)+1
until not used_indexes[N]
used_indexes[N] = 1;
--Actions with the creature with number N (not k!!)
end

 

It seems like you have some kind of error here - i is not passed anywhere. Or should it be n instead of i? I tried it in the game with your version, and the creatures spawned in the first two locations. Luckily, they have fixed spawn points, otherwise the game would crash due to lag 😆 

I made a few adjustments and ran it again - now the monsters spawn in different locations, but still in the same order, i.e., I run the function a second time, and it spawns the monsters in the same locations.

 

Yes, and here's another question. I have this condition in the function:

local type = random( 3 ) + 1
if ( WR_luck < 3 ) and ( type == 4 ) then
type = random( 2 ) + 1
end

Before I put these two conditions in parentheses, the game ignored them. Why? When should parentheses be used in conditions?