Post: [PI] Greegree Tutorial
03-09-2015, 10:30 PM #1
Stunz
Former Staff
(adsbygoogle = window.adsbygoogle || []).push({});
So in this tutorial, I have created a greegree system which at the moment is bug free. It handles all kinds of cases such as wearing items, removing items, performing emotes, or logging out with a greegree equipt.

So here it is:

The first thing to do is add this Greegree.java class in the same folder as Player.java:
    package server.model.players;

import server.model.players.Player;

/**
* Contains data for using monkey greegrees.
* @author Chex
*
*/
public class Greegree {
public static enum MonkeyData {
SMALL_NINJA(4024, 1480, 1386, 1380, 1381, 1383, -1),
LARGE_NINJA(4025, 1481, 1386, 1380, 1381, 1383, -1),
MONKEY_GUARD(4026, 1482, 1401, 1399, 1400, 1402, 1403),
BEARDED_MONKEY_GUARD(4027, 1483, 1401, 1399, 1400, 1402, 1403),
BLUE_FACE_MONKEY_GUARD(4028, 1484, 1401, 1399, 1400, 1402, 1403),
SMALL_ZOMBIE(4029, 1485, 1386, 1382, 1381, 1383,-1),
LARGE_MONKEY(4030, 1486, 1386, 1382, 1381, 1383, -1),
KARAMAJA_MONKEY(4031, 1487, 222, 219, 220, 220, 221);

int greegreeID, npcID, standAnim, walkAnim, runAnim, attackAnim, blockAnim;

private MonkeyData(int greegreeID, int npcID, int standAnim, int walkAnim, int runAnim, int attackAnim, int blockAnim) {
this.greegreeID = greegreeID;
this.npcID = npcID;
this.standAnim = standAnim;
this.walkAnim = walkAnim;
this.runAnim = runAnim;
this.attackAnim = attackAnim;
this.blockAnim = blockAnim;
}

public int getGreegreeID() {
return greegreeID;
}

public int getNpcID() {
return npcID;
}

public int getStandAnim() {
return standAnim;
}

public int getWalkAnim() {
return walkAnim;
}

public int getRunAnim() {
return runAnim;
}

public int getBlockAnim() {
return blockAnim;
}

public int getAttackAnim() {
return attackAnim;
}

public static MonkeyData forId(int id) {
for (MonkeyData data: MonkeyData.values())
if (data.greegreeID == id)
return data;
return null;
}

public static boolean isWearingGreegree(Player p) {
return MonkeyData.forId(p.playerEquipment[Player.playerWeapon]) != null;
}

public static boolean isAnim(int animId) {
for (MonkeyData data: MonkeyData.values())
if (data.attackAnim == animId || data.blockAnim == animId)
return true;
return false;
}
}

public static boolean attemptGreegree(Player p, int weaponID) {
int targetSlot = p.getItems().targetSlot(p.getItems().getItemName(weaponID).toLowerCase());
if (MonkeyData.forId(weaponID) == null && targetSlot != Player.playerWeapon && MonkeyData.isWearingGreegree(p)) {
p.sendMessage("You can't equipt that while wearing a greegree.");
return false;
}
MonkeyData data = MonkeyData.forId(weaponID);
if (MonkeyData.isWearingGreegree(p) || data != null) {
if (data != null) {
setAnimations(p, data);
} else {
resetAnimations(p);
}
p.gfx100(359);
return true;
}
return true;
}

public static void setAnimations(Player p, MonkeyData data) {
p.npcId2 = data.getNpcID();
p.isNpc = true;
p.playerStandIndex = data.getStandAnim();
p.playerWalkIndex = data.getWalkAnim();
p.playerRunIndex = data.getRunAnim();
p.playerTurnIndex = data.getWalkAnim();
p.playerTurn180Index = data.getWalkAnim();
p.playerTurn90CWIndex = data.getWalkAnim();
p.playerTurn90CCWIndex = data.getWalkAnim();
p.getPA().requestUpdates();
}

public static void resetAnimations(Player p) {
p.npcId2 = -1;
p.isNpc = false;
p.getPA().resetAnimation();
p.gfx100(359);
}

public static boolean attemptRemove(Player p, int slot) {
if (slot == Player.playerWeapon && MonkeyData.isWearingGreegree(p)) {
resetAnimations(p);
} else if (slot != Player.playerWeapon && MonkeyData.isWearingGreegree(p)) {
p.sendMessage("You can't remove items while wearing a greegree.");
return false;
}
return true;
}
}


NOTE: If you don't have a method called targetSlot() in ItemAssistant.java, replace this method in Greegree.java:
    public static boolean attemptGreegree(Player p, int weaponID) {
int targetSlot = Item.targetSlots[weaponID];
if (MonkeyData.forId(weaponID) == null && targetSlot != Player.playerWeapon && MonkeyData.isWearingGreegree(p)) {
p.sendMessage("You can't equipt that while wearing a greegree.");
return false;
}
MonkeyData data = MonkeyData.forId(weaponID);
if (MonkeyData.isWearingGreegree(p) || data != null) {
if (data != null) {
setAnimations(p, data);
} else {
resetAnimations(p);
}
p.gfx100(359);
return true;
}
return true;
}

NOTE: If your server used Client.java, replace all the (Player p, ...) in the methods in Greegree.java with (Client p, ...)
Good. Now open up ItemAssistant.java

Add this import at the top of the file:
    import server.model.players.Greegree;

Now find this:
    public boolean wearItem(int wearID, int slot) {

Add this under synchronized(c) {
    boolean greegree = Greegree.attemptGreegree(c, wearID);
if (!greegree) return false;

In the method (it should be near the very end), find:
    c.getCombat().getPlayerAnimIndex(c.getItems().getItemName(c.playerEquipment[Player.playerWeapon]).toLowerCase());

and right above that add:
    if (!greegree)

Now we need to handle removing the greegree from the equipment tab. In the same class (ItemAssistant.java), find this:
    public void removeItem(int wearID, int slot) {

Now under the synchronized(c) { add this:
    boolean greegree = Greegree.attemptGreegree(c, wearID);
if (!greegree) return false;

So now you are done...the next part is adding the attack and block animations for combat.

Open up CombatAssistant.java

Add this import at the top of the file:
    import server.model.players.Greegree.MonkeyData;

Find this method:
    public int getWepAnim(String weaponName) {

Right under that add:
    MonkeyData data = MonkeyData.forId(c.playerEquipment[Player.playerWeapon]);
if (data != null)
return data.getAttackAnim();

Now find this method:
    public int getBlockEmote() {

and under that add:
    MonkeyData data = MonkeyData.forId(c.playerEquipment[Player.playerWeapon]);
if (data != null)
return data.getBlockAnim();

Done. Now open Player.java

Add this import at the top of the file:
    import server.model.players.Greegree.MonkeyData;

Now find:
    public void startAnimation(int animId) {

Under that line add:
    if (MonkeyData.isWearingGreegree(this) && !MonkeyData.isAnim(animId)) {
return;
}

That makes sure you can only do certain emotes as a monkey.

Now if your server uses Client.java, open it otherwise stay in Player.java and find:
    public void initialize() {

In that method, find:
    getCombat().getPlayerAnimIndex(getItems().getItemName(playerEquipment[playerWeapon]).toLowerCase());

Now put this right under it:
    Greegree.attemptGreegree(this, playerEquipment[playerWeapon]);

That makes sure when you log in and have a greegree equipt, you will be the monkey.
NOTE: If you used Client.java, you need to add this import:
    import server.model.players.Greegree;
(adsbygoogle = window.adsbygoogle || []).push({});

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo