gainCloseness()

Status
Not open for further replies.
Joined
Nov 30, 2007
Messages
511
Reaction score
0
.-.

Yeah. gainCloseness() adds to a pet's closeness. It's used for NPC scripts. :|

In NPCConversationManager.java:
PHP:
	public void gainCloseness(int closeness) {
		if (pet.getCloseness() < 30000 || pet.getLevel() < 30) {
			if ((pet.getCloseness() + closeness) > 30000) {
				pet.setCloseness(30000);
			} else {
				pet.setCloseness(pet.getCloseness() + closeness);
			}
			while (pet.getCloseness() > ExpTable.getClosenessNeededForLevel(pet.getLevel()+1)) {
				pet.setLevel(pet.getLevel()+1);
				getClient().getSession().write(MaplePacketCreator.showPetLevelUp());
			}
			getPlayer().getClient().getSession().write(MaplePacketCreator.updatePet(pet.getPosition(), pet.getItemId(), pet.getUniqueId(), pet.getName(), pet.getLevel(), pet.getCloseness(), pet.getFullness(), true));
                }
        }

Add to your imports:
Code:
import net.sf.odinms.client.MaplePet;

Example of usage:
Code:
cm.gainCloseness(5);

Huge thanks to Leifde for bringing pets to OdinMS!

PHP:
        public void gainCloseness(int closeness) {
            MaplePet pet = getPlayer().getPet();
            if (pet.getCloseness() < 30000 || pet.getLevel() < 30) {
                    pet.setCloseness(pet.getCloseness() + closeness);
                } else {
                     pet.setCloseness(pet.getCloseness() + 0);
                }
        }

A few more commands to satisfy your inner lazy:
PHP:
        public int getPetLevel() {
            return pet.getLevel();
        }
        
        public int getFullness() {
            return pet.getFullness();
        }
        
        public String getPetName() {
            return pet.getName();
        }
        
        public void setPetName(String petname) {
            pet.setName(petname);
        }

In NPCConversationManager.java, find:
PHP:
public class NPCConversationManager extends AbstractPlayerInteraction {
	private int npc;
	private String getText;

Underneath it place:
Code:
private MaplePet pet = getPlayer().getPet();

Find:
PHP:
        public void gainCloseness(int closeness) {
            MaplePet pet = getPlayer().getPet();
            if (pet.getCloseness() < 30000 || pet.getLevel() < 30) {
                    pet.setCloseness(pet.getCloseness() + closeness);
                } else {
                     pet.setCloseness(pet.getCloseness() + 0);
                }
        }

Replace it with:
PHP:
	public void gainCloseness(int closeness) {
		if (pet.getCloseness() < 30000 || pet.getLevel() < 30) {
			if ((pet.getCloseness() + closeness) > 30000) {
				pet.setCloseness(30000);
			} else {
				pet.setCloseness(pet.getCloseness() + closeness);
			}
			while (pet.getCloseness() > ExpTable.getClosenessNeededForLevel(pet.getLevel()+1)) {
				pet.setLevel(pet.getLevel()+1);
				getClient().getSession().write(MaplePacketCreator.showPetLevelUp());
			}
			getPlayer().getClient().getSession().write(MaplePacketCreator.updatePet(pet.getPosition(), pet.getItemId(), pet.getUniqueId(), pet.getName(), pet.getLevel(), pet.getCloseness(), pet.getFullness(), true));
                }
        }

Thanks RMZero213 for fixing the previous nub function.
Thanks Leifde(<3) for adding in level up checking.
 
Last edited:
Re: [Release] gainCloseness()

I would also recomend adding a getPet(), so you can check if there is a pet or not before trying to add closeness.

Also recomened to add a check on the pets level so that it doesnt go over 30 and wrap to a negative.
(I dunno if it would go over 30 with commands, but pet food took my pet to 31, and then the closeness went negative.)
 
Re: [Release] gainCloseness()

I would also recomend adding a getPet(), so you can check if there is a pet or not before trying to add closeness.

Also recomened to add a check on the pets level so that it doesnt go over 30 and wrap to a negative.
(I dunno if it would go over 30 with commands, but pet food took my pet to 31, and then the closeness went negative.)
Thanks, I'll do that now.
 
Re: [Release] gainCloseness()

great release :D!

what happeng whit my ideas...? :/
 
Re: [Release] gainCloseness()

Updated the command. It now checks if the pet's closeness is less than 30,000 and if its level is less than 30. If its closeness is higher than 30,000 or if it's level is greater than or is level 30, the pet gains no closeness. :|

PHP:
        public void gainCloseness(int closeness) {
            MaplePet pet = getPlayer().getPet();
            if (pet.getCloseness() < 30000 || pet.getLevel() < 30) {
                    pet.setCloseness(pet.getCloseness() + closeness);
                } else {
                     pet.setCloseness(pet.getCloseness() + 0);
                }
        }

A few more commands to satisfy your inner lazy:
PHP:
        public int getPetLevel() {
            return pet.getLevel();
        }
        
        public int getFullness() {
            return pet.getFullness();
        }
        
        public String getPetName() {
            return pet.getName();
        }
        
        public void setPetName(String petname) {
            pet.setName(petname);
        }

In NPCConversationManager.java, find:
PHP:
public class NPCConversationManager extends AbstractPlayerInteraction {
	private int npc;
	private String getText;

Underneath it place:
Code:
private MaplePet pet = getPlayer().getPet();

Find:
PHP:
        public void gainCloseness(int closeness) {
            MaplePet pet = getPlayer().getPet();
            if (pet.getCloseness() < 30000 || pet.getLevel() < 30) {
                    pet.setCloseness(pet.getCloseness() + closeness);
                } else {
                     pet.setCloseness(pet.getCloseness() + 0);
                }
        }

Replace it with:
PHP:
        public void gainCloseness(int closeness) {
            if (pet.getCloseness() < 30000 || pet.getLevel() < 30) {
                    pet.setCloseness(pet.getCloseness() + closeness);
                } else {
                     pet.setCloseness(pet.getCloseness() + 0);
                }
        }
 
Re: [Release] gainCloseness()

I swear I posted in here o.o

Anyway, you'll need to send the updatePet packet when you increase the closeness, and you'll also need to check for level-ups. Good job though =)
 
Status
Not open for further replies.
Back