Thread: Perfect Title System [Full Support]

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Perfect Title System [Full Support] 
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    151
    Thanks given
    37
    Thanks received
    121
    Rep Power
    165
    This should be the proper way to handle player titles.

    Preview


    Download: [Only registered and activated users can see links. ]
    or Create a new File and paste: [Only registered and activated users can see links. ]

    Place this file in your cache directory.

    [CLIENT]

    Create a new file named PlayerTitles
    Code:
    import com.sign.SignLink;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.File;
    import java.io.LineNumberReader;
    
    public class PlayerTitles {
    	
    	public static void unpack() throws IOException {
    		BufferedReader br = new BufferedReader(new FileReader(SignLink.findcachedir() + "title.dat"));
    		LineNumberReader lnr = new LineNumberReader(new FileReader(SignLink.findcachedir() + "title.dat"));
    		try {
    			String line;
    			lnr.skip(Long.MAX_VALUE);
    			archived = lnr.getLineNumber() + 1;
    			titleM = new String[lnr.getLineNumber() + 1];
    			titleF = new String[lnr.getLineNumber() + 1];
    			color = new String[lnr.getLineNumber() + 1];
    			int index = 0;
    			while((line = br.readLine()) != null) {
    				String[] data = line.split("#");
    				titleM[index] = data[0].trim();
    				titleF[index] = data[1].trim();
    				color[index] = data[2].trim();
    				index++;
    			}
    			System.out.println("Loaded: " + titleM.length + " Titles");
    		} finally {
    			br.close();
    			lnr.close();
    		}
    		br.close();
    		lnr.close();
    	}
    	
    	public boolean getGender(Player player) {
    		if(player.anInt1702 == 0)
    			return true;
    		
    		return false;
    	}
    
    	public String format(String title) {
    		for(int index = 0; index < suffixChar.length; index++) {
    			if(title.startsWith("<col="))
    				title = title.substring(12);
    			
    			if(title.startsWith(suffixChar[index])) {
    				suffix = true;
    				if(index < 4) {
    					return " @";
    				} else 
    					return " #";
    			}
    		}
    		if(title.contains("</col>"))
    			return " $";
    		else 
    			return "";
    		
    	}
    
    	public String tag() {
    		String[] tag = {"str", "trans", "shad", "u"};
    		for(int id = 0; id < tag.length; id++)
    			if(title.contains("<" + tag[id]) && !title.contains("</"+ tag[id]))
    				return ("</" + tag[id] + ">");
    		
    		return "";
    	}
    
    	public String placement(String name, String title) {
    		if(name != null || title != null) {
    			if(suffix && format(title) == " @") 
    				name += "" + title + tag();
    			else
    			if(suffix && format(title) == " #")
    				name += " " + title + tag();
    			else {
    				String character = name;
    				name = title + (format(title) == " $" ? " " : "") + character + tag();
    			}
    			return name;
    		}
    		return "";
    	}
    	
    	public String title(int id, Player player) {
    		title = getGender(player) ? titleM[id] : titleF[id];
    		if(title.contains("null"))
    			title = titleM[id];
    		
    		return (color[id] + title + (id != 0 ? "</col>" : ""));
    	}
    	
    	public String get(int index) {
    		return color[index] + titleM[index] + "</col>";
    	}
    	
    	PlayerTitles() {
    		title = "";
    		suffix = false;
    	}
    	
    	String[] suffixChar = {
    		".", "?", ",", " ",
    		"to", "the", "was", "lost", "ate", "of", "<col", "<s", "Zil", "Scourge", 
    		"Master of", "Scion", "BlackB", "Runeb", "Ruler of", "Chronicl", "Slapsa", "le "
    	};
    	
    	public static int archived;
    	String title;
    	static String[] titleM;
    	static String[] titleF;
    	static String[] color;
    	boolean suffix;
    	
    }
    In your client class replace pushMessage(String, int, String) with
    Code:
    	public void pushMessage(String message, int view, String name) {
    		pushMessage(message, view, name, "");
    	}
    	
    	public void pushMessage(String message, int view, String name, String title) {
    		if (view == 0 && dialogueId != -1) {
    			clickToContinueString = message;
    			super.clickMode3 = 0;
    		}
    		if (backDialogueId == -1)
    			inputTaken = true;
    		
    		for (int previous = 499; previous > 0; previous--) {
    			chatTypes[previous] = chatTypes[previous - 1];
    			chatNames[previous] = chatNames[previous - 1];
    			chatMessages[previous] = chatMessages[previous - 1];
    			chatRights[previous] = chatRights[previous - 1];
    			playerTitles[previous] = playerTitle[previous - 1];
    		}
    		chatTypes[0] = view;
    		chatNames[0] = name;
    		chatMessages[0] = message;
    		chatRights[0] = rights;
    		playerTitles[0] = title;
    		
    	}
    Add the class instance
    Code:
    public PlayerTitles playerTitle = new PlayerTitles();
    Declare our new string (follow chatNames and place under)
    Code:
    playerTitles = new String[500];
    Code:
    public final String[] playerTitles;
    In drawChatArea, above
    Code:
    if(chatType == 0) {
    Code:
    	String title = playerTitles[messages] != null ? playerTitles[messages] : "";
    	name = playerTitle.placement(name, title);
    Scroll down and replace similar
    Code:
    	String s;
    	if (localPlayer != null && localPlayer.name != null) {
    		s = playerTitle.placement(localPlayer.name, playerTitle.title(localPlayer.title, localPlayer));
    	} else {
    		//Draws name before player is initiated into the server (precaution)
    		s = playerTitle.placement(StringUtils.formatUsername(capitalize(myUsername)), playerTitle.title(localPlayer.title, localPlayer));
    	}
    Search
    Code:
    localPlayer.textCycle = 150;
    Code:
    pushMessage(localPlayer.spokenText, 2, (myPrivilege == 1 ? "@[email protected]" : (myPrivilege > 1 ? "@[email protected]" : "")) + localPlayer.name, 
    				playerTitle.title(localPlayer.title, localPlayer));
    Search
    Code:
    player.textCycle = 150;
    Code:
    pushMessage(text, (privilege > 0 ? 1 : 2), (privilege == 1 ? "@[email protected]" : (privilege > 1 ? "@[email protected]" : "")) + player.name, 
    				playerTitle.title(player.title, player));
    Search
    Code:
    buildAtPlayerMenu
    Code:
    if (player.skill == 0)
    	s = playerTitle.placement(player.name, playerTitle.title(player.title, player)) + combatDiffColor(localPlayer.combatLevel, player.combatLevel) + " (level-" + player.combatLevel + ")";
    else
    	s = playerTitle.placement(player.name, playerTitle.title(player.title, player)) + " (skill-" + player.skill + ")";
    In your Player class,
    Code:
    public int title;
    Code:
    combatLevel = stream.readUnsignedByte();
    title = stream.readUShort();
    //skill = stream.readUShort();


    [SERVER]
    Spoiler for Click if you want:

    [CLIENT]
    In your Interface class, add
    Code:
    	public int processAction = 315;
    	public static void addConfigText(int id, int width, String text, String action, GameFont tda[], int idx, int color, boolean center, boolean shadow, int config, int configColor) {
    		Widget tab = addTabInterface(id);
    		tab.parent = id;
    		tab.id = id;
    		tab.type = 4;
    		tab.optionType = 1;
    		tab.width = width;
    		tab.height = 11;
    		tab.contentType = 0;
    		tab.opacity = 0;
    		tab.hoverType = -1;
    		tab.centerText = center;
    		tab.textShadow = shadow;
    		tab.textDrawingAreas = tda[idx];
    		tab.defaultText = text;
    		tab.textColor = color;
    		tab.secondaryColor = 0;
    		tab.defaultHoverColor = 0;
    		tab.secondaryHoverColor = 0;
    		tab.scriptOperators = new int[1];
    		tab.scriptDefaults = new int[1];
    		tab.scriptOperators[0] = 1;
    		tab.scriptDefaults[0] = config;
    		tab.scripts = new int[1][3];
    		tab.scripts[0][0] = 5;
    		tab.scripts[0][1] = configColor;
    		tab.scripts[0][2] = 0;
    		tab.actions = new String[] {action};
    		tab.processAction = ;//OPCODE
    	}
    
    	public static Client c() {
    		return Client.instance;
    	}
    
    	public static void buildTitleDisplay(GameFont[] text) {
    		int interfaceId = 14000;
    		Widget tab = addTabInterface(interfaceId);
    		tab.totalChildren(4);
    		addButton(24060, 2, "Interfaces/QuestTab/QUEST", 18, 18, "Swap to Info", 1);
    		setBounds(24060, 172, 4, 0, tab);
    		addButton(24061, 1, "Interfaces/QuestTab/QUEST", 18, 18, "Swap to Achievements", 1);
    		setBounds(24061, 154, 4, 1, tab);
    		
    		addText(24062, "Title Selection", 0xFF981F, false, true, 52, text, 2);
    		setBounds(24062, 10, 5, 2, tab);
    		
    		setBounds(14001, 5, 42, 3, tab);
    		
    		Widget list = addTabInterface(14001);
    		int children = c().playerTitle.archived;
    		list.totalChildren(children);
    		int y = 0;
    		for (int id = 14007, index = 0; id < 14007 + children; id++, index++) {
    			addConfigText(id, 165, "", "Apply Title:", text, 0, 0xffffff, false, true, (index == 0 ? 1 : 0), 0xffffff);
    			setBounds(id, 0, y, index, list);
    			y += 14;
    		}
    		list.height = 190;
    		list.width = 165;
    		list.scrollMax = (int) (14.05D * children);
    		
    	}
    This uses the 'minigame' tab in the quest tab for the titles. I would recommend changing the tooltip and getting the button id for later.

    Search "(action == 315)" and add this above
    Code:
    		if(action == OPCODE) {
    			outgoing.writeOpCode(OPCODE);
    			outgoing.writeShort(second);
    			outgoing.writeShort(first);
    			outgoing.writeShort(playerTitle.archived);
    		}
    In "buildInterfaceMenu" add (firstMenuAction = menuActionCmd2 : secondMenuAction = menuActionCmd3)
    Code:
    					if (!flag) {
    						if(childInterface.processAction != 315) {
    							if(childInterface.actions != null) {
    								if ((childInterface.type == 4 && childInterface.defaultText.length() > 0) || childInterface.type == 5) {
    									for(int actionIndex = childInterface.actions.length - 1; actionIndex >= 0; actionIndex--) {
    										String actionName = childInterface.actions[actionIndex];
    										if(actionName != null) {
    											menuActionText[menuActionRow] = actionName + (childInterface.type == 4 ? " " + childInterface.defaultText : "");
    											menuActionTypes[menuActionRow] = childInterface.processAction;
    											secondMenuAction[menuActionRow] = childInterface.id;
    											firstMenuAction[menuActionRow] = actionIndex;
    											menuActionRow++;
    										}
    									}
    								}
    							}
    						} else {
    							menuActionText[menuActionRow] = childInterface.tooltip;
    							menuActionTypes[menuActionRow] = childInterface.processAction;
    							secondMenuAction[menuActionRow] = childInterface.id;
    							menuActionRow++;
    						}
    					}
    Search "updateStrings(String, int)"
    Add this above the switch
    Code:
    		int id = 14007;
    		for(int i = 0, text = id; text <= id + playerTitle.archived; i++, text++) {
    			if(message.equals("")) {
    				sendString((i == 0 ? "Clear" :  playerTitle.placement("Name", playerTitle.get(i))), text);
    			}
    		}
    That should finish with the clients end.

    [SERVER]
    Change the packet size for the new packet we created to 6.
    For example, If I used opcode 220, go to //220 and change the first index in the line to 6.

    Code:
    	/**
    	 * Lengths for the various packets. PACKET_SIZES
    	 */
    	public static final int packetLengths[] = { 
    			0, 0, 0, 1, -1, 0, 0, 0, 0, 0, // 0
    			0, 0, 0, 0, 4, 0, 6, 2, 2, 0, // 10
    			0, 2, 0, 6, 0, 12, 0, 0, 0, 0, // 20
    			0, 0, 0, 0, 0, 8, 4, 0, 0, 2, // 30
    			2, 6, 0, 6, 0, -1, 0, 0, 0, 0, // 40
    			0, 0, 0, 12, 0, 0, 0, 8, 8, 12, // 50
    			8, 8, 0, 0, 0, 0, 0, 0, 0, 0, // 60
    			6, 0, 2, 2, 8, 6, 0, -1, 0, 6, // 70
    			0, 0, 0, 0, 0, 1, 4, 6, 0, 0, // 80
    			0, 0, 0, 0, 0, 3, 0, 0, -1, 0, // 90
    			0, 13, 0, -1, 0, 0, 0, 0, 0, 0, // 100
    			0, 0, 0, 0, 0, 0, 0, 6, 0, 0, // 110
    			1, 0, 6, 0, 0, 0, -1, /* 0 */-1, 2, 6, // 120
    			0, 4, 6, 8, 0, 6, 0, 0, 0, 2, // 130
    			0, 0, 0, 0, 0, 6, 0, 0, 0, 0, // 140
    			0, 0, 1, 2, 0, 2, 6, 0, 0, 0, // 150
    			0, 0, 0, 0, -1, -1, 0, 0, 0, 0, // 160
    			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170
    			0, 8, 0, 3, 0, 2, 0, 0, 8, 1, // 180
    			0, 0, 12, 0, 0, 0, 0, 0, 0, 0, // 190
    			2, 0, 0, 0, 0, 0, 0, 0, 4, 0, // 200
    			4, 0, 0, 4, 7, 8, 0, 0, 10, 0, // 210
    			6, 0, 0, 0, 0, 0, -1, 0, 6, 0, // 220           
    			1, 0, 0, 0, 6, 0, 6, 8, 1, 0, // 230
    			0, 4, 0, 0, 0, 0, -1, 0, -1, 4, // 240
    			0, 0, 6, 6, 0, 0, 0 // 250
    	};
    Code:
    block.writeShort(flags.getTitleId());
    Code:
    titleId = player.titleId;
    In Player add
    Code:
    	public int titleId;
    	
    	public int getTitleId() {
    		return titleId;
    	}
    	
    	public void setTitleId(int id) {
    		titleId = id;
    		this.setAppearanceUpdateRequired(true);
    	}
    	
    	public List<Title> unlocked = new ArrayList<>();
    In your login method, add
    Code:
    TitleManager.loadUnlockedTitles(this);
    In PlayerSave add
    Code:
    		private final List<Title> unlocked;
    		private final int titleId;
    Code:
    			titleId = player.titleId;
    			unlocked = player.unlocked;
    Code:
    				if (details.unlocked != null && !details.unlocked.isEmpty()) {
    					player.unlocked.addAll(details.unlocked);
    				}
    				player.setTitleId(details.titleId);
    In your packet handler class, add
    Code:
    private static final IncomingPacket menuClickPacket = new MenuClickPacket();
    Code:
    packets[OPCODE] = menuClickPacket;
    Create a new packet class (Add your imports and package yourself)
    Code:
    public class MenuClickPacket extends IncomingPacket {
    
    	@Override
    	public int getMaxDuplicates() {
    		return 1;
    	}
    
    	@Override
    	public void handle(Player player, StreamBuffer.InBuffer in, int opcode, int length) {
    		int id = in.readShort();//2
    		@SuppressWarnings("unused")
    		int action = in.readShort();//4 
    		int archived = in.readShort();//6
    		
    		if(TitleManager.checkUnlockParam(player, id, archived))
    			return;
    	
    	}
    }
    Create a new class (Add your imports and package yourself)
    Spoiler for new class:
    Code:
    public class TitleManager {
    	
    	/**
    	 * @author Deku
    	 * @notes: This is a ROUGH base, sorry.
    	 * @param id - titles base id, don't bother touching
    	 * @param unlockId
    	 * 		-special unlock requirement:  	-1
    	 * 		-automatically unlocked: 		id
    	 * @param requirement - set a requirement for unlocking the title
    	 * 
    	 * - If you add a new title in the client, don't forget to register it into the enum.
    	 */
    	public enum Title {
    		//Id, unlockId, requirement
    		TITLE0(0, 0, 0),
    		TITLE1(1, 1, 250_000),
    		TITLE2(2, 2, 300_000),
    		TITLE3(3, 3, 0),
    		TITLE4(4, 4, 0),
    		TITLE5(5, 5, 0),
    		TITLE6(6, 6, 0),
    		TITLE7(7, 7, 0),
    		TITLE8(8, 8, 0),
    		TITLE9(9, 9, 0),
    		TITLE10(10, 10, 0),
    		TITLE11(11, 11, 0),
    		TITLE12(12, 12, 0),
    		TITLE13(13, 13, 0),
    		TITLE14(14, 14, 0),
    		TITLE15(15, 15, 0),
    		TITLE16(16, 15, 0),
    		TITLE17(17, 17, 0),
    		TITLE18(18, 18, 0),
    		TITLE19(19, 19, 0),
    		TITLE20(20, 20, 0),
    		TITLE21(21, 21, 0),
    		TITLE22(22, 22, 0),
    		TITLE23(23, 23, 0),
    		TITLE24(24, 24, 0),
    		TITLE25(25, 25, 0),
    		TITLE26(26, -1, 0),
    		TITLE27(27, -1, 0),
    		TITLE28(28, -1, 0),
    		TITLE29(29, -1, 0),
    		TITLE30(30, -1, 0),
    		TITLE31(31, -1, 0),
    		TITLE32(32, -1, 0),
    		TITLE33(33, -1, 0),
    		TITLE34(34, -1, 0),
    		TITLE35(35, -1, 0),
    		TITLE36(36, -1, 0),
    		TITLE37(37, -1, 0),
    		TITLE38(38, -1, 0),
    		TITLE39(39, -1, 0),
    		TITLE40(40, -1, 0),
    		TITLE41(41, -1, 0),
    		TITLE42(42, -1, 0),
    		TITLE43(43, -1, 0),
    		TITLE44(44, -1, 0),
    		TITLE45(45, -1, 0),
    		TITLE46(46, -1, 0),
    		TITLE47(47, -1, 0),
    		TITLE48(48, -1, 0),
    		TITLE49(49, -1, 0),
    		TITLE50(50, -1, 0),
    		TITLE51(51, -1, 0),
    		TITLE52(52, -1, 0),
    		TITLE53(53, -1, 0),
    		TITLE54(54, -1, 0),
    		TITLE55(55, -1, 0),
    		TITLE56(56, -1, 0),
    		TITLE57(57, -1, 0),
    		TITLE58(58, -1, 0),
    		TITLE59(59, -1, 0),
    		TITLE60(60, -1, 0),
    		TITLE61(61, -1, 0),
    		TITLE62(62, -1, 0),
    		TITLE63(63, -1, 0),
    		TITLE64(64, -1, 0),
    		TITLE65(65, -1, 0),
    		TITLE66(66, -1, 0),
    		TITLE67(67, -1, 0),
    		TITLE68(68, -1, 0),
    		TITLE69(69, -1, 0),
    		TITLE70(70, -1, 0),
    		TITLE71(71, -1, 0),
    		TITLE72(72, -1, 0),
    		TITLE73(73, -1, 0),
    		TITLE74(74, -1, 0),
    		TITLE75(75, -1, 0),
    		TITLE76(76, -1, 0),
    		TITLE77(77, -1, 0),
    		TITLE78(78, -1, 0),
    		TITLE79(79, -1, 0),
    		TITLE80(80, -1, 0),
    		TITLE81(81, -1, 0),
    		TITLE82(82, -1, 0),
    		TITLE83(83, -1, 0),
    		TITLE84(84, -1, 0),
    		TITLE85(85, -1, 0),
    		TITLE86(86, -1, 0),
    		TITLE87(87, -1, 0),
    		TITLE88(88, -1, 0),
    		TITLE89(89, -1, 0),
    		TITLE90(90, -1, 0),
    		TITLE91(91, -1, 0),
    		TITLE92(92, -1, 0),
    		TITLE93(93, -1, 0),
    		TITLE94(94, -1, 0),
    		TITLE95(95, -1, 0),
    		TITLE96(96, -1, 0),
    		TITLE97(97, -1, 0),
    		TITLE98(98, -1, 0),
    		TITLE99(99, -1, 0),
    		TITLE100(100, -1, 0),
    		TITLE101(101, -1, 0),
    		TITLE102(102, -1, 0),
    		TITLE103(103, -1, 0),
    		TITLE104(104, -1, 0),
    		TITLE105(105, -1, 0),
    		TITLE106(106, -1, 0),
    		TITLE107(107, -1, 0),
    		TITLE108(108, -1, 0),
    		TITLE109(109, -1, 0),
    		TITLE110(110, -1, 0),
    		TITLE111(111, -1, 0),
    		TITLE112(112, -1, 0),
    		TITLE113(113, -1, 0),
    		TITLE114(114, -1, 0),
    		TITLE115(115, -1, 0),
    		TITLE116(116, -1, 0),
    		TITLE117(117, -1, 0),
    		TITLE118(118, -1, 0),
    		TITLE119(119, -1, 0),
    		TITLE120(120, -1, 0),
    		TITLE121(121, -1, 0),
    		TITLE122(122, -1, 0),
    		TITLE123(123, -1, 0),
    		TITLE124(124, -1, 0),
    		TITLE125(125, -1, 0),
    		TITLE126(126, -1, 0),
    		TITLE127(127, -1, 0),
    		TITLE128(128, -1, 0),
    		TITLE129(129, -1, 0),
    		TITLE130(130, -1, 0),
    		TITLE131(131, -1, 0),
    		TITLE132(132, -1, 0),
    		TITLE133(133, -1, 0),
    		TITLE134(134, -1, 0),
    		TITLE135(135, -1, 0),
    		TITLE136(136, -1, 0),
    		TITLE137(137, -1, 0),
    		TITLE138(138, -1, 0),
    		TITLE139(139, -1, 0),
    		TITLE140(140, -1, 0),
    		TITLE141(141, -1, 0),
    		TITLE142(142, -1, 0),
    		TITLE143(143, -1, 0),
    		TITLE144(144, -1, 0),
    		TITLE145(145, -1, 0),
    		TITLE146(146, -1, 0),
    		TITLE147(147, -1, 0),
    		TITLE148(148, -1, 0),
    		TITLE149(149, -1, 0),
    		TITLE150(150, -1, 0),
    		TITLE151(151, -1, 0),
    		TITLE152(152, -1, 0),
    		TITLE153(153, -1, 0),
    		TITLE154(154, -1, 0),
    		TITLE155(155, -1, 0),
    		TITLE156(156, -1, 0),
    		TITLE157(157, -1, 0),
    		TITLE158(158, -1, 0),
    		TITLE159(159, -1, 0),
    		TITLE160(160, -1, 0),
    		TITLE161(161, -1, 0),
    		TITLE162(162, -1, 0),
    		TITLE163(163, -1, 0),
    		TITLE164(164, -1, 0),
    		TITLE165(165, -1, 0),
    		TITLE166(166, -1, 0),
    		TITLE167(167, -1, 0),
    		TITLE168(168, -1, 0),
    		TITLE169(169, -1, 0),
    		TITLE170(170, -1, 0),
    		TITLE171(171, -1, 0),
    		TITLE172(172, -1, 0),
    		TITLE173(173, -1, 0),
    		TITLE174(174, -1, 0),
    		TITLE175(175, -1, 0),
    		TITLE176(176, -1, 0),
    		TITLE177(177, -1, 0),
    		TITLE178(178, -1, 0),
    		TITLE179(179, -1, 0),
    		TITLE180(180, -1, 0),
    		TITLE181(181, -1, 0),
    		TITLE182(182, -1, 0),
    		TITLE183(183, -1, 0),
    		TITLE184(184, -1, 0),
    		TITLE185(185, -1, 0),
    		TITLE186(186, -1, 0),
    		TITLE187(187, -1, 0),
    		TITLE188(188, -1, 0),
    		TITLE189(189, -1, 0),
    		TITLE190(190, -1, 0),
    		TITLE191(191, -1, 0),
    		TITLE192(192, -1, 0),
    		TITLE193(193, -1, 0),
    		TITLE194(194, -1, 0),
    		TITLE195(195, -1, 0),
    		TITLE196(196, -1, 0),
    		TITLE197(197, -1, 0),
    		TITLE198(198, -1, 0),
    		TITLE199(199, -1, 0),
    		TITLE200(200, -1, 0),
    		TITLE201(201, -1, 0),
    		TITLE202(202, -1, 0),
    		TITLE203(203, -1, 0),
    		TITLE204(204, -1, 0),
    		TITLE205(205, -1, 0),
    		TITLE206(206, -1, 0),
    		TITLE207(207, -1, 0),
    		TITLE208(208, -1, 0),
    		TITLE209(209, -1, 0),
    		TITLE210(210, -1, 0),
    		TITLE211(211, -1, 0),
    		TITLE212(212, -1, 0),
    		TITLE213(213, -1, 0),
    		TITLE214(214, -1, 0),
    		TITLE215(215, -1, 0),
    		TITLE216(216, -1, 0),
    		TITLE217(217, -1, 0),
    		TITLE218(218, -1, 0),
    		TITLE219(219, -1, 0),
    		TITLE220(220, -1, 0),
    		TITLE221(221, -1, 0),
    		TITLE222(222, -1, 0),
    		TITLE223(223, -1, 0),
    		TITLE224(224, -1, 0),
    		TITLE225(225, -1, 0),
    		TITLE226(226, -1, 0),
    		TITLE227(227, -1, 0),
    		TITLE228(228, -1, 0),
    		TITLE229(229, -1, 0),
    		TITLE230(230, -1, 0),
    		TITLE231(231, -1, 0),
    		TITLE232(232, -1, 0),
    		TITLE233(233, -1, 0),
    		TITLE234(234, -1, 0),
    		TITLE235(235, -1, 0),
    		TITLE236(236, -1, 0),
    		TITLE237(237, -1, 0),
    		TITLE238(238, -1, 0),
    		TITLE239(239, -1, 0),
    		TITLE240(240, -1, 0),
    		TITLE241(241, -1, 0),
    		TITLE242(242, -1, 0),
    		TITLE243(243, -1, 0),
    		TITLE244(244, -1, 0),
    		TITLE245(245, -1, 0),
    		TITLE246(246, -1, 0),
    		TITLE247(247, -1, 0),
    		TITLE248(248, -1, 0),
    		TITLE249(249, -1, 0),
    		TITLE250(250, -1, 0),
    		TITLE251(251, -1, 0),
    		TITLE252(252, -1, 0),
    		TITLE253(253, -1, 0),
    		TITLE254(254, -1, 0),
    		TITLE255(255, -1, 0),
    		TITLE256(256, -1, 0),
    		TITLE257(257, -1, 0),
    		TITLE258(258, -1, 0),
    		TITLE259(259, -1, 0),
    		TITLE260(260, -1, 0),
    		TITLE261(261, -1, 0),
    		TITLE262(262, -1, 0),
    		TITLE263(263, -1, 0),
    		TITLE264(264, -1, 0),
    		TITLE265(265, -1, 0),
    		TITLE266(266, -1, 0),
    		TITLE267(267, -1, 0),
    		TITLE268(268, -1, 0),
    		TITLE269(269, -1, 0),
    		TITLE270(270, -1, 0),
    		TITLE271(271, -1, 0),
    		TITLE272(272, -1, 0),
    		TITLE273(273, -1, 0),
    		TITLE274(274, -1, 0),
    		TITLE275(275, -1, 0),
    		TITLE276(276, -1, 0),
    		TITLE277(277, -1, 0),
    		TITLE278(278, -1, 0),
    		TITLE279(279, -1, 0),
    		TITLE280(280, -1, 0),
    		TITLE281(281, -1, 0),
    		TITLE282(282, -1, 0),
    		TITLE283(283, -1, 0),
    		TITLE284(284, -1, 0),
    		TITLE285(285, -1, 0),
    		TITLE286(286, -1, 0),
    		TITLE287(287, -1, 0),
    		TITLE288(288, -1, 0),
    		TITLE289(289, -1, 0),
    		TITLE290(290, -1, 0),
    		TITLE291(291, -1, 0),
    		TITLE292(292, -1, 0),
    		TITLE293(293, -1, 0),
    		TITLE294(294, -1, 0),
    		TITLE295(295, -1, 0),
    		TITLE296(296, -1, 0),
    		TITLE297(297, -1, 0),
    		TITLE298(298, -1, 0),
    		TITLE299(299, -1, 0),
    		TITLE300(300, -1, 0),
    		TITLE301(301, -1, 0),
    		TITLE302(302, -1, 0),
    		TITLE303(303, -1, 0),
    		TITLE304(304, -1, 0),
    		TITLE305(305, -1, 0),
    		TITLE306(306, -1, 0),
    		TITLE307(307, -1, 0),
    		TITLE308(308, -1, 0),
    		TITLE309(309, -1, 0),
    		TITLE310(310, -1, 0),
    		TITLE311(311, -1, 0),
    		TITLE312(312, -1, 0),
    		TITLE313(313, -1, 0),
    		TITLE314(314, -1, 0),
    		TITLE315(315, -1, 0),
    		TITLE316(316, -1, 0),
    		TITLE317(317, -1, 0),
    		TITLE318(318, -1, 0),
    		TITLE319(319, -1, 0),
    		TITLE320(320, -1, 0),
    		TITLE321(321, -1, 0),
    		TITLE322(322, -1, 0),
    		TITLE323(323, -1, 0),
    		TITLE324(324, -1, 0);
    		
    		public int id;
    		public int unlockId;
    		public Object requirement;
    		
    		public static Title forId(int id) {
    			for(Title title : Title.values()) {
    				if(title.getTitleId() == id) {
    					return title;
    				}
    			}
    			return null;
    		}
    		
    		Title(int id, int unlockId, Object requirement) {
    			this.id = id;
    			this.unlockId = unlockId;
    			this.requirement = requirement;
    		}
    		
    		public int getTitleId() {
    			return id;
    		}
    		
    		public int getUnlockId() {
    			return unlockId;
    		}
    		
    		public Object getRequirement() {
    			return requirement;
    		}
    		
    	}
    	
    	/**
    	 * 
    	 * @param player - player instance
    	 * @param title - title enum
    	 */
    	public static void unlockTitle(final Player player, final Title title) {
    		if(title != null) {
    			if(player.unlocked.contains(title))
    				return;
    			
    			player.unlocked.add(title);
    			player.getClient().queueOutgoingPacket(new SendMessage("You have earned a special title!"));
    		}
    	}
    	
    	/**
    	 * Check if the title is unlocked by default or earned.
    	 * @param player - player instance
    	 */
    	public static void loadUnlockedTitles(final Player player) {
    		for(int i = Title.TITLE0.ordinal(); i < Title.TITLE324.ordinal() + 1; i++) {
    			Title title = Title.values()[i];
    			if(title != null) {
    				if(title.getUnlockId() == -1) 
    					return;
    				
    				if(title.getUnlockId() == i) {
    					if(player.unlocked.contains(title))
    						return;
    					
    					player.unlocked.add(title);
    				}
    			}
    		}
    	}
    
    	/**
    	 * Check special arguments for unlocking and setting a title.
    	 * @param player - player instance
    	 * @param id - action id in the interface, used to get the index of the title id
    	 * @param archived - total amount of titles loaded from the client
    	 * @return if the parameters have met the arguments unlock the title
    	 */
    	public static boolean checkUnlockParam(final Player player, int id, int archived) {
    		Title title = Title.forId(id - 14007);
    		if(title == null)
    			return false;
    		
    		if(!player.unlocked.contains(title)) {
    			if (GameSettings.DEV_MODE) {
    				System.out.println("title clicked: " + title);
    				System.out.println("list: " + player.unlocked);
    			}
    			/** 
    			 * Add requirement objects here 
    			 * */
    			if (!player.getInventory().hasItemAmount(995, Integer.parseInt(String.valueOf(title.getRequirement())))) {
    				player.getClient().queueOutgoingPacket(new SendMessage("<col=128>You don't have enough coins to unlock this title."));
    				return true;
    			}
    			
    			/** 
    			 * Set the title 
    			 * */
    			if(player.getTitleId() != id) {
    				player.getInventory().remove(995, Integer.parseInt(String.valueOf(title.getRequirement())));
    				player.getClient().queueOutgoingPacket(new SendMessage("<col=128>You have unlocked this title."));
    			}
    			
    			/** 
    			 * Add to the list.
    			 * TODO: save 'unlocked' to the player file
    			 *  */
    			if(player.unlocked.contains(title))
    				return false;
    			
    			player.unlocked.add(title);
    			return true;
    		} else {
    			if(player.getTitleId() == title.getTitleId()) {
    				player.getClient().queueOutgoingPacket(new SendMessage("<col=ff0000>You are already using this title!"));
    				return true;
    			} else {
    				if(player.getTitleId() != id) {
    					if (!player.getInventory().hasItemAmount(995, Integer.parseInt(String.valueOf(title.getRequirement())))) {
    						player.getClient().queueOutgoingPacket(new SendMessage("<col=128>You don't have enough coins to apply this title."));
    						return true;
    					}
    					player.setTitleId(id - 14007);
    					player.getInventory().remove(995, Integer.parseInt(String.valueOf(title.getRequirement())));
    					return true;
    				}
    			}
    			return true;
    		}
    	
    	}
    	
    }
    wut
    Reply With Quote  
     

  2. #2  
    Vratha Something Different

    Canada's Avatar
    Join Date
    Apr 2016
    Posts
    348
    Thanks given
    36
    Thanks received
    65
    Rep Power
    91
    Great contribution to the community. Looks pretty well sorted out.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    151
    Thanks given
    37
    Thanks received
    121
    Rep Power
    165
    Quote Originally Posted by Rabbit_ View Post
    Great contribution to the community. Looks pretty well sorted out.
    Thanks, for a little more flexibility you can add effects as well to the prefix (that extend to your player name)
    (underline, bold, strikethrough, etc)



    Code:
    	public String tag(String tag) {
    		if(title.contains("<" + tag) && !title.contains("</"+ tag))
    			return ("</" + tag + ">");
    		
    		return "";
    	}
    	
    	public String placement(String name, String title) {
    		if(name != null || title != null) {
    			if(suffix && format(title) == " @") 
    				name += "" + title;
    			else
    			if(suffix && format(title) == " #")
    				name += " " + title;
    			else {
    				String character = name;
    				name = title + (format(title) == " $" ? " " : "") + character + tag("str");
    			}
    			return name;
    		}
    		return "[DEBUGplacement]";
    	}
    Code:
    Definetly not<str=FFFFFF># null# <col=BA061F>#
    wut
    Reply With Quote  
     

  4. #4  
    Extreme Donator Market Banned Market Banned



    Join Date
    Aug 2011
    Age
    25
    Posts
    3,596
    Thanks given
    1,403
    Thanks received
    1,619
    Rep Power
    5000
    Thanks for sharing this

    [Only registered and activated users can see links. ]

    Discord: Roy#2382

    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    May 2016
    Posts
    35
    Thanks given
    9
    Thanks received
    2
    Rep Power
    11
    instead of sending an identifier, why not send a 64-bit hash value (a long) so you can dynamically set the title to any string you want?
    Reply With Quote  
     

  6. #6  
    The Meme God

    4DFo's Avatar
    Join Date
    Dec 2013
    Age
    23
    Posts
    618
    Thanks given
    54
    Thanks received
    81
    Rep Power
    185
    Quote Originally Posted by Deku View Post
    Thanks, for a little more flexibility you can add effects as well to the prefix (that extend to your player name)
    (underline, bold, strikethrough, etc)



    Code:
    	public String tag(String tag) {
    		if(title.contains("<" + tag) && !title.contains("</"+ tag))
    			return ("</" + tag + ">");
    		
    		return "";
    	}
    	
    	public String placement(String name, String title) {
    		if(name != null || title != null) {
    			if(suffix && format(title) == " @") 
    				name += "" + title;
    			else
    			if(suffix && format(title) == " #")
    				name += " " + title;
    			else {
    				String character = name;
    				name = title + (format(title) == " $" ? " " : "") + character + tag("str");
    			}
    			return name;
    		}
    		return "[DEBUGplacement]";
    	}
    Code:
    Definetly not<str=FFFFFF># null# <col=BA061F>#
    Ill contribution mate. Love it!



    Rest easy, [Only registered and activated users can see links. ]. Suicide is never the answer.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    151
    Thanks given
    37
    Thanks received
    121
    Rep Power
    165
    Quote Originally Posted by _cream_ View Post
    instead of sending an identifier, why not send a 64-bit hash value (a long) so you can dynamically set the title to any string you want?
    You can if that's how you want it done, I just figured I'd try and get the formatting and loading done via the clients end. Guess it's just which preference you have.

    Quote Originally Posted by 44.. View Post
    Ill contribution mate. Love it!
    Thanks, hopefully it may help someone
    wut
    Reply With Quote  
     

  8. #8  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    151
    Thanks given
    37
    Thanks received
    121
    Rep Power
    165
    Made a few adjustments, and updated the thread.
    -Added a new interface that stores the title names, below is a preview
    -Interface is interactive and supported in the server portion
    -Added better server support (includes unlocking, setting, and saving titles)
    -Cleaned a few problems that existed

    Should be flawless as far as I know

    Rough draft,
    wut
    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Nov 2013
    Age
    21
    Posts
    767
    Thanks given
    286
    Thanks received
    264
    Rep Power
    0
    Quote Originally Posted by Deku View Post
    Made a few adjustments, and updated the thread.
    -Added a new interface that stores the title names, below is a preview
    -Interface is interactive and supported in the server portion
    -Added better server support (includes unlocking, setting, and saving titles)
    -Cleaned a few problems that existed

    Should be flawless as far as I know

    Rough draft,
    You could create an interface almost like OS-PvP for titles. Regardless, it looks pretty nice. Thanks for this.
    Reply With Quote  
     

  10. #10  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    151
    Thanks given
    37
    Thanks received
    121
    Rep Power
    165
    Quote Originally Posted by Setup View Post
    You could create an interface almost like OS-PvP for titles. Regardless, it looks pretty nice. Thanks for this.
    Thanks, I don't know what that interface looks like, so for reference I can't haha.
    But I'm cleaning the interface class in my client and then I'll probably redesign the interface.
    Probably going to also add searching and setting a custom title, since I hate doing things half-assed.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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. Replies: 13
    Last Post: 12-29-2011, 10:09 PM
  2. Replies: 11
    Last Post: 02-27-2010, 05:44 PM
  3. Replies: 18
    Last Post: 03-19-2008, 12:43 PM
  4. Custom Player Title's
    By Dune in forum Tutorials
    Replies: 43
    Last Post: 09-03-2007, 11:34 AM
  5. Custom player titles
    By Lothy in forum Tutorials
    Replies: 9
    Last Post: 06-16-2007, 03:33 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •