How to despawn a bullet if another one is spawned (SOLVED!!)

Started by Stoutscientist on Sat, 09/04/2021 - 15:28

Topic category: Help with modding (Java Edition)

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How to despawn a bullet if another one is spawned (SOLVED!!)
Tue, 09/07/2021 - 15:10 (edited)

I'm making a mod that adds rush pearls from Hypixel but if you throw another one while flying you will lag between the two. What I'm trying to figure out is how to detect when to delete the old one and then delete it.

 

Thanks!

- Stoutscientist

Edited by Stoutscientist on Tue, 09/07/2021 - 15:10
Last seen on 17:40, 23. Oct 2021
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Try making a procedure that…
Sat, 09/04/2021 - 18:38

Try making a procedure that detect nearby entity and despawn bullet

Last seen on 17:40, 23. Oct 2021
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
use "for each entity in area…
Sat, 09/04/2021 - 18:39

use "for each entity in area"

 

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Can you give an example?
Sat, 09/04/2021 - 19:57

Can you give an example?

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
??
Sun, 09/05/2021 - 16:53

??

Last seen on 17:40, 23. Oct 2021
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
The bullet detects other…
Sun, 09/05/2021 - 21:22

The bullet detects other bullets around him and makes them despawn, I cannot post images because a host is needed

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
but then the new pearl will…
Sun, 09/05/2021 - 21:31

but then the new pearl will detect it and despawn

Last seen on 09:13, 19. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Add a variable for each…
Sun, 09/05/2021 - 22:15

Add a variable for each player. Each time you try to shoot, it checks if the variable is 1 or 0. If it's 0, it'll allow you to shoot. if it's 1, it won't shoot. When it shoots, it'll set the variable to 1. When it lands, it'll reset the variable back to 0. Guess you could use true or false for this too.

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
the issue is i want to be…
Sun, 09/05/2021 - 22:32

the issue is i want to be able to throw multiple while flying

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
i just want the old ones to…
Sun, 09/05/2021 - 22:33

i just want the old ones to get deleted

Last seen on 09:13, 19. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Oh... Ok then. If you're…
Mon, 09/06/2021 - 03:31

Oh... Ok then. If you're doing multiplayer, this will also work. When a player joins, the game will do a when player joins procedure to give the player a random number between 1 and 100000 as a variable for the player (Player persistent variable). This is so that the player's number code won't overlap. It might sound useless and why am I doing this? But you'll understand it. Next, we have the ranged item. Let's say we have a bow for example. We shoot the bow, and and arrow comes out. In minecraft, the arrow is classified an entity, meaning you can give it a tag. So then when the ranged item is thrown, you can call a procedure to run a slash command. Now this is where it gets important. Remember the player number code each player has? Let's say your code is 1245. Then the ranged item entity will give itself the same code as the player. This way, we know that specific bullet was shot by a specific player. Then you have the variable I was talking about a day ago (The 1 and 0 one) so if it's 0, then it just shoots normally. If it's 1, before it's shot, it'll kill all entities with the tag of the player, except for the player. And then it shoots the ranged item and gives itself the ID. To put it simply:

 

Put a unique ID on each player

When a ranged item is thrown, it kills all bullet entities with that ID, and doesn't kill the player

It then gives itself the ID the player has with the /tag command.

That way, if a new bullet is thrown, all other bullets with the same tag will be killed and disappear.

Sorry if my explaining was bad.

Last seen on 09:13, 19. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Ok I just realized the first…
Mon, 09/06/2021 - 03:33

Ok I just realized the first part was hard to understand. You want to give each player a unique number with a variable (Player persistent variable). That summarized the player and code, number part.

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Ok I got 99% of it done but…
Mon, 09/06/2021 - 16:52

Ok I got 99% of it done but I can't figure out how to kill all the entities with that specific tag

Last seen on 03:23, 24. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
if it helps my tag name is…
Mon, 09/06/2021 - 16:52

if it helps my tag name is test and the namespace is forge

Last seen on 09:13, 19. Oct 2021
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Oh not that tag. Sorry, my…
Tue, 09/07/2021 - 04:49

Oh not that tag. Sorry, my explaining was bad. It's just a tag in minecraft. for the when ranged item shot procedure, instead of giving it that kind of tag, you give it a minecraft tag. Let's say we're adding a tag to a pig:

/tag add @e[type=pig] John

That way, the computer will recognize the mob as John and if you do

/kill @e[tag=John] it'll kill the pig.

We're gonna use this and do exactly what the image is doing here: https://drive.google.com/file/d/1Z6IbzlhbZCajRzSOL4w_7J58UfcpWyWB/view?usp=sharing

It's an image of the procedure you need. This is the procedure for when ranged item shot.

Replace the variable with the player variable you made, and replace the YouBulletEntityHere to the name of your bullet in minecraft namespace ID. Hopefully this helps!