Spikesscape
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[508] fishing base

Go down

[508] fishing base Empty [508] fishing base

Post  [Owner]Spikes Sun Aug 23, 2009 5:55 am

Description: This tutorial will show you how to add this simple fishing base.
Difficulty: 1/10.
Knowledge Needed: How to declare methods/Variables, and how to follow simple instructions.
Server tested on: Palidino76's Version 1.
Files Modified: Player.java and NPCOption1.java.


Procedure


Note: This isn't compatible for An Espeon base, as the packaging, and some methods/classes, are different. You may wish to convert it to Espeon, though it is completely your choice.

Step 1 - Declaring the variables

First off, you need to open Player.java, and declare these variables:

Code:

/**
* Fishing Variables
*/
public int fishTimer = -1;
public int fishXP;
public int fishGet;
public int fishEmote;
public int fishLvlReq;
public String fishName;


These will be used in the methods/Snippets of code you will be adding shortly.
The 'fishTimer' variable explains itself.
The 'fishXP' variable will determine what Experience you will gain when a fish has been caught.
The 'fishGet' variable will be the ID of the fish you are trying to catch.
The 'fishEmote' variable will be the animation you do when you attempt to catch fish.
The 'fishLvlReq' variable will be the level required to catch the fish.
The 'fishName' string will be the name of the fish you are trying to catch, will be used in the message sent when you catch a fish. EG. "You caught a Lobster".


Step 2 - Adding the method used for fishing

You now need to declare these methods:

Code:

/**
* Fishing Methods
*/
public void Fish(Player p, int Exp, int Item, int Anim, String FishingName) {
int invItemSlots = Engine.playerItems.findInvSlot(this);
int k = skillLvl[10];

if (invItemSlots > 0) {
Engine.playerItems.addItem(p, Item, 1);
p.frames.sendMessage(this, "You caught a "+ fishName +".");
fishTimer = Misc.random(15 + (k / Cool - fishLvlReq / 4);
fishName = FishingName;
p.requestAnim(Anim, 0);
p.addSkillXP(Exp, 10);
} else {
resetFishing();
frames.playSound(this, 2268, 1, 0);
p.frames.showChatboxInterface(p, 241);
p.frames.setString(p, "You have run out of inventory space.", 241, 4);
p.frames.setString(p, "", 241, 3);
p.frames.sendMessage(this, "You have run out of inventory space.");
p.requestAnim(standEmote, 0);
}
}

public void resetFishing() {
fishTimer = -1;
fishXP = 0;
fishGet = 0;
fishEmote = 0;
fishName = "";
fishLvlReq = 0;
}



The 'Fish' method will, if you have enough inventory slots, give you the fish you are attempting to fish, give you the fishing Experience for that particular type of fish, and make the timer a random number which is determined by your fishing level, and the fishing level required to catch the fish.
If you do not have enough inventory slots to get a fish, it will reset all the fishing variables and reset the animation. It will also play the sound for not having enough inventory space, also showing the chatbox interface.

The 'resetFishing' method is self explanatory.


Step 3 - Adding items into the processing method

Next, in the processing method (public void process), add these:

Code:

if (fishTimer > 0) {
fishTimer--;
}
if (fishTimer == 0) {
Fish(this, fishXP, fishGet, fishEmote, fishName);
}



Those will deplete the fishTimer variable by one everytime the process method is called, which is every 600ms, and when the fishTimer is 0, it will call the 'Fish' method that you added earlier.


Step 4 - Adding the fishspot's NPC clicking

In both NPCOption1.java, and NPCOption2.java, in the 'handlePacket' method, you need to add these under 'p.clickId = npcId;':

Code:

NPC n = Engine.npcs[p.clickId];
int k = p.skillLvl[10];


'NPC n = Engine.npcs[p.clickId];'- This will allow you to use the NPCId as the case in the switch statement instead of a random stream number for that NPC.
'int k = p.skillLvl[10];' - This declares the integer 'k' (only for this method), and makes it equal your fishing level.


Also, you need to replace the switch statements in both classes, to this:

Code:

switch (n.npcType) {



In NPCOption1, add these switch statement cases for the fishing:

Code:

case 316: // Fish Shrimps
if (p.skillLvl[10] >= 1) {
if (Engine.playerItems.HasItemAmount(p, 303, 1) == true) {
p.fishXP = 50;
p.fishGet = 317;
p.fishEmote = 620;
p.fishLvlReq = 1;
p.fishName = "Shrimp";
p.fishTimer = Misc.random(15 + (k / Cool - p.fishLvlReq / 4);
p.requestAnim(p.fishEmote, 0);
} else {
p.frames.sendMessage(p, "You need a small fishing net to fish Shrimp.");
}
} else {
p.frames.sendMessage(p, "You need level 1 fishing to fish Shrimp.");
}
break;

case 313: // Fish Bass
if (p.skillLvl[10] > 29) {
if (Engine.playerItems.HasItemAmount(p, 305, 1) == true) {
p.fishXP = 110;
p.fishGet = 363;
p.fishEmote = 620;
p.fishLvlReq = 29;
p.fishName = "Bass";
p.fishTimer = Misc.random(15 + (k / Cool - p.fishLvlReq / 4);
p.requestAnim(p.fishEmote, 0);
} else {
p.frames.sendMessage(p, "You need a big fishing net to fish Bass.");
}
} else {
p.frames.sendMessage(p, "You need level 30 fishing to fish Bass.");
}
break;


case 312: // Fish Lobsters
if (p.skillLvl[10] > 39) {
if (Engine.playerItems.HasItemAmount(p, 301, 1) == true) {
p.fishXP = 300;
p.fishGet = 377;
p.fishEmote = 619;
p.fishLvlReq = 40;
p.fishName = "Lobster";
p.fishTimer = Misc.random(15 + (k / Cool - p.fishLvlReq / 4);
p.requestAnim(p.fishEmote, 0);
} else {
p.frames.sendMessage(p, "You need a lobster pot to fish Lobsters.");
}
} else {
p.frames.sendMessage(p, "You need level 40 fishing to fish Lobsters.");
}
break;



Now, in NPCOption1, add these switch statement cases for the fishing:

Code:

case 326: // Fish Trout
if (p.skillLvl[10] > 14) {
if (Engine.playerItems.HasItemAmount(p, 307, 1) == true) {
p.fishXP = 150;
p.fishGet = 335;
p.fishEmote = 622;
p.fishName = "Trout";
p.fishTimer = Misc.random(15 + (k / Cool - p.fishLvlReq / 4);
p.requestAnim(p.fishEmote, 0);
} else {
p.frames.sendMessage(p, "You need a fishing rod to fish Trout.");
}
} else {
p.frames.sendMessage(p, "You need level 15 fishing to fish Trout.");
}
break;

case 322: // Fish Shark
if (p.skillLvl[10] > 74) {
if (Engine.playerItems.HasItemAmount(p, 311, 1) == true) {
p.fishXP = 500;
p.fishGet = 383;
p.fishEmote = 618;
p.fishName = "Shark";
p.fishTimer = Misc.random(15 + (k / Cool - p.fishLvlReq / 4);
p.requestAnim(p.fishEmote, 0);
} else {
p.frames.sendMessage(p, "You need a harpoon to fish here.");
}
} else {
p.frames.sendMessage(p, "You need level 75 fishing to fish Sharks.");
}
break;

case 323: // Fish Manta
if (p.skillLvl[10] > 89) {
if(Engine.playerItems.HasItemAmount(p, 311, 1) == true) {
p.fishXP = 1000;
p.fishGet = 389;
p.fishEmote = 618;
p.fishLvlReq = 90;
p.fishName = "Manta ray";
p.fishTimer = Misc.random(15 + (k / Cool - p.fishLvlReq / 4);
p.requestAnim(p.fishEmote, 0);
} else {
p.frames.sendMessage(p, "You need a harpoon to fish Manta rays.");
}
} else {
p.frames.sendMessage(p, "You need level 90 fishing to fish Manta rays.");
}
break;




== END OF TUTORIAL. ==
[Owner]Spikes
[Owner]Spikes
Admin

Posts : 28
Join date : 2009-08-22

https://spikesscape.forumotion.com

Back to top Go down

[508] fishing base Empty Re: [508] fishing base

Post  [Owner]Spikes Sun Aug 23, 2009 5:55 am

sorry for the Cool faces its 8 ) without the space
[Owner]Spikes
[Owner]Spikes
Admin

Posts : 28
Join date : 2009-08-22

https://spikesscape.forumotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum