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
    376
    Thanks given
    406
    Thanks received
    70
    Discord
    View profile
    Rep Power
    79
    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:
    [Only registered and activated users can see links. ]
    so this work for 667 n 718 then jw
    Reply With Quote  
     

  2. #12  
    Registered Member
    Join Date
    Jan 2013
    Posts
    611
    Thanks given
    291
    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,342
    Thanks given
    274
    Thanks received
    513
    Rep Power
    3955
    Nicely done
    Reply With Quote  
     

  4. #14  
    Java4Love

    Sagacity's Avatar
    Join Date
    Dec 2012
    Age
    24
    Posts
    696
    Thanks given
    274
    Thanks received
    82
    Discord
    View profile
    Rep Power
    88

    Check out my 667/718 Interfaces services, I have more than 15 vouches and will be happy to help you out for affordable prices
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #15  
    Discord Johnyblob22#7757


    Join Date
    Mar 2016
    Posts
    1,342
    Thanks given
    274
    Thanks received
    513
    Rep Power
    3955
    Quote Originally Posted by Sagacity View Post
    nice
    Reply With Quote  
     

  6. #16  
    Registered Member

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

    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
  •