Page 1 of 1

How to randomize script execute between items?

Posted: Mon Sep 15, 2025 3:26 pm
by JtoTheB
In my map, I want the player to have to collect a specific item out of many other of the same item. The issue is, I don't want the player instantly going for the one that executes the script, and I want it to be random.

Re: How to randomize script execute between items?

Posted: Mon Sep 15, 2025 5:43 pm
by Enjay
If there aren't too many things, you could give each one a unique tid, then use Thing_SetSpecial to allocate the special for running the script to one of the actors, choosing the actor's tid at random.

Something like: Thing_SetSpecial (random(1,5), 80, 200, 0, 0);

I haven't checked it but that should randomly choose a tid from 1 to 5, and then allocate the special of running a script (80 is ACS_Execute) to the actor with the chosen tid. When the thing is picked up, script 200 will run. Obviously choose numbers that suit your actual situation.

Re: How to randomize script execute between items?

Posted: Mon Sep 15, 2025 6:42 pm
by JtoTheB
I'm afraid I have too many things for that, is there any other way to do it?

Re: How to randomize script execute between items?

Posted: Tue Sep 16, 2025 8:39 am
by stainedofmind
Just an idea here. At the start of the map, use ThingCount (https://zdoom.org/wiki/ThingCount) to grab the number of those items, then use the randomize function to pick a number between 1 and the number of items you have. From there, you can either have a script running that periodically checks if the number of those items is less than or equal to that number, and if so, the player has collected the "picked" item, or somehow work that check into the items pickup code. Essentially works the same way, but it depends on the order they are picked up.

Re: How to randomize script execute between items?

Posted: Tue Sep 16, 2025 1:21 pm
by JtoTheB
I feel like i've seen what i'm going for replicated in other WADS but with switches. I vividly remember a room in one specific mod with 6 switches on each side and the correct switch would be random every time you played.