Is it possible to give potions an "overdose" effect?

Started by necrocrunk on

Topic category: Help with modding (Java Edition)

Last seen on 05:39, 17. Jan 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is it possible to give potions an "overdose" effect?

I'm creating a very, very simple mod add on for a personal server with some friends, and the potion I'm adding adds things like regen and saturation.

I'd like to find a way to make it where if consumed more than 3 times within a certain period, (like, 10/20  mins or so) it starts causing negative effects like an overdose. I could potentially create an effect called overdose for visuals, if that's something that could be done for this, but if not totally fine. I'm curious how I would implement all of this.

I also considered setting up a withdrawal system (what im making isn't a 'drug' explicitly, it's a re-animator reference lol) but I am INCREDIBLY out of my depth here. I am good at html and css coding, but javascript is something I don't understand well at all. I may need this explained in layman's terms OR shown to me visually. 

Regardless, I'm looking for someone to help me smooth out some ideas. Willing to speak with someone through discord for future help too.

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You might not be as out of…
Wed, 12/27/2023 - 07:13

You might not be as out of your depth as you say- this should be pretty straightforward with MCreator's built in systems. I did something similar to this, a simple 'potion sickness' effect to discourage spamming potions. For that I just made a procedure that triggers whenever the player finishes using a potion item, and then either gives them the sickness status effect, or gives them a random negative status effect if they already have sickness.

If you want to make something a little more elaborate, you could make a player persistent number variable for a timer, and a procedure that triggers every player tick and either ticks it down by one or resets it if it reaches zero. You could then have another player persistent number variable that tracks the number of potions the player has drunk, and tick this down by one every time your first timer resets, or give the player a negative status effect and tick it down by one if it exceeds 3. Two procedures, (one for each timer), and two variables should do it. (You could also make a custom status effect to act as a warning when the player is at 3 potions.)

But yeah, happy to send some screenshots if that'd help! Funnily enough I'm also not great with JAVA, I wind up just using the visual code a lot. Which is slightly embarrassing, but saves me having to rearrange imports every two minutes, so I can live with it.

Last seen on 14:13, 26. Jul 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
not sure if that will work…
Wed, 12/27/2023 - 16:48

not sure if that will work but try that
1. make that so if you consume potion, +1 adds to number NBT tag (not sure how to make it with only potions)
2. if that tag > 0 then do wait procedure and set that nbt tag to 0
3. if that tag > 3 then give that effect to player and reset that nbt tag to 0
4. optionally you could make it set to 0 after you die, eat something, etc.

Last seen on 14:13, 26. Jul 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
instead of 3 put 2 sorry
Wed, 12/27/2023 - 16:49

instead of 3 put 2 sorry

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
NBT tags cannot be used on…
Fri, 12/29/2023 - 12:36

NBT tags cannot be used on players, to the best of my knowledge. But player variables are basically the same thing, and are more consistent in general.

Last seen on 05:39, 17. Jan 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
But yeah, happy to send some…
Sun, 12/31/2023 - 00:52

But yeah, happy to send some screenshots if that'd help! Funnily enough I'm also not great with JAVA, I wind up just using the visual code a lot. Which is slightly embarrassing, but saves me having to rearrange imports every two minutes, so I can live with it.

im going to spend some time fiddling with it myself, but i'd love to see what you'd recommend ! i'm worried about server load if i  make a code that's too shoddy or potentially works in a way that is too intensive.

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Generally speaking, the…
Sun, 12/31/2023 - 01:30

Generally speaking, the difference between good code and bad code that works good enough isn't going to be too noticeable. It's  usually more of a large-scale approach kind of thing. A little bit of unnecessary repetition isn't the end of the world, but if you're spawing hundreds of entities, or running a lot of code every tick, generating really large structures all at once... with a couple small exceptions the things that will break the game generally sound like bad ideas to begin with. 

The small exception is 'while' loops and recursion. (Procedures that for some reason need to call themselves multiple times). When I was new to coding, so many problems wound up being minor issues with things looping endlessly. Be careful with those. Otherwise, (at risk of encouraging shoddy code), try stuff until it works, don't get too discouraged, and ideally go back and improve stuff later!

Last seen on 05:39, 17. Jan 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
will update and say, after a…
Sun, 12/31/2023 - 08:33

will update and say, after a full day of tinkering on and off, what im finding is that theres some minor frame drops and performance issues, so i'm trying to figure out if theres a way to condense things.

 also trying to pinpoint how many blocks i actually need to add in to tell it to 1. start a 'timer' (set variable to 6000 for ex and tick down every player tick) and reset is when the items consumed variable tag is above 0
2. remove 1 for the variable tag for how many items have been consumed
3. do it in a way that wont bog down a server that i know my friend probably won't soup with way too many GB to handle intensive procedures. 
4. finding out if checking for the overdose effect and removing the reanimated affect if it's present is part of the performance issue

while i've got it somewhat working to my specs, i'm hitting a wall with knowing if i'm doing things super roundabout on accident lol. i can share any code snippets but im sure they'll be a mess to read and parse

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah, this definitely…
Sun, 12/31/2023 - 17:08

Yeah, this definitely shouldn't be causing performance issues. If you're using 'wait' or 'while' loops, it's possible you've got something looping endlessly in the background. 

To make a timer, you should just create a number variable, and then have a procedure with the 'on player update tick' global trigger. Then have an if bracket that checks if the variable is greater than zero. If it is, set that variable to the current value of the variable, minus one. This way, whenever there is a timer, it will tick down automatically without you doing anything. 

From then on the logic should just be making another number variable for the potion counter, and another procedure to manage it. Use the 'player finishes using item' global trigger, and check if the item is a potion. If it is, increase the counter variable by one. (And if the counter variable is too high, give them negative status effects.) You can then add another section onto the timer procedure that decreases the counter by one whenever it reaches zero, and then resets the timer if the counter is itself still above zero.

If you're having performance issues, it's likely something else that's causing the problem. You could also try restarting MCreator, or clearing your gradle caches, that often helps.

Last seen on 05:39, 17. Jan 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
my formal apologies to…
Sun, 12/31/2023 - 22:08

my formal apologies to anyone who's going to see this absolute chunk of photos haha, i've been tweaking and tweaking and redoing things over and over and i gotta say, giving myself a bit of a headache. 

this has been a pet project for probably a one off server so in the end, if i cant get things working ill likely go back to an older version of this and work with just the item giving a baseline effect. i did have to make the "potion" in question an item more technically, because i couldn't call upon it for an origin associated with this item that needed to consume that item. it's still a consumable so it works out.

regardless, still having terrible performance issues, so im wondering if theres a logic bit here my brain just hasn't caught up on (ive been staring at it for so long i may just not be seeing smth)

ANYWAY, thank you so much for the help and advice so far, i've been having a lot of fun learning how to use this in the mean time. my hope is getting to make bigger pet projects for me and my friends servers

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
First picture is sort of…
Sun, 12/31/2023 - 23:19
  • First picture is sort of fine, the first else-if bracket might be unessasary if you're always removing the 'reanimated' effect whenever overdose is initially applied. (Unless you want it to always do this, in which case this would need to be called from a procedure that triggers every tick.)
  • Second picture: This procedure shouldn't be necessary. If you're using player lifetime variables, the variables will automatically reset on death. (However, keep in mind, this won't work for non-player entities. Though you can use NBT number tags to accomplish the same thing.)
  • Third picture is probably fine, it's hard to tell without context for which variable is which. Either way, you could combine this with the fourth procedure and use an else-if statement to avoid having the two clash.
  • Same thing, not sure about the fourth procedure, but keep in mind if you're using 'reagent consumed' as a counter instead of a timer, you don't want it to go down every tick, just every time the timer passes a certain point. (If 'reagent consumed' is the timer, then it's fine.)
  • The last two procedures should work fine, just depends on when and how you're triggering them. You might want to include 'round' or 'round down' functions for health and hunger, I'm not 100% sure how it responds to decimal values. (Such as multiplying seven hearts by 0.5)

Nothing looks like it should be causing any major issues. Double check that your timers and counters reset properly, (otherwise they might be stuck on or below zero and constantly calling a procedure), but otherwise, it's probably something else causing the issues.

Last seen on 05:39, 17. Jan 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, followed some of these…
Mon, 01/01/2024 - 03:02

Okay, followed some of these and a few tweaks definitely helped, it's running much better from what I'm seeing. I must have had something looping, or maybe the check for the consumed counter was unnecessary.

I'm having another problem now, if someone dies while any custom effect is active, the death screen glitches out severely and refuses to let them restart or quit, instead they have to close the entire world or game. Is this a known problem or am i not accounting for something in code?

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Not an error I’ve ever heard…
Mon, 01/01/2024 - 03:05

Not an error I’ve ever heard of- it’s possible if you didn’t delete the variable reset procedure, it resets the counters, but then stops ticking the player, so it loops the counter procedure endlessly but can’t find a living entity to target. Did you change the variables to player lifetime instead of persistent?

Last seen on 05:39, 17. Jan 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It is lifetime, went and…
Mon, 01/01/2024 - 04:38

It is lifetime, went and doublechecked. It's not just the overdose effect that is causing this either, it's all custom effects made by this mod. Doubling down on clearing potion effects with a trigger dependent on entity death and hoping that fixes it?

tried that, did not work- in fact made it work and crashed the game.

for context, it's usually killing players and on their screen they are caught in the laying down death animation while the effects are still trying to tick health up (like my Reanimated affect causes health regen using the "potion-like tick procedure")

hitting a wall with it honestly, not sure where the issue is but it may just be something i simplify down for the sake of the server for now.

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If the problem is with death…
Mon, 01/01/2024 - 06:15

If the problem is with death itself, it may have something to do with the effects still trying to add hearts once the entity has already died. (Not 100% certain, but that's my best guest.) You might consider adding another if bracket to check if the entity is alive? (Not that it exists, but specifically that it's alive- there's an 'is entity alive' logic function in the entity management tab.)