How to make code run at every player at every interval

Started by wowlmao on Sat, 11/19/2022 - 21:48

Topic category: Help with modding (Java Edition)

Last seen on 03:12, 22. Nov 2022
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How to make code run at every player at every interval
Sat, 11/19/2022 - 21:48

I recently saw this youtube video. I want to make a similar feature like how the air raids came in. But I don't know how to Run a piece of code at every player at a timed interval. Basically every 10 minutes an air raid spawns at every player 

Last seen on 00:40, 27. Jan 2023
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
You could either do this by…
Sat, 11/19/2022 - 22:43

You could either do this by making a procedure that runs on every player tick, (that is, ticks for each player individually), or every world tick, (that is, ticks for all players simultaneously), depending on what you want. Just keep in mind that you don't want super complex procedures firing every 20th of a second. Make sure the conditions are simple, and if the conditions are met, have it execute a more complicated procedure to spawn the raids.

Last seen on 03:12, 22. Nov 2022
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I thought about that too but…
Sun, 11/20/2022 - 05:26

I thought about that too but the problem is that to count I need to spawn the entity at every players coords so the world tick wouldn't work. Thenif I Incremented the player tick once every time and there was two players it wont work. Even if I divided the increment by the number of players that woiln't work

Last seen on 00:40, 27. Jan 2023
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I'm not entirely sure what…
Sun, 11/20/2022 - 06:01

I'm not entirely sure what you're getting at, but here's a more consise explanation of an idea for how this could work:

If you're doing something every World Tick:

  • Make a custom number variable that goes down every world tick as long as it's greater than zero. Once it reaches zero, you'll trigger the raid. (You can also randomize this if you don't want there to be a specific amount of time between raids.) When a raid is triggered, you can then set the number variable back to however long you want between raids.
  • When a raid is triggered, either use a command to summon entities at the positions of all players, (@a), or make use the entity iterator block for 'all players in world,' which will execute the desired procedure relative to the position of each individual player. (It can be found in the world management tab.)

If you're doing it every player tick, (players would then have raids occurring at different times), basically do the same thing, but make the number variable player-persistent instead of world based. (Or player-lifetime, if you want it to reset on death.) Then just trigger your raid relative to that specific player's position.