How to randomize script execute between items?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
JtoTheB
Posts: 50
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

How to randomize script execute between items?

Post 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.
User avatar
Enjay
 
 
Posts: 27146
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: How to randomize script execute between items?

Post 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.
User avatar
JtoTheB
Posts: 50
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

Re: How to randomize script execute between items?

Post by JtoTheB »

I'm afraid I have too many things for that, is there any other way to do it?
User avatar
stainedofmind
Posts: 228
Joined: Sun Sep 01, 2019 10:59 am

Re: How to randomize script execute between items?

Post 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.
User avatar
JtoTheB
Posts: 50
Joined: Sat Aug 09, 2025 9:46 am
Operating System Version (Optional): Windows 11
Location: New Jersey

Re: How to randomize script execute between items?

Post 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.
Post Reply

Return to “Scripting”