Thread: OSBuddy Health Bar

Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11  
    Registered Member
    Join Date
    Mar 2013
    Posts
    579
    Thanks given
    684
    Thanks received
    137
    Rep Power
    217
    Quote Originally Posted by Lucifer_ View Post
    Hello,

    A lot of people have wanted this, so I'll release a snippet of how mine works on my own personal server, which is running on the revision 667. This is not complete, and is only a snippet. There are many changes that you would have to make in order to ensure full functionality.

    OSBuddyHealthBar.java:

    Code:
    package org.nova.kshan.content.interfaces;
    
    import org.nova.Constants;
    import org.nova.cache.loaders.WidgetDef;
    import org.nova.game.entity.Entity;
    import org.nova.game.npc.NPC;
    import org.nova.game.player.Player;
    
    /**
     * Handles the overlay of the OSBuddy Health Bar.
     * 
     * @author K-Shan
     *
     */
    public class OSBuddyHealthBar {
    
    	/**
    	 * Represents the widget ID which contains the OSBuddy health bar.
    	 */
    	public static final int WIDGET = 1156;
    
    	/**
    	 * 
    	 * @param player
    	 * @param entity
    	 * @param hp
    	 */
    	public static void showBar(Player player, Entity entity, int hp, int damage) {
    		if(entity != null && entity instanceof Player)
    			showPlayerHealth(player, ((Player) entity),damage);
    		else
    			showNPCHealth(player, ((NPC) entity), damage);	
    		if(hp < 1) {
    			player.doAfterDelay(1.5, () -> { closeBar(player); });
    			player.getData().getRuntimeData().remove("osbuddy_health");
    			player.getData().getRuntimeData().remove("osbuddy_last_hp");
    			return;
    		}
    	}
    
    	/**
    	 * 
    	 * @param p
    	 * @param npc
    	 * @param hp
    	 */
    	public static void showNPCHealth(Player p, NPC npc, int damage) {
    		if (!p.interfaces().containsInterface(WIDGET))
    			p.interfaces().sendTab(2, WIDGET);
    		p.packets().sendString(npc.getName(), WIDGET, 3);
    		p.packets().sendString(npc.getHitpoints()+"/"+npc.getMaxHitpoints(), WIDGET, 7);
    		double calculated = 161.0 * ((double) npc.getHitpoints() / npc.getMaxHitpoints());
    		int total = (int) Math.floor(calculated);
    		if(Constants.DEVELOPER_MODE && p.getRights() > 1)
    			p.sm("Percentage of health bar: "+calculated+": To display: "+total);
    		int green = 6;
    		int yellow = 5;
    		WidgetDef greenBar = WidgetDef.getComponent(WIDGET, green);
    		WidgetDef yellowBar = WidgetDef.getComponent(WIDGET, yellow);
    		p.packets().changeWCSize(WIDGET, green, npc.getHitpoints() < 1 ? 0 : total, greenBar.baseHeight);
                    // add animation here
    		p.doAfterDelay(0.600, () -> { 
    			p.packets().changeWCSize(WIDGET, yellow, npc.getHitpoints() < 1 ? 0 : total, yellowBar.baseHeight);
    		});
    	}
    
    	/**
    	 * 
    	 * @param p
    	 * @param other
    	 * @param hp
    	 */
    	private static void showPlayerHealth(Player p, Player other, int damage) {
    		if (!p.interfaces().containsInterface(WIDGET))
    			p.interfaces().sendTab(2, WIDGET);
    		p.packets().sendString(other.getDisplayName(), WIDGET, 3);
    		p.packets().sendString(other.getHitpoints()+"/"+other.getMaxHitpoints(), WIDGET, 7);
    		double calculated = 161.0 * ((double) other.getHitpoints() / other.getMaxHitpoints());
    		int total = (int) Math.floor(calculated);
    		if(Constants.DEVELOPER_MODE && p.getRights() > 1)
    			p.sm("Percentage of health bar: "+calculated+": To display: "+total);
    		int green = 6;
    		int yellow = 5;
    		WidgetDef greenBar = WidgetDef.getComponent(WIDGET, green);
    		WidgetDef yellowBar = WidgetDef.getComponent(WIDGET, yellow);
    		p.packets().changeWCSize(WIDGET, green, other.getHitpoints() < 1 ? 0 : total, greenBar.baseHeight);
                    // add animation here
    		p.doAfterDelay(0.600, () -> { 
    			p.packets().changeWCSize(WIDGET, yellow, other.getHitpoints() < 1 ? 0 : total, yellowBar.baseHeight);
    		});
    	}
    
    	/**
    	 * 
    	 * @param player
    	 */
    	private static void closeBar(Player player) {
    		player.packets().closeInterface(2);
    
    	}
    
    
    }
    ... where:
    "changeWCSize" is a method which adjusts the size of a widget component,
    "doAfterDelay" executes whatever is inside of the curly braces after the specified delay, in seconds.

    If you have any questions, feel free to ask.

    Here is a gif of it in action:
    https://gyazo.com/454383bfba43a8ae6412fc7f67f3e16f
    so this work for 667 n 718 then jw
    Reply With Quote  
     

  2. #12  
    Registered Member
    Join Date
    Jan 2013
    Posts
    610
    Thanks given
    292
    Thanks received
    120
    Rep Power
    39
    Quote Originally Posted by Superkickabout View Post
    Could you upload the interface/widget data file? I know its just a couple rectangles and text, but for those who don't know how to make them.
    Try making those transparent rectangles with Paint.NET my dimensions were 161x17. The widget data is something that I made with my own editor, so I can't provide the code for that here since I do sell custom made interfaces. If you have questions though, I'll gladly answer them here or through private message.

    Quote Originally Posted by deaneo8 View Post
    so this work for 667 n 718 then jw
    Yes, it should work for 562-718 and those servers that load rs3 caches but are still 718. I'll create it for 562 to display, shouldn't be too different
    Reply With Quote  
     

  3. #13  
    Discord Johnyblob22#7757


    Join Date
    Mar 2016
    Posts
    1,384
    Thanks given
    365
    Thanks received
    575
    Rep Power
    5000
    Nicely done
    Attached image
    Reply With Quote  
     

  4. #14  
    Onyxia

    Sagacity's Avatar
    Join Date
    Dec 2012
    Age
    27
    Posts
    727
    Thanks given
    335
    Thanks received
    98
    Rep Power
    160
    Attached image

    Check out my 667/718 Interfaces services, I have more than 25 vouches and will be happy to help you out for affordable prices
    Attached image
    Reply With Quote  
     

  5. #15  
    Discord Johnyblob22#7757


    Join Date
    Mar 2016
    Posts
    1,384
    Thanks given
    365
    Thanks received
    575
    Rep Power
    5000
    Quote Originally Posted by Sagacity View Post
    Attached image
    nice
    Reply With Quote  
     

  6. Thankful user:


  7. #16  
    Registered Member

    Join Date
    Feb 2014
    Posts
    429
    Thanks given
    5
    Thanks received
    3
    Rep Power
    173
    Quote Originally Posted by Johnyblob22 View Post
    nice
    nice for you to pay me back.....

    Attached image
    Reply With Quote  
     

Page 2 of 2 FirstFirst 12

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Health bar Issue
    By Gnakos in forum Help
    Replies: 0
    Last Post: 02-08-2012, 07:20 PM
  2. Replies: 0
    Last Post: 12-15-2011, 12:40 AM
  3. Replies: 0
    Last Post: 06-22-2011, 09:50 PM
  4. [508] HitSplats and Health Bar
    By Demon in forum Help
    Replies: 8
    Last Post: 08-23-2010, 07:04 PM
  5. [508] HitSplats and Health Bar
    By Demon in forum Help
    Replies: 0
    Last Post: 08-21-2010, 05:31 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •