Thread: [718] Custom Armor Saving

Results 1 to 10 of 10
  1. #1 [718] Custom Armor Saving 
    Registered Member
    Join Date
    Apr 2013
    Posts
    47
    Thanks given
    4
    Thanks received
    3
    Rep Power
    13
    The first thing we need to do is open our player.java and insert this into it.
    This chunk of code saves the ids of the items that we want to save for the player, and also allows us to call the ids.
    Code:
    	int HelmID;
    	int AuraID;
    	int CapeID;
    	int neckID;
    	int ammoID;
    	int SwordID;
    	int shieldID;
    	int chestID;
    	int legsID;
    	int glovesID;
    	int bootsID;
    	int ringID;
    	public int getHelm(){
    		return HelmID;
    	}
    	public void setHelm(int HelmID){
    		this.HelmID = HelmID;
    	}
    	public int getAura(){
    		return AuraID;
    	}
    	public void setAura(int AuraID){
    		this.AuraID = AuraID;
    	}
    	public int getCape(){
    		return CapeID;
    	}
    	public void setCape(int CapeID){
    		this.CapeID = CapeID;
    	}
    	public int getNeck(){
    		return neckID;
    	}
    	public void setNeck(int neckID){
    		this.neckID = neckID;
    	}
    	public int getAmmo(){
    		return ammoID;
    	}
    	public void setAmmo(int ammoID){
    		this.ammoID = ammoID;
    	}
    	public int getSword(){
    		return SwordID;
    	}
    	public void setSword(int SwordID){
    		this.SwordID = SwordID;
    	}
    	public int getShield(){
    		return shieldID;
    	}
    	public void setShield(int shieldID){
    		this.shieldID = shieldID;
    	}
    	public int getChest(){
    		return chestID;
    	}
    	public void setChest(int chestID){
    		this.chestID = chestID;
    	}
    	public int getLegs(){
    		return legsID;
    	}
    	public void setLegs(int legsID){
    		this.legsID = legsID;
    	}
    	public int getGloves(){
    		return glovesID;
    	}
    	public void setGloves(int glovesID){
    		this.glovesID = glovesID;
    	}
    	public int getBoots(){
    		return bootsID;
    	}
    	public void setBoots(int bootsID){
    		this.bootsID = bootsID;
    	}
    	public int getRing(){
    		return ringID;
    	}
    	public void setRing(int ringID){
    		this.ringID = ringID;
    	}

    The Next thing we are doing is adding two commands to save the current items, and equip the items to the player.
    The first command saves all the item ids that the player is wearing, and saves it to the ids we already made it player.java
    The second command grabs the ids that we saved, and equips them to the player, then refreshes the players items and appearance.
    You save this in commands.java

    Code:
    	if (cmd[0].equalsIgnoreCase("savearmor")) {
    		if(player.getEquipment().wearingArmour()){
    				player.getAppearence().generateAppearenceData();
    				player.setHelm(player.getEquipment().getHatId());
    				//player.setAura(player.getEquipment().getAuraId());
    				player.setCape(player.getEquipment().getCapeId());
    				player.setNeck(player.getEquipment().getAmuletId());
    				//player.setAmmo(player.getEquipment().getAmmoId());
    				player.setSword(player.getEquipment().getWeaponId());
    				player.setShield(player.getEquipment().getShieldId());
    				player.setChest(player.getEquipment().getChestId());
    				player.setLegs(player.getEquipment().getLegsId());
    				player.setGloves(player.getEquipment().getGlovesId());
    				player.setBoots(player.getEquipment().getBootsId());
    				player.setRing(player.getEquipment().getRingId());
    				player.sendMessage("You have saved your armor.");
    				return true;
    		} else {
    			player.getPackets().sendGameMessage("You need to be wearing some armor to save.");
    		}
    		
    	}
    
    	if (cmd[0].equalsIgnoreCase("setarmor")) {
    		if(!player.getEquipment().wearingArmour()){
    				player.getEquipment().getItems().set(Equipment.SLOT_HAT, new Item(player.getHelm(), 1));
    				//player.getEquipment().getItems().set(Equipment.SLOT_AURA, new Item(player.getAura(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_CAPE, new Item(player.getCape(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_AMULET, new Item(player.getNeck(), 1));
    				//player.getEquipment().getItems().set(Equipment.SLOT_ARROWS, new Item(player.getAmmo(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_WEAPON, new Item(player.getSword(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_SHIELD, new Item(player.getShield(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_CHEST, new Item(player.getChest(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_LEGS, new Item(player.getLegs(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_HANDS, new Item(player.getGloves(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_FEET, new Item(player.getBoots(), 1));
    				player.getEquipment().getItems().set(Equipment.SLOT_RING, new Item(player.getRing(), 1));
    				for(int i = 0; i < 15; i++){
    					player.getEquipment().refresh(i);
    				}
    				player.getAppearence().generateAppearenceData();
    				player.getPackets().sendGameMessage("Spawned your custom set!");
    				return true;
    		} else {
    			player.getPackets().sendGameMessage("You need to remove your armor to set it");
    			return false;
    		}
    	}
    If you want to add exceptions to what players can and cannot save, you have to check what the player is trying to save.
    You would need to check this before you set each of the items, you can check it with any sort of item list you have, from donator items, to shop items.

    Code:
       for(int item : unspawnables) {
    	if(player.getEquipment().getHatId() == item) {
    		player.sendMessage("You can't save this hat.");
    		return false;
    	}
       }
    I used the interface 549 for mine, to make it more user friendly.
    The first part of the code, is the buttons on the interface, the second part checks, then saves the armor on the player.
    You save this in ButtonHandler.java

    Code:
    		else if (interfaceId == 549) {
    			player.stopAll();
    			WorldTile destTile = null;
    			setarmor(player);
    			player.closeInterfaces();
    			if(componentId == 31) {
    			player.closeInterfaces();
    			}
    			else if(componentId == 33) {
    			setarmor(player);
    			player.closeInterfaces();
    			}
    			if(componentId == 35) {
    			}
    			player.stopAll();
    			setarmor(player);
    			WorldTile destTile = null;
    			} else {
    			player.getPackets().sendGameMessage("CI: " + componentId);
    			}
    		}
    
    public static void setarmor(Player player) {
    			int itemId = player.getEquipment().getHatId();
    			int itemId1 = player.getEquipment().getCapeId();
    			int itemId2 = player.getEquipment().getAmuletId();
    			int itemId3 = player.getEquipment().getWeaponId();
    			int itemId4 = player.getEquipment().getShieldId();
    			int itemId5 = player.getEquipment().getChestId();
    			int itemId6 = player.getEquipment().getLegsId();
    			int itemId7 = player.getEquipment().getGlovesId();
    			int itemId8 = player.getEquipment().getBootsId();
    			int itemId9 = player.getEquipment().getRingId();
    												
    		if(player.getEquipment().wearingArmour()){
    			ItemDefinitions def = ItemDefinitions.getItemDefinitions(itemId);
    			ItemDefinitions def1 = ItemDefinitions.getItemDefinitions(itemId1);
    			ItemDefinitions def2 = ItemDefinitions.getItemDefinitions(itemId2);
    			ItemDefinitions def3 = ItemDefinitions.getItemDefinitions(itemId3);
    			ItemDefinitions def4 = ItemDefinitions.getItemDefinitions(itemId4);
    			ItemDefinitions def5 = ItemDefinitions.getItemDefinitions(itemId5);
    			ItemDefinitions def6 = ItemDefinitions.getItemDefinitions(itemId6);
    			ItemDefinitions def7 = ItemDefinitions.getItemDefinitions(itemId7);
    			ItemDefinitions def8 = ItemDefinitions.getItemDefinitions(itemId8);
    			ItemDefinitions def9 = ItemDefinitions.getItemDefinitions(itemId9);
    						for(String itemName : Commands.unspawnablesNames) { //Hat Check
    							 if(def.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save this helmet.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Cape Check
    							 if(def1.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save this cape.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Amulet Check
    							 if(def2.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save this amulet.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Wep Check
    							 if(def3.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save this weapon.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Shield Check
    							 if(def4.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save this shield.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Chest Check
    							 if(def5.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save this chest.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Legs Check
    							 if(def6.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save these legs.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Gloves Check
    							 if(def7.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save these gloves.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Boots Check
    							 if(def8.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save these boots.");
    								return;
    							 }
    						}
    						for(String itemName : Commands.unspawnablesNames) { //Ring Check
    							 if(def9.getName().toLowerCase().contains(itemName)) {
    								player.sendMessage("You can't save this ring.");
    								return;
    							 }
    						}
    				player.getAppearence().generateAppearenceData();
    				player.setHelm(player.getEquipment().getHatId());
    				//player.setAura(player.getEquipment().getAuraId());
    				player.setCape(player.getEquipment().getCapeId());
    				player.setNeck(player.getEquipment().getAmuletId());
    				//player.setAmmo(player.getEquipment().getAmmoId());
    				player.setSword(player.getEquipment().getWeaponId());
    				player.setShield(player.getEquipment().getShieldId());
    				player.setChest(player.getEquipment().getChestId());
    				player.setLegs(player.getEquipment().getLegsId());
    				player.setGloves(player.getEquipment().getGlovesId());
    				player.setBoots(player.getEquipment().getBootsId());
    				player.setRing(player.getEquipment().getRingId());
    				player.getPackets().sendGameMessage("You have just saved your armour.");	
    				return;
    		} else {
    			player.getPackets().sendGameMessage("You need to be wearing some armour to save.");
    			return;
    		}
    	}


    The way I set the armor for the player was when i used the interface was using a dialogue with the rest of my quick spawns
    This would go in a dialogue that you already have, if you need help making one, let me know.

    Code:
    if(componentId == OPTION_4) {//Cust
    				if (!player.canSpawn()) {
    					player.getPackets().sendGameMessage("You can't be in the wilderness to spawn sets");
    					end();
    				} else {
    		if(!player.getEquipment().wearingArmour()){
    			if(player.getHelm() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_HAT, new Item(player.getHelm(), 1));
    				//player.getEquipment().getItems().set(Equipment.SLOT_AURA, new Item(player.getAura(), 1));
    			if(player.getCape() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_CAPE, new Item(player.getCape(), 1));
    			if(player.getNeck() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_AMULET, new Item(player.getNeck(), 1));
    				//player.getEquipment().getItems().set(Equipment.SLOT_ARROWS, new Item(player.getAmmo(), 1));
    			if(player.getSword() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_WEAPON, new Item(player.getSword(), 1));
    			if(player.getShield() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_SHIELD, new Item(player.getShield(), 1));
    			if((player.getChest() != -1))
    				player.getEquipment().getItems().set(Equipment.SLOT_CHEST, new Item(player.getChest(), 1));
    			if(player.getLegs() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_LEGS, new Item(player.getLegs(), 1));
    			if(player.getGloves() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_HANDS, new Item(player.getGloves(), 1));
    			if(player.getBoots() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_FEET, new Item(player.getBoots(), 1));
    			if(player.getRing() != -1)
    				player.getEquipment().getItems().set(Equipment.SLOT_RING, new Item(player.getRing(), 1));
    			if(player.getHelm() != -1){
    				player.getEquipment().refresh(0);
    			}
    			if(player.getCape() != -1){
    				player.getEquipment().refresh(1);
    			}
    			if(player.getNeck() != -1){
    				player.getEquipment().refresh(2);
    			}
    			if(player.getSword() != -1){
    				player.getEquipment().refresh(3);
    			}
    			if(player.getChest() != -1){
    				player.getEquipment().refresh(4);
    			}
    			if(player.getShield() != -1){
    				player.getEquipment().refresh(5);
    			}
    			if(player.getLegs() != -1){
    				player.getEquipment().refresh(7);
    			}
    			if(player.getGloves() != -1){
    				player.getEquipment().refresh(9);
    			}
    			if(player.getBoots() != -1){
    				player.getEquipment().refresh(10);
    			}
    			if(player.getRing() != -1){
    				player.getEquipment().refresh(12);
    			}
    				player.getAppearence().generateAppearenceData();
    				player.getPackets().sendGameMessage("Spawned your custom set!");
    				end();
    		} else {
    			player.getPackets().sendGameMessage("You need to remove your armour to spawn it");
    			end();
    		}
    		   end();
    		   }
    		}
    Thanks for reading.
    if i missed anything, let me know.
    I know the code is not the most efficient or pretty, it works, and that's what matters, right?
    Reply With Quote  
     

  2. #2  
    Donator
    Esper's Avatar
    Join Date
    Jun 2011
    Age
    30
    Posts
    108
    Thanks given
    13
    Thanks received
    6
    Rep Power
    1
    had this already but thanks i know a few people still needing this
    Reply With Quote  
     

  3. #3  
    Registered Member
    OblivionRSPS's Avatar
    Join Date
    Feb 2015
    Posts
    831
    Thanks given
    231
    Thanks received
    98
    Rep Power
    87
    Thanks for this.
    Reply With Quote  
     

  4. #4  
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    33
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,062
    Rep Power
    750
    Code:
    	private int[] quickSet;
    
    	public int getQuickSlot(int slot) {
    	     return quickSet[slot];
    	}
    
    	public void setQuickSlot(int id, int slot) {
    	     this.quickSet[slot] = id;
    	}
    
    	public boolean spawnSet() {
    		if (!player.canSpawn()) {
    			player.getPackets().sendGameMessage("You can't be in the wilderness to spawn sets");
    			return false;
    		}
    		
    		if(!player.getEquipment().wearingArmour()) {
    			player.getPackets().sendGameMessage("Please remove your current armour.");
    			return false;
    		}
    		
    		for (int i = 0; i < 15; i++) {
    			if (player.getQuickSlot(i) == -1) {
    				continue;
    			}
    			player.getEquipment().getItems().set(i, new Item(player.getQuickSlot(i), 1));
    			player.getEquipment().refresh(i);
    		}
    		
    		player.getAppearence().generateAppearenceData();
    		player.getPackets().sendGameMessage("Spawned your custom set!");
    	}
    for anyone thats a neatfreak >..>

    using this example u can expand it to an multi-dimensional array and have multiple sets ;D

    Attached image
    Reply With Quote  
     

  5. #5  
    48 0x69

    Pax M's Avatar
    Join Date
    Oct 2013
    Posts
    2,008
    Thanks given
    36
    Thanks received
    488
    Rep Power
    2270
    Already had this, but gj I guess.
    Reply With Quote  
     

  6. #6  
    What?

    Luminous's Avatar
    Join Date
    Apr 2015
    Posts
    489
    Thanks given
    231
    Thanks received
    341
    Rep Power
    179
    Won't be using but good release either way
    Reply With Quote  
     

  7. #7  
    Donator


    Join Date
    Jul 2013
    Posts
    1,233
    Thanks given
    1
    Thanks received
    493
    Rep Power
    0
    Only thing i like from this is that interface.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Jun 2015
    Posts
    7
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    make a tut for PI haha
    Reply With Quote  
     

  9. #9  
    Banned
    Join Date
    Jul 2012
    Age
    27
    Posts
    996
    Thanks given
    646
    Thanks received
    266
    Rep Power
    0
    I like how you're making use of the Photo Booth interface; I never thought of that! Good idea
    Reply With Quote  
     

  10. #10  
    Sexy User
    User's Avatar
    Join Date
    Apr 2013
    Posts
    601
    Thanks given
    97
    Thanks received
    218
    Rep Power
    346
    https://docs.oracle.com/javase/tutor...ts/arrays.html

    My version of this uses an array for the object items inventory and equipment then a string array for the name, and byte for skills/boolean for using curses or not.

    I guess you provided the fundamentals of the system to people but it can be majorly improved m8.
    Attached image
    Reply With Quote  
     


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. RuneNova 718 - Customized Shops
    By Peril in forum Show-off
    Replies: 10
    Last Post: 08-04-2012, 04:58 AM
  2. Replies: 2
    Last Post: 02-05-2010, 11:13 PM
  3. Replies: 3
    Last Post: 12-03-2009, 12:21 AM
  4. Replies: 0
    Last Post: 11-29-2009, 11:51 PM
  5. Replies: 44
    Last Post: 07-13-2009, 10:56 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •