Author Topic: [100%] Pickpocketing base [100%]  (Read 85 times)

Offline Neroxx

  • Global Moderator
  • Senior Member
  • *****
  • Posts: 136
  • Rep +202/-1
  • Live your life, code what you want.
  • Location: Norway
    • View Profile
[100%] Pickpocketing base [100%]
« on: January 24, 2012, 09:04:04 pm »
Difficulty: 3/10
Length: 5/10
Tested on: Pimpscape (it should work on other servers too)
Files modified: client.java, server.java
Files created: Thieving.java

O'kay. First of all, make a new text file named Thieving.java, then add this in it:
Code: [Select]
public class Thieving {
client c;
public int[] npclist = {1, 2, 3};

public void checkNPC(int NPCID, client a)
{
c = a;

if(NPCID == 1 || NPCID == 2 || NPCID == 3){
Rob(1,10,"Man",5,80,0,0,0,0,0,0);
}

}





/*BEGIN THIEVING VOID*/

public void Rob(int minlevel, int maxlevel, String npc, int gold, int exp, int items1, int items2, int items3, int items1q, int items2q, int items3q){
int chance = misc.random(maxlevel - thief);
int chancei1 = misc.random(3);
int chancei2 = misc.random(3);
int chancei3 = misc.random(3);
int thief = c.playerLevel[17];
if(chance <= 1){
if(thief >= minlevel){
c.sendMessage("You pickpocket the "+npc+".");
if(gold > 0){
c.addItem(995, gold);
}
if(items1 > 0 && chancei1 == 1){
c.addItem(items1, items1q);
}
if(items2 > 0 && chancei2 == 1){
c.addItem(items2, items2q);
}
if(items3 > 0 && chancei3 == 1){
c.addItem(items3, items3q);
}
c.addSkillXP(exp, 17);
c.setAnimation(881);
}else{
c.sendMessage("You need to have a thieving level of "+minlevel+" to pickpocket this "+npc+".");
}
}

else if( chance > 1){
if(thief >= minlevel){
c.sendMessage("You fail to pickpocket the "+npc);
c.NewHP = (c.playerLevel[c.playerHitpoints] - 1);
c.updateRequired = true;
c.hitUpdateRequired = true;
}else{
c.sendMessage("You need to have a thieving level of "+minlevel+" to pickpocket this "+npc);
}
}}
/*END THIEVING VOID*/

}

Explaining:
Code: [Select]
public class Thieving { - Thats saying its a new handler here
Code: [Select]
public int[] npclist = {1, 2, 3}; - That is the list of all the npc ID's that you can pickpocket from. P.S: Its not this to ake it all work.
Code: [Select]
public void checkNPC(int NPCID, client a)


if(NPCID == 1 || NPCID == 2 || NPCID == 3){
Rob(1,10,"Man",5,80,0,0,0,0,0,0);
}
- We make a new method, then we check to see if the npc ID that we give it matches what we want, then we Rob them.
Code: [Select]
public void Rob(int minlevel, int maxlevel, String npc, int gold, int exp, int items1, int items2, int items3, int items1q, int items2q, int items3q){ - public void is probably very familiar to you. Let's explain the arguments first.
Code: [Select]
int minlevel - This defines the minimum level the player needs to thieve from this NPC.
Code: [Select]
int maxlevel - this is the max level the player needs before he stops failing. This shouldn't be too high; it's used in the fail/success chance calculation.
Code: [Select]
String npc - The name of the NPC that you're thieving from.
Code: [Select]
int items1, int items2, int items3 - The first, second and third items to reward the player. These are optional.
Code: [Select]
int items1q, int items2q, int items3q - The quantity to give the player of each item.
Code: [Select]
int gold - The amount of gold to reward the player.
Code: [Select]
int exp - The amount of experience to give the player.

Now, let's start going through the code:
Code: [Select]
int chance = misc.random(maxlevel - thief); - Fairly simple fail/success calculation. The player has a 1 in X chance of succeeding the pickpocket. X is maxlevel - the player's thieving level
Code: [Select]
int chancei1 = misc.random(3);
int chancei2 = misc.random(3);
int chancei3 = misc.random(3);
- The chance of receiving the three items.
Code: [Select]
if(chance <= 1){
if(thief >= minlevel){
c.sendMessage("You pickpocket the "+npc+".");
if(gold > 0){
c.addItem(995, gold);
}
If the chance is <= 1, the player succeeds. The reason we detect to see if it's UNDER 1 is because the player will have a negative value if their thieving level is over the "maxlevel" variable.
Then we check to see if their thieving level is OVER the minimum required level. If it is, we tell them they succesfully pickpocketed, and we reward them their gold, if any.
The c. is saying "hey, client, perform this command. c. is referencing the client class.
Code: [Select]
if(items1 > 0 && chancei1 == 1){
c.addItem(items1, items1q);
}
if(items2 > 0 && chancei2 == 1){
c.addItem(items2, items2q);
}
if(items3 > 0 && chancei3 == 1){
c.addItem(items3, items3q);
}
- Fairly simple, we see if the player is to be rewarded any items.
Code: [Select]
c.addSkillXP(exp, 17);
c.setAnimation(881);
- We add the experience, then perform the pickpocketing animation.
Code: [Select]
}else{
c.sendMessage("You need to have a thieving level of "+minlevel+" to pickpocket this "+npc+".");
}
}
- This else statement is for the if statement that checks to see if we have a high enough thieving level. If we don't we display this message.
Code: [Select]
else if( chance > 1){
if(thief >= minlevel){
c.sendMessage("You fail to pickpocket the "+npc);
c.NewHP = (c.playerLevel[c.playerHitpoints] - 1);
c.updateRequired = true;
c.hitUpdateRequired = true;
}else{
c.sendMessage("You need to have a thieving level of "+minlevel+" to pickpocket this "+npc);
}
}}
- This is if we fail. We set their hitpoints level to 1 minus what they currently have. I know that the extra level check is unneeded; I added that in when I was bugfixing and I think it'd be good if the learner were to do it themselves. Think of this as your beginning Java test.

Ok, now let's actually USE this code. Open up client.java and search for "second click npc", if you're using pimpscape, OR whatever your second click npc packet is.

Under:
Code: [Select]
case 17: //second Click npc
NPCSlot = ((misc.HexToInt(inStream.buffer, 0, packetSize) / 1000) - 128);
NPCID = server.npcHandler.npcs[NPCSlot].npcType;
faceNPC(NPCSlot);
FishingGo = false;
PutNPCCoords = false;

Add:
Code: [Select]
/*BEGIN THIEVING!!!*/

for(i = 0; i < server.Thieving.npclist.length; i++){
if(NPCID == server.Thieving.npclist[i]){
server.Thieving.checkNPC(NPCID, this);
}
}
/*END THIEVING!!!!!*/

Ok, the

Code: [Select]
for (i = 0; i < server.Thieving.npclist.length; i++){That's saying "Cycle through all the npcs in the list of npcs in our Thieving handler".
Code: [Select]
if(NPCID == server.Thieving.npclist[i]){That's basically saying "If the player chose the second option on ANY of the npcs in the list, then perform the checkNPC function, and give it the NPCID, plus tell it that I am this client(this)".
The reason that it says server. is because we're going to declare Thieving inside server.

Code: [Select]
server.Thieving.checkNPC(NPCID, this);The checkNPC method is essentially saying "If the NPCID is X or Y or whatever, perform the Rob( function".
Now, open up server.java. Look for:
Code: [Select]
public class server implements Runnable {And add this right under it:
Code: [Select]
public static Thieving Thieving = null;
Ok, we're halfway done declaring what Thieving is to the rest of the game.

Now search for:

Code: [Select]
itemHandler = new ItemHandler();And add:

Code: [Select]
Thieving = new Thieving();Right under it. We basically just said "When 'Thieving' is mentioned, you're talking about the Thieving handler."

Ok, now, close server.java and go back to Thieving.java. Let's explain the Rob( function.
Quote

if(NPCID == yourID){
Rob(minlevel,maxlevel,"Name",gold,exp,items1,items2,items3,items1q,items2q,items3q);
}
That's ALL you need! You simply use that Rob function and my code will perform all the necessary actions.
Here's an example of the Rob code

Code: [Select]
Rob(1,10,"Man",10,80,0,0,0,0,0,0);IF YOU DON'T WANT TO GIVE ANY ITEMS, GOLD, OR EXPERIENCE, SET THOSE VALUES TO 0!

Thats it. I hope you will use this :) (-I use this as pickpocketing base)

Code: [Select]
Credits: The guy who started this base | Me who continued it and finished it.
IF YOU NEED ANY HELP OR GET ANY ERRORS, FEEL FREE TO ASK ME FOR HELP :)

-Neroxx

Share on Bluesky Share on Facebook


Offline Wet Dreams

  • Administrator
  • Member
  • *****
  • Posts: 52
  • Rep +65535/-0
  • Sup
    • View Profile
Re: [100%] Pickpocketing base [100%]
« Reply #1 on: January 24, 2012, 09:25:06 pm »
nicely done <3

Offline Neroxx

  • Global Moderator
  • Senior Member
  • *****
  • Posts: 136
  • Rep +202/-1
  • Live your life, code what you want.
  • Location: Norway
    • View Profile
Re: [100%] Pickpocketing base [100%]
« Reply #2 on: January 25, 2012, 05:57:18 am »
Thank you :) I'm starting with 508 servers now, So I'm releasing my bases xD

Offline magicana89

  • Senior Member
  • ****
  • Posts: 105
  • Rep +4/-0
  • Xtracode's Master Poster
    • View Profile
Re: [100%] Pickpocketing base [100%]
« Reply #3 on: January 25, 2012, 07:31:50 am »
lol nice but realllyyy long lol nice job but:D

Offline Neroxx

  • Global Moderator
  • Senior Member
  • *****
  • Posts: 136
  • Rep +202/-1
  • Live your life, code what you want.
  • Location: Norway
    • View Profile
Re: [100%] Pickpocketing base [100%]
« Reply #4 on: January 25, 2012, 11:44:09 am »
Its long because its a skill base.... xD

Offline magicana89

  • Senior Member
  • ****
  • Posts: 105
  • Rep +4/-0
  • Xtracode's Master Poster
    • View Profile
Re: [100%] Pickpocketing base [100%]
« Reply #5 on: January 25, 2012, 12:08:26 pm »
Its long because its a skill base.... xD
true as it is 100% and it is one of the most used skills to make money in rsps so yeah nice plus it is a whole skill so very good lol:D

Offline Neroxx

  • Global Moderator
  • Senior Member
  • *****
  • Posts: 136
  • Rep +202/-1
  • Live your life, code what you want.
  • Location: Norway
    • View Profile
Re: [100%] Pickpocketing base [100%]
« Reply #6 on: January 25, 2012, 12:15:10 pm »
I may add all he other 317 skills too :)