PDA

View Full Version : 317 - Avatar Base V1 (non OO, w/ OO)



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!

TehCow
June 22nd, 2010, 18:56
WOW
Very nice, what this would add is awesome, post pics of it?

Sunni
June 22nd, 2010, 18:57
This is kinda like warcraft rs server, intresting.

Rog3r
June 22nd, 2010, 19:03
WOW
Very nice, what this would add is awesome, post pics of it?

Never tested this ever before. Kind of wrote it and released it assuming it'd work... :o

Kingdomkey01
June 22nd, 2010, 19:22
Nice job :D. It's a good base for people adding this to their server.

XxBryantD
June 22nd, 2010, 19:25
nice..

Shane
June 22nd, 2010, 19:26
That's impressive. Nice work!

Canownueasy`
June 22nd, 2010, 20:50
Barely any conventions :(

samuraiblood2
June 23rd, 2010, 01:47
This is ugly, to the point I actually attempted on creating a better version.



import java.util.Random;

public class RaceHandler {

private static RaceHandler singleton;

private Race race;

public RaceHandler() {
Random random = new Random();
Race.Type[] values = Race.Type.values();
int rand = random.nextInt(3);
race = new Race(values[rand]);
}

public int getWeaponRequirements(int item) {
if (item == -1) {
return 0;
}
String name = RaceHandler.getNameForID(item);

// XXX: The contains method does use regex right? If not, then who cares.
switch (race.getType()) {
case GOBLIN:
if (name.contains("(?i)dragon sp")) {
return 3;
} else if (name.contains("(?i)dragon hal")) {
return 3;
}
return 0;

case ELF:
if (name.contains("(?i)dragon_vamb")) {
return 3;
} else if (name.contains("(?i)new_crystal")) {
return 5;
}
return 0;

default:
// TODO: Give humans something useful.
return 0;
}
}

public void getL*****pMessage(int id) {
client client = (client) PlayerHandler.players[id];
switch (client.cobatLevel) {
case 4:
case 53:
case 73:
case 103:
int level = race.getLevel();
race.setLevel(level++);
client.sendMessage("Congratulations, you are now a level " + race.getLevel() + " " + race.getRaceName());
break;
}
}

public Race getRace() {
return race;
}

public static String getNameForID(int item) {
for (int i = 0; i < ItemHandler.MaxListedItems; i++) {
if (server.itemHandler.ItemList[i] == null) {
break;
}

if (server.itemHandler.ItemList[i].itemId == item) {
return server.itemHandler.ItemList[i].itemName;
}

if (item == -1) {
return "Unarmed";
}
}
return "bad id (" + item + ")";
return null;
}

public static class Race {

private Type type;
private int level;
private String name;

public enum Type {
GOBLIN, ELF, HUMAN
}

public Race(Type type) {
this.type = type;
}

public String getRaceName() {
switch (type) {
case GOBLIN:
return "Goblin";
case ELF:
return "Elf";
default:
return "Human";
}
}

public void setLevel(int level) {
this.level = level;
}

public int getLevel() {
return level;
}

public Type getType() {
return type;
}
}
}

Trey
June 23rd, 2010, 01:55
Your OOP style is bad. Learn to encapsulate and learn proper naming conventions and just general structure. Btw, your variables (which should be private anyway) are static, which means this wouldn't work the way you want it to. I am trying to figure out your logic behind just about everything in this.

And wtf at this:


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 honestly expected a lot more.

Faab234
June 23rd, 2010, 07:01
Can you post a Picture Rog3r, Thanks!

Rog3r
June 23rd, 2010, 15:00
Your OOP style is bad. Learn to encapsulate and learn proper naming conventions and just general structure. Btw, your variables (which should be private anyway) are static, which means this wouldn't work the way you want it to. I am trying to figure out your logic behind just about everything in this.

And wtf at this:


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 honestly expected a lot more.

This was originally posted on 02-20-2009, 06:25 PM (so it was a tad old) although I rewritten the tutorial part, not the code part (probably why its not as good as I could have done it today).

Thanks though for the suggestions and Samurai for re-building the code. :)

Par3210
June 23rd, 2010, 18:16
Hey, I just wanted to ask (I'm new to this) but where is packet 185? I have looked in the client java for the cases and the packet 185 but nothing turned up.
Help please?

Rog3r
June 23rd, 2010, 19:04
Hey, I just wanted to ask (I'm new to this) but where is packet 185? I have looked in the client java for the cases and the packet 185 but nothing turned up.
Help please?

You may have a separate class called 'clickingmostbuttons'.

Fenway`
June 23rd, 2010, 19:16
weird but creative

samuraiblood2
June 23rd, 2010, 19:28
weird but creative

Its not weird, there are actually a lot of RPG's with a similar system. Off the top of my head I can think of World Of Warcraft and The Elder Scrolls.

Rixi
June 23rd, 2010, 19:56
Umm... So will there still be human race if I add this (I didn't look at the code at all yet, soz.)

Its kinda interesting too. Might convert to Hyperion and use for my Mahjarrat base. (I've got two 'races' written in right now. Mahjarrats and Humans, Human can become mahjarrat after finishing something.)

Comboed
June 23rd, 2010, 20:02
Hey, I just wanted to ask (I'm new to this) but where is packet 185? I have looked in the client java for the cases and the packet 185 but nothing turned up.
Help please?
Packets are cases. search case 185:

Trey
June 23rd, 2010, 22:32
Packets are cases. search case 185:

No they aren't. Just because some servers (specifically WL based ones for the most part) handle the packets by using a switch on the opcode doesn't mean "packet" is the term for a case in a switch.

elf run1
June 24th, 2010, 02:17
this is nice good job rog3r =)

thirkle
July 25th, 2010, 22:21
i got 1 million errors FUCK!

XxBryantD
September 6th, 2010, 04:15
client.java:13417: <identifier> expected
Avatarhandler.playerOn(playerId);
^
client.java:13417: <identifier> expected
Avatarhandler.playerOn(playerId);
^
client.java:13418: illegal start of type
if (!Avatarhandler.setPicked) {
^
client.java:13418: illegal start of type
if (!Avatarhandler.setPicked) {
^
client.java:13418: ')' expected
if (!Avatarhandler.setPicked) {
^
client.java:13418: ';' expected
if (!Avatarhandler.setPicked) {
^
client.java:13418: <identifier> expected
if (!Avatarhandler.setPicked) {
^
7 errors
Finished!
Press any key to continue . . .

sageofmali
December 11th, 2010, 21:13
Hey uhmmm. I have Delta based server. And when people are goblins they turn into hans. Could someone help me fix this please?