Skip to content
User Avatar
#3829
Auto-translated
Azgalor
I've fixed the issue. I wrote the following:
--All sorts of things before these lines
local n = random(length(creatures_positions))+1
local x = creatures_positions[n].x
local y = creatures_positions[n].y

--All sorts of things after these lines, k has been replaced with n

Now the random function works, and the creatures spawn at random saved coordinates 😇 Still, a huge thank you for correcting the function that saves the coordinates and for helping with the respawn function!


I still don't understand your task, but never mind. My code iterates through all k creatures (while i is not needed) and generates a random index k until it exists in the array of indices. As soon as it doesn't, it works with the creature with the generated index k.

The reason for this check with a loop is that a simple random function (like yours) can produce duplicate values, and as I understand it, that shouldn't happen. Perhaps I misunderstood.

And in general, it's very strange that it doesn't work for you and generates in two places. I ran some test prints for k=100, and it generated a bunch of values, all different (well, I didn't scroll through all of them).
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________