Jump to content

Recommended Posts

Posted

Hi,

So I recently followed a tutorial on how to make custom potion effects, and I did so, but I couldn't figure out how to do anything with it (for my needs). I'm not only looking for something that makes you jump higher or makes you invisible. I'm looking for some way to add things on the screen, such as in this mod:

 

 

Any help is appreciated. thanks!

-Pandassaurus

Posted

You can check if the player has a potion effect from almost anywhere you'd need it, so you can do anything you want. If you want to do something like that, just use the PlayerTickEvent hook to render a overlay if the player has your potion effect on (which you can check with player.isPotionActive(yourpotioneffect) )

 

There's plenty of tutorials on the rendering part of that too btw, it's not really that complicated :P

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Posted

Hi,

I don't really know what the RenderGameOverlayEvent is. What I have right now is a hook, but I'm not sure what to do with it.

 

 

/**
* User: Pandassaurus
* Date: 4/7/14
*/
public class BreakingBadEventHooks {
    @SubscribeEvent
    public void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
        if (event.entityLiving.isPotionActive(BreakingBad.CrystalSky_)) {
            event.entityLiving.attackEntityFrom(DamageSource.generic, 2);
            if (event.entityLiving.worldObj.rand.nextInt(20) == 0) {
               //As far as I know, i would write whatever it does here
            }
        }
    }
}

 

 

I learned to write it there, but i'm not sure what I would put there for the effect on the screen to show up,

 

Thanks for the help,

-Pandassaurus

Posted

Well, to use things like this, you have to understand the code your using. First, that is definitely NOT the place to put it, not anywhere close. Let me walk you through what you have so far... Right now, what you are doing is subscribing to forges event handler (that's what the @SubscribeEvent is, it's telling forge to run that function when the kind of event you specify happens) the LivingEvent.LivingUpdateEvent tells forge every entity should run this code for itself each update. In your case, since enemies and other things shouldn't get any kind of overlay, you should change this to something else (I'll get to that). Next, it's checking if the entity it's running the code for has the buff with event.entityliving.ispotionactive, and if it has the effect then it's damaging it for 2 damage with event.entityliving.attackentityfrom (remember this code is running each tick, so 20 times a second. I would assume you don't want the attacking to happen, or at least not that rapidly, so you should remove this code. Finally, it's picking a number between 1 and 20, and if it equals 20 it's running the code in the area you think you should put the overlay, effectively rendering the overlay about once a second, for a tick (a 20th of a second). If you want something to be happening constantly (to the game every tick is constantly), don't put it in that area (infact you could probs delete that whole if statment). To do something to any entity with your effect, use event.entityLiving.INSERTWHATEVERFUNCTIONYOUWANTTOCALLHERE, or something similar.

 

For the overlay, you'll need to make another class very similar to this, but without the code in the onEntityUpdate function. Then, you'll need to change LivingEvent.LivingUpdateEvent to RenderGameOverlayEvent. This tells forge to run your code every time it's drawing the game overlay Then you should do a check to see if the player has your potion effect (to see how, you already did it in the code you have), and you'll need to put all the rendering code in that if statment. You can find how to do the rendering online, there should be plenty of tutorials on screen overlays and HUD's (I wouldn't search for doing it with potion effects though, there might not be any for that in specific and adapting the code for something else like a helmet HUD is easy)

 

BTW, if you're gonna use tutorials make sure you follow along and know WTF you're actually doing and pay attention to how it works while you're following it instead of just copying and pasting blindly. (Other people on these forums might not be so tolerant of people who just copy from tutorials and expect it to work :P )

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Posted

Hi,

Theres only one problem. If I only use RenderGameOverlayEvent and not LivingEvent.LivingUpdateEvent, how would I check to see if the potion is active?  I tried doing both only to get a crash. Do I have each separate class and call the function in the first Hook?

 

this is what i have:

 

public class BreakingBadEventHooks {
    @SubscribeEvent
    public void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
        if (event.entityLiving.isPotionActive(BreakingBad.CrystalSky_)) {
        }
    }
}

 

 

 

public class BreakingBadGuiHook {
    @SubscribeEvent
    public void onEntityUpdate(RenderGameOverlayEvent event, LivingEvent.LivingUpdateEvent e) {
        if (e.entityLiving.isPotionActive(BreakingBad.CrystalSky_)) {

        }
    }
}

 

thanks,

-Pandassaurus

 

Posted

Hi,

Theres only one problem. If I only use RenderGameOverlayEvent and not LivingEvent.LivingUpdateEvent, how would I check to see if the potion is active?  I tried doing both only to get a crash. Do I have each separate class and call the function in the first Hook?

 

this is what i have:

 

public class BreakingBadEventHooks {
    @SubscribeEvent
    public void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
        if (event.entityLiving.isPotionActive(BreakingBad.CrystalSky_)) {
        }
    }
}

 

 

 

public class BreakingBadGuiHook {
    @SubscribeEvent
    public void onEntityUpdate(RenderGameOverlayEvent event, LivingEvent.LivingUpdateEvent e) {
        if (e.entityLiving.isPotionActive(BreakingBad.CrystalSky_)) {

        }
    }
}

 

thanks,

-Pandassaurus

If you can get the player variable from RenderGameOverlayEvent via event.player or something of the sort,mthen just use event.player.isPotionActive(etc.) to check. If you can't (I think you can...) you MIGHT be able to put the rendering code in a player tick hook (functions the exact same as a LivingUpdateEvent but only runs for the player, which you would want because mobs can't have an overlay, so there's no sense in running any code for them).

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.