Rog3r
June 22nd, 2010, 18:55
Add an avatar system in YOUR source!
Explanation:
This will create an avatar based society in you're source. Basically, you can pick from two races at the moment. Each race has it's bonuses and weapons and emotes and many other things - just read the features list.
This will only work for Devolution or Dodian based servers, sorry! However, perhaps a simple conversion will allow it to compile without any errors.
Features:
- Goblin/Elf Families
- Goblin/Elf Separate Walking Animations
- Goblin/Elf Separate Banking Spots
- Goblin/Elf Family Based Levels
- Goblin/Elf Family Based Level Weapon Requirements
- Goblin/Elf Family Weapon Bonuses
- Goblin/Elf Family Level Up Messages
- Goblin/Elf Family Based Starter
- Goblin/Elf Family Based Setting of NPC Depending on Combat Level
- Goblin/Elf Basis of Selecting Family in the Beginning
- Goblin/Elf Leveling up with changing of player NPCID
- Goblin Only Emotes in Emote Tab
Procedure:
Create a new file and make sure you name it as: Avatarhandler.java. Then, put this in:
/*
Created by: Rog3r
Version: v0.1
*/
public class Avatarhandler {
public static int Elf, Goblin, familyLevel, elfStarter, goblinStarter, bankSpace, walkAnimation, attackAnimation;
public static boolean goblinWeapon, elfWeapon, setPicked;
public static String GetItemName(int ItemID) {
for (int i = 0; i < server.itemHandler.MaxListedItems; i++) {
if (server.itemHandler.ItemList[i] != null) {
if (server.itemHandler.ItemList[i].itemId == ItemID) {
return server.itemHandler.ItemList[i].itemName;
}
if (ItemID == -1) {
return "Unarmed";
}
}
}
return "Non Existing Item - ID:"+ItemID;
}
public static int GetCLElf(int ItemID) {
if (ItemID == -1) {
return 0;
}
String ItemName = GetItemName(ItemID);
if (ItemName.startsWith("New_crystal")) {
return 5; // You need a Elf family level of 5 to wield this item
}
if (ItemName.startsWith("Dragon_vamb")) {
return 3; // You need a Elf family level of 3 to wield this item (and Def of 60 or what ever dragon is set on)
}
return 0;
}
public static int GetCLGoblin(int ItemID) {
if (ItemID == -1) {
return 0;
}
String ItemName = GetItemName(ItemID);
if (ItemName.startsWith("Dragon sp")) {
return 3; // You need a Goblin family level of 5 to wield this item (and Def of 60 or what ever dragon is set on)
}
if (ItemName.startsWith("Dragon hal")) {
return 3; // You need a Goblin family level of 3 to wield this item (and Def of 60 or what ever dragon is set on)
}
return 0;
}
public static void weaponBonus(int ItemID) {
String ItemName = GetItemName(ItemID);
if (Goblin == 1) {
if (ItemName.endsWith("spear") || ItemName.endsWith("spear(p)") || ItemName.endsWith("spear(kp)")) { // Weapons that give the class a bonus when attacking
goblinWeapon = true;
} else {
goblinWeapon = false;
}
}
if (Elf == 1) {
if (ItemName.endsWith("longbow")) { // Weapons that give the class a bonus when attacking
elfWeapon = true;
} else {
elfWeapon = false;
}
}
}
public static void l*****p(int plrID) {
client client = (client) PlayerHandler.players[plrID];
if (Elf == 1) {
switch (client.combatLevel) { // Displays the level up family level at every level followed
case 4:
case 53:
case 73:
case 103:
playerOn(plrID);
client.sendMessage("Congratulations, you are now a level "+familyLevel+" Elf!");
break;
}
}
if (Goblin == 1) {
switch (client.combatLevel) { // Displays the level up family level at every level followed
case 4:
case 53:
case 73:
case 103:
playerOn(plrID);
client.sendMessage("Congratulations, you are now a level "+familyLevel+" Goblin!");
break;
}
}
}
public static void playerOn(int plrID) {
client client = (client) PlayerHandler.players[plrID];
Elf = 1;
if (Elf == 1) {
bankSpace = 350; // Change the bank space given by the race
walkAnimation = 0x333; // Change the walking animation that will be used for the Elf
if (elfStarter == 1) {
setPicked = true; // < Do not change this!
client.addItem(841, 1); // Change the items that is given by the race when he logs in
client.addItem(882, 100);
elfStarter = 2;
}
if (misc.random(2) == 1) {
client.sendMessage("You're race is currently set at a level "+familyLevel+" Elf.");
} else {
client.sendMessage("You are apart of the level "+familyLevel+" Elf family.");
}
if (client.combatLevel == 3) {
client.npcId = 2361;
client.isNpc = true;
familyLevel = 1;
} else if (client.combatLevel >= 4 && client.combatLevel <= 52) {
client.npcId = 2359;
client.isNpc = true;
familyLevel = 2;
} else if (client.combatLevel >= 53 && client.combatLevel <= 72) {
client.npcId = 2362;
client.isNpc = true;
familyLevel = 3;
} else if (client.combatLevel >= 73 && client.combatLevel <= 102) {
client.npcId = 1183;
client.isNpc = true;
familyLevel = 4;
} else if (client.combatLevel >= 103) {
client.npcId = 1201;
client.isNpc = true;
familyLevel = 5;
}
}
if (Goblin == 1) {
bankSpace = 300; // Change the bank space given by the race
walkAnimation = 0x333; // Change the walking animation that will be used for the Goblin
if (goblinStarter == 1) {
setPicked = true; // < Do not change this!
client.addItem(1237, 1); // Change the items that is given by the race when he logs in
client.addItem(1155, 1);
goblinStarter = 2;
}
if (misc.random(2) == 1) {
client.sendMessage("You're race is currently set at a level "+familyLevel+" Goblin.");
} else {
client.sendMessage("You are apart of the level "+familyLevel+" Goblin family.");
}
if (client.combatLevel == 3) {
client.npcId = 100;
client.isNpc = true;
familyLevel = 1;
} else if (client.combatLevel >= 4 && client.combatLevel <= 52) {
client.npcId = 101;
client.isNpc = true;
familyLevel = 2;
} else if (client.combatLevel >= 53 && client.combatLevel <= 72) {
client.npcId = 102;
client.isNpc = true;
familyLevel = 3;
} else if (client.combatLevel >= 73 && client.combatLevel <= 102) {
client.npcId = 122;
client.isNpc = true;
familyLevel = 4;
} else if (client.combatLevel >= 103) {
client.npcId = 3061;
client.isNpc = true;
familyLevel = 5;
}
}
}
}
Now, close that file and then in the client class, search for:
if (oldLevel < getLevelForXP(playerXP[skill])) {
And below it, add the following:
Avatarhandler.l*****p(playerId);
In the same class, search for:
if ((playerItems[slot]-1) == wearID) {
And above it, add the following:
Avatarhandler.weaponBonus(wearID);
Now, add this.
It's just a few lines below this, and shouldn't be a problem adding:
int CLElf = Avatarhandler.GetCLElf(wearID);
int CLGoblin = Avatarhandler.GetCLGoblin(wearID);
A bit down, you should add the following.
If you don't know where this goes, ask however it's pretty self explanatory - just look around for some things that are similar to this code snippet.
if (CLElf > Avatarhandler.Elf) {
sendMessage("You're family level or race doesn't match the requirements");
GoFalse = true;
}
if (CLGoblin > Avatarhandler.Goblin) {
sendMessage("You're family level or race doesn't match the requirements");
GoFalse = true;
}
Where ever you're welcome message is, add this right below it.
Avatarhandler.playerOn(playerId);
if (!Avatarhandler.setPicked) {
/*
TODO: Make a dialogue appear to allow the user to pick their family!
* When they have picked, what ever code selects their family, place this in depending on what family they picked:
Avatarhandler.elfStarter = 1;
Avatarhandler.goblinStarter = 1;
*
You also don't have to set the boolean, setPicked to true as the starter will do it.
*/
}
Oh yeah, if you want some help on how to choose the family, please refer to the quoted out above.
In packet 185, replace case labels 52071 and label 52072 with the following:
case 52071:
if (Avatarhandler.Goblin == 1) {
if (emotes == 0) {
emotes = 1;
pEmote = 0x84F;
updateRequired = true;
appearanceUpdateRequired = true;
} else {
emotes = 0;
pEmote = playerSE;
updateRequired = true;
appearanceUpdateRequired = true;
}
} else {
sendMessage("You must be in the Goblin family to cast this emote.");
}
break;
case 52072:
if (Avatarhandler.Goblin == 1) {
if (emotes == 0) {
emotes = 1;
pEmote = 0x850;
updateRequired = true;
appearanceUpdateRequired = true;
} else {
emotes = 0;
pEmote = playerSE;
updateRequired = true;
appearanceUpdateRequired = true;
}
} else {
sendMessage("You must be in the Goblin family to cast this emote.");
}
break;
In the method Attack in your client class, search for:
boolean UseBow = false;
And below it, add the following:
if (Avatarhandler.elfWeapon) {
hitDiff = misc.random(playerMaxHit);
}
if (Avatarhandler.goblinWeapon) {
hitDiff = misc.random(playerMaxHit+misc.random(3));
}
In the player class, replace the max bank spots variable with the following:
public int playerBankSize = Avatarhandler.bankSpace;
In the same class, replace the pWalk variable with this:
public int pWalk = Avatarhandler.walkAnimation;
You are now done with this tutorial. Post any errors or concerns.
Bonus (not required if finished above):
Please note, if you added the following thing above - you don't have to add this below. They are the same things, just programmed differentially.
For those concerned with their performance and the level of programming skills in a source, you can always use this alternative avatar base class. It uses OOP and please note, it's an extreme base.
Create a new file and put this in:
/*
* Created by: Rog3r
*/
public class classMisc {
// Use these conditions in other classes ( > )
public static boolean dark = false;
public static boolean arch = false;
// Use these conditions in other classes ( < )
/*
If let's say for example, the condition 'dark' is set to true (upon dialogue screen etc?) - then it'd call upon this class.
You can add items from there and in the future.
To call upon methods in the client class, use the preface of: client.
*/
public void assignClasses(int plrID) { // ( < ) Assigns the call when the method run is called
client client = (client) PlayerHandler.players[plrID];
playerClasses darkMage = new playerClasses();
playerClasses archMage = new playerClasses();
/*
Above basically creates new classes. If you wish to change, then please do so.
*/
if (dark) {
darkMage.setClass("Dark Mage"); // ( < ) Sets the class only if the player chose the dark mage
client.sendMessage("Your class is of Dark Mage.");
assignRewards(plrID);
}
if (arch) {
archMage.setClass("Arch Mage"); // ( < ) Sets the class only if the player chose the arch mage
client.sendMessage("Your class is of Arch Mage.");
assignRewards(plrID);
}
}
public void assignRewards(int plrID) {
client client = (client) PlayerHandler.players[plrID];
/*
Assign only 'starter' the class will get upon switch. Please remember, you must save the variables ' darkMage ' and ' archMage ' via client class.
Ideas:
- More Bank Space
- Better Weapon Speed
- !! Quests using (if darkMage == 1) { etc to indiciate what class you are !!
*/
if (dark) {
// client.addItem(995, 1000);
}
if (arch) {
}
}
}
Create another new file and put this in:
/*
* Created by: Rog3r
*/
class playerClasses {
private String Class;
public int darkMage = 0, archMage = 0;
public void setClass(String n) {
Class = n;
if (Class.equalsIgnoreCase("Dark Mage")) { // Self Explained
darkMage = 1; // Variable used to save to define one's class in the future
Class = null;
} else if (Class.equalsIgnoreCase("Arch Mage")) { // Self Explained
archMage = 1; // Variable used to save to define one's class in the future
Class = null;
}
}
public String returnClass() { // Returns the initial class of the selected player
return Class;
}
}
I won't explain much - this is just an example of object orientated ways of programming this avatar base. It may be better in the long run - for those who want an example - i've provided it above for your convenience.
Once again this would only work with Devolution V7 however with some simple conversions, this will work for other sources too. Have fun!
Explanation:
This will create an avatar based society in you're source. Basically, you can pick from two races at the moment. Each race has it's bonuses and weapons and emotes and many other things - just read the features list.
This will only work for Devolution or Dodian based servers, sorry! However, perhaps a simple conversion will allow it to compile without any errors.
Features:
- Goblin/Elf Families
- Goblin/Elf Separate Walking Animations
- Goblin/Elf Separate Banking Spots
- Goblin/Elf Family Based Levels
- Goblin/Elf Family Based Level Weapon Requirements
- Goblin/Elf Family Weapon Bonuses
- Goblin/Elf Family Level Up Messages
- Goblin/Elf Family Based Starter
- Goblin/Elf Family Based Setting of NPC Depending on Combat Level
- Goblin/Elf Basis of Selecting Family in the Beginning
- Goblin/Elf Leveling up with changing of player NPCID
- Goblin Only Emotes in Emote Tab
Procedure:
Create a new file and make sure you name it as: Avatarhandler.java. Then, put this in:
/*
Created by: Rog3r
Version: v0.1
*/
public class Avatarhandler {
public static int Elf, Goblin, familyLevel, elfStarter, goblinStarter, bankSpace, walkAnimation, attackAnimation;
public static boolean goblinWeapon, elfWeapon, setPicked;
public static String GetItemName(int ItemID) {
for (int i = 0; i < server.itemHandler.MaxListedItems; i++) {
if (server.itemHandler.ItemList[i] != null) {
if (server.itemHandler.ItemList[i].itemId == ItemID) {
return server.itemHandler.ItemList[i].itemName;
}
if (ItemID == -1) {
return "Unarmed";
}
}
}
return "Non Existing Item - ID:"+ItemID;
}
public static int GetCLElf(int ItemID) {
if (ItemID == -1) {
return 0;
}
String ItemName = GetItemName(ItemID);
if (ItemName.startsWith("New_crystal")) {
return 5; // You need a Elf family level of 5 to wield this item
}
if (ItemName.startsWith("Dragon_vamb")) {
return 3; // You need a Elf family level of 3 to wield this item (and Def of 60 or what ever dragon is set on)
}
return 0;
}
public static int GetCLGoblin(int ItemID) {
if (ItemID == -1) {
return 0;
}
String ItemName = GetItemName(ItemID);
if (ItemName.startsWith("Dragon sp")) {
return 3; // You need a Goblin family level of 5 to wield this item (and Def of 60 or what ever dragon is set on)
}
if (ItemName.startsWith("Dragon hal")) {
return 3; // You need a Goblin family level of 3 to wield this item (and Def of 60 or what ever dragon is set on)
}
return 0;
}
public static void weaponBonus(int ItemID) {
String ItemName = GetItemName(ItemID);
if (Goblin == 1) {
if (ItemName.endsWith("spear") || ItemName.endsWith("spear(p)") || ItemName.endsWith("spear(kp)")) { // Weapons that give the class a bonus when attacking
goblinWeapon = true;
} else {
goblinWeapon = false;
}
}
if (Elf == 1) {
if (ItemName.endsWith("longbow")) { // Weapons that give the class a bonus when attacking
elfWeapon = true;
} else {
elfWeapon = false;
}
}
}
public static void l*****p(int plrID) {
client client = (client) PlayerHandler.players[plrID];
if (Elf == 1) {
switch (client.combatLevel) { // Displays the level up family level at every level followed
case 4:
case 53:
case 73:
case 103:
playerOn(plrID);
client.sendMessage("Congratulations, you are now a level "+familyLevel+" Elf!");
break;
}
}
if (Goblin == 1) {
switch (client.combatLevel) { // Displays the level up family level at every level followed
case 4:
case 53:
case 73:
case 103:
playerOn(plrID);
client.sendMessage("Congratulations, you are now a level "+familyLevel+" Goblin!");
break;
}
}
}
public static void playerOn(int plrID) {
client client = (client) PlayerHandler.players[plrID];
Elf = 1;
if (Elf == 1) {
bankSpace = 350; // Change the bank space given by the race
walkAnimation = 0x333; // Change the walking animation that will be used for the Elf
if (elfStarter == 1) {
setPicked = true; // < Do not change this!
client.addItem(841, 1); // Change the items that is given by the race when he logs in
client.addItem(882, 100);
elfStarter = 2;
}
if (misc.random(2) == 1) {
client.sendMessage("You're race is currently set at a level "+familyLevel+" Elf.");
} else {
client.sendMessage("You are apart of the level "+familyLevel+" Elf family.");
}
if (client.combatLevel == 3) {
client.npcId = 2361;
client.isNpc = true;
familyLevel = 1;
} else if (client.combatLevel >= 4 && client.combatLevel <= 52) {
client.npcId = 2359;
client.isNpc = true;
familyLevel = 2;
} else if (client.combatLevel >= 53 && client.combatLevel <= 72) {
client.npcId = 2362;
client.isNpc = true;
familyLevel = 3;
} else if (client.combatLevel >= 73 && client.combatLevel <= 102) {
client.npcId = 1183;
client.isNpc = true;
familyLevel = 4;
} else if (client.combatLevel >= 103) {
client.npcId = 1201;
client.isNpc = true;
familyLevel = 5;
}
}
if (Goblin == 1) {
bankSpace = 300; // Change the bank space given by the race
walkAnimation = 0x333; // Change the walking animation that will be used for the Goblin
if (goblinStarter == 1) {
setPicked = true; // < Do not change this!
client.addItem(1237, 1); // Change the items that is given by the race when he logs in
client.addItem(1155, 1);
goblinStarter = 2;
}
if (misc.random(2) == 1) {
client.sendMessage("You're race is currently set at a level "+familyLevel+" Goblin.");
} else {
client.sendMessage("You are apart of the level "+familyLevel+" Goblin family.");
}
if (client.combatLevel == 3) {
client.npcId = 100;
client.isNpc = true;
familyLevel = 1;
} else if (client.combatLevel >= 4 && client.combatLevel <= 52) {
client.npcId = 101;
client.isNpc = true;
familyLevel = 2;
} else if (client.combatLevel >= 53 && client.combatLevel <= 72) {
client.npcId = 102;
client.isNpc = true;
familyLevel = 3;
} else if (client.combatLevel >= 73 && client.combatLevel <= 102) {
client.npcId = 122;
client.isNpc = true;
familyLevel = 4;
} else if (client.combatLevel >= 103) {
client.npcId = 3061;
client.isNpc = true;
familyLevel = 5;
}
}
}
}
Now, close that file and then in the client class, search for:
if (oldLevel < getLevelForXP(playerXP[skill])) {
And below it, add the following:
Avatarhandler.l*****p(playerId);
In the same class, search for:
if ((playerItems[slot]-1) == wearID) {
And above it, add the following:
Avatarhandler.weaponBonus(wearID);
Now, add this.
It's just a few lines below this, and shouldn't be a problem adding:
int CLElf = Avatarhandler.GetCLElf(wearID);
int CLGoblin = Avatarhandler.GetCLGoblin(wearID);
A bit down, you should add the following.
If you don't know where this goes, ask however it's pretty self explanatory - just look around for some things that are similar to this code snippet.
if (CLElf > Avatarhandler.Elf) {
sendMessage("You're family level or race doesn't match the requirements");
GoFalse = true;
}
if (CLGoblin > Avatarhandler.Goblin) {
sendMessage("You're family level or race doesn't match the requirements");
GoFalse = true;
}
Where ever you're welcome message is, add this right below it.
Avatarhandler.playerOn(playerId);
if (!Avatarhandler.setPicked) {
/*
TODO: Make a dialogue appear to allow the user to pick their family!
* When they have picked, what ever code selects their family, place this in depending on what family they picked:
Avatarhandler.elfStarter = 1;
Avatarhandler.goblinStarter = 1;
*
You also don't have to set the boolean, setPicked to true as the starter will do it.
*/
}
Oh yeah, if you want some help on how to choose the family, please refer to the quoted out above.
In packet 185, replace case labels 52071 and label 52072 with the following:
case 52071:
if (Avatarhandler.Goblin == 1) {
if (emotes == 0) {
emotes = 1;
pEmote = 0x84F;
updateRequired = true;
appearanceUpdateRequired = true;
} else {
emotes = 0;
pEmote = playerSE;
updateRequired = true;
appearanceUpdateRequired = true;
}
} else {
sendMessage("You must be in the Goblin family to cast this emote.");
}
break;
case 52072:
if (Avatarhandler.Goblin == 1) {
if (emotes == 0) {
emotes = 1;
pEmote = 0x850;
updateRequired = true;
appearanceUpdateRequired = true;
} else {
emotes = 0;
pEmote = playerSE;
updateRequired = true;
appearanceUpdateRequired = true;
}
} else {
sendMessage("You must be in the Goblin family to cast this emote.");
}
break;
In the method Attack in your client class, search for:
boolean UseBow = false;
And below it, add the following:
if (Avatarhandler.elfWeapon) {
hitDiff = misc.random(playerMaxHit);
}
if (Avatarhandler.goblinWeapon) {
hitDiff = misc.random(playerMaxHit+misc.random(3));
}
In the player class, replace the max bank spots variable with the following:
public int playerBankSize = Avatarhandler.bankSpace;
In the same class, replace the pWalk variable with this:
public int pWalk = Avatarhandler.walkAnimation;
You are now done with this tutorial. Post any errors or concerns.
Bonus (not required if finished above):
Please note, if you added the following thing above - you don't have to add this below. They are the same things, just programmed differentially.
For those concerned with their performance and the level of programming skills in a source, you can always use this alternative avatar base class. It uses OOP and please note, it's an extreme base.
Create a new file and put this in:
/*
* Created by: Rog3r
*/
public class classMisc {
// Use these conditions in other classes ( > )
public static boolean dark = false;
public static boolean arch = false;
// Use these conditions in other classes ( < )
/*
If let's say for example, the condition 'dark' is set to true (upon dialogue screen etc?) - then it'd call upon this class.
You can add items from there and in the future.
To call upon methods in the client class, use the preface of: client.
*/
public void assignClasses(int plrID) { // ( < ) Assigns the call when the method run is called
client client = (client) PlayerHandler.players[plrID];
playerClasses darkMage = new playerClasses();
playerClasses archMage = new playerClasses();
/*
Above basically creates new classes. If you wish to change, then please do so.
*/
if (dark) {
darkMage.setClass("Dark Mage"); // ( < ) Sets the class only if the player chose the dark mage
client.sendMessage("Your class is of Dark Mage.");
assignRewards(plrID);
}
if (arch) {
archMage.setClass("Arch Mage"); // ( < ) Sets the class only if the player chose the arch mage
client.sendMessage("Your class is of Arch Mage.");
assignRewards(plrID);
}
}
public void assignRewards(int plrID) {
client client = (client) PlayerHandler.players[plrID];
/*
Assign only 'starter' the class will get upon switch. Please remember, you must save the variables ' darkMage ' and ' archMage ' via client class.
Ideas:
- More Bank Space
- Better Weapon Speed
- !! Quests using (if darkMage == 1) { etc to indiciate what class you are !!
*/
if (dark) {
// client.addItem(995, 1000);
}
if (arch) {
}
}
}
Create another new file and put this in:
/*
* Created by: Rog3r
*/
class playerClasses {
private String Class;
public int darkMage = 0, archMage = 0;
public void setClass(String n) {
Class = n;
if (Class.equalsIgnoreCase("Dark Mage")) { // Self Explained
darkMage = 1; // Variable used to save to define one's class in the future
Class = null;
} else if (Class.equalsIgnoreCase("Arch Mage")) { // Self Explained
archMage = 1; // Variable used to save to define one's class in the future
Class = null;
}
}
public String returnClass() { // Returns the initial class of the selected player
return Class;
}
}
I won't explain much - this is just an example of object orientated ways of programming this avatar base. It may be better in the long run - for those who want an example - i've provided it above for your convenience.
Once again this would only work with Devolution V7 however with some simple conversions, this will work for other sources too. Have fun!