Kronic-Scape
Click here to vote for kronic-scape!!

Join the forum, it's quick and easy

Kronic-Scape
Click here to vote for kronic-scape!!
Kronic-Scape
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[Glitch] My Big Idea List [Glitch]

3 posters

Go down

[Glitch] My Big Idea List [Glitch] Empty [Glitch] My Big Idea List [Glitch]

Post  Glitch Fri Feb 12, 2010 2:56 am

Welcome To My Big Idea List :
~ Achieve ~
1.0 - Proper Prayer Draining
1.1 - Correct Npc Attacking
~ End ~

(1.0) - Proper Prayer Draining

The drainage rate for prayer is the time in between each depletion of 1 prayer point from the player.

Each prayer has a set amount of prayer that it is supposed to deplete from the player, every <so many> seconds.

Below is an array containing the amounts depleted. These amounts have been changed so they all deplete these amounts every 12 seconds (They are for 12 seconds in the array so we don't have to store endless/recurring decimals in the array, and it will create these when we calculate the proper rate). The amounts in the array, divided by 12, will give you the amount that is depleted from the Player's prayer every second.

double[] prayerData = {
1, // Thick Skin.
1, // Burst of Strength.
1, // Clarity of Thought.
1, // Sharp Eye.
1, // Mystic Will.
2, // Rock Skin.
2, // SuperHuman Strength.
2, // Improved Reflexes.
0.4, // Rapid restore.
0.6, // Rapid Heal.
0.6, // Protect Items.
1.5, // Hawk eye.
2, // Mystic Lore.
4, // Steel Skin.
4, // Ultimate Strength.
4, // Incredible Reflexes.
4, // Protect from Summoning.
4, // Protect from Magic.
4, // Protect from Missiles.
4, // Protect from Melee.
4, // Eagle Eye.
4, // Mystic Might.
1, // Retribution.
2, // Redemption.
6, // Smite.
8, // Chivalry.
8, // Piety.
};

For example, if you were using only the steel skin prayer, your prayer would be depleted by 0.3(Recurring) every second (1 every 3 seconds). For every prayer the Player is using, you would divide the amount from the above array (for the appropriate prayer), divide it by 12, and add it to the Player's current prayer drainage rate.


However, this changes if the Player has a prayer bonus greater than 1.
The formula for adding the prayer bonus to the formula, is: drainRate x (1 + (0.035 x prayerBonus)).

So, for example, if you had a prayer bonus of 4, and you had a drainage rate of 2, the drainage rate would end up as 2.28. This would be the delay inbetween 1 point taken off the Player while he/she is using the prayer.



To use this in a private server, it is simple:

/**
* If the player is using the specific prayer.
* The order these are in should be used the same as the above array.
*/
boolean[] usingPrayer = new boolean[26];

/**
* Stores the amount of prayer points depleted every 12 seconds.
* This is divisible by 12 to get the amount of prayer depleted every second.
*/
double[] prayerData = {
1, // Thick Skin.
1, // Burst of Strength.
1, // Clarity of Thought.
1, // Sharp Eye.
1, // Mystic Will.
2, // Rock Skin.
2, // SuperHuman Strength.
2, // Improved Reflexes.
0.4, // Rapid restore.
0.6, // Rapid Heal.
0.6, // Protect Items.
1.5, // Hawk eye.
2, // Mystic Lore.
4, // Steel Skin.
4, // Ultimate Strength.
4, // Incredible Reflexes.
4, // Protect from Summoning.
4, // Protect from Magic.
4, // Protect from Missiles.
4, // Protect from Melee.
4, // Eagle Eye.
4, // Mystic Might.
1, // Retribution.
2, // Redemption.
6, // Smite.
8, // Chivalry.
8, // Piety.
};

/**
* Gets the drain rate.
* @param p the Player that the calculations are made for.
*/
double getDrainRate() {
double drainRate = 0;
final int PRAYER_BONUS = 11;

for (int i = 0; i < prayerData.length; i++) {
if (usingPrayer[i]) {
drainRate += prayerData[i] / 12;
}
}
if (drainRate != 0) {
drainRate = drainRate * (1 + (0.035 * equipmentBonus[PRAYER_BONUS]));
}
return drainRate;
}

The boolean array 'usingPrayer' is self explanatory. You would set the values within this array to true or false depending on whether the specific prayer is on or off.

I have already explained the 'prayerData' array and it's concepts; read above if you haven't already.

The 'getDrainRate()' double simply calculates the drainage rate from the formulas explained earlier on in this topic. It loops through all values in the usingPrayer array, and if the value equals true, then the drainage rate value for that prayer will be added to the drainage rate.


To use the getDrainRate() double, you could either used a 'processed' timer (Not recommended), or an event to make it so it depletes 1 prayer point from the Player, every amount of seconds that the getDrainRate() double returns.

(1.1) - Correct Npc Attacking

When you click to attack an NPC in DeltaScape, or any server for that matter (not sure about this), the NPC comes after you, no matter how far away you are. This will fix that.

tep 1: Declaring the Variables
Open up your Player.java class. Here is where you will declare two variables. First off, declare a public integer called targetNpc and set its value to 0. The purpose of this is to store the NPC slot in a variable so we know which NPC to attack and move towards.

Next, declare a public boolean called toAttackNpc and set its value to false. We need this to know whether or not we're still trying to attack an NPC. When we move away, this gets set to false.

In the end, it should've ended up looking like this.

public boolean toAttackNpc = false;
public int targetNpc = 0;


You're now done with Player.java.


Step 2: usingABow
This step is merely declaring a boolean that returns whether or not you're using a bow. Please note that I did not make this.

Open up client.java and at the top, add this.

public boolean usingABow()
{
if (playerEquipment[playerWeapon] == 839 || playerEquipment[playerWeapon] == 841 || playerEquipment[playerWeapon] == 843 || playerEquipment[playerWeapon] == 845 || playerEquipment[playerWeapon] == 847 || playerEquipment[playerWeapon] == 849 || playerEquipment[playerWeapon] == 851 || playerEquipment[playerWeapon] == 853 || playerEquipment[playerWeapon] == 855 || playerEquipment[playerWeapon] == 857 || playerEquipment[playerWeapon] == 837 || playerEquipment[playerWeapon] == 861 || playerEquipment[playerWeapon] == 4734 || playerEquipment[playerWeapon] == 859 || playerEquipment[playerWeapon] == 4827 || hasCrystalBow() || playerEquipment[playerWeapon] == 6522 || playerEquipment[playerWeapon] == 1381 || playerEquipment[playerWeapon] == 1383 || playerEquipment[playerWeapon] == 1385 || playerEquipment[playerWeapon] == 1387 || playerEquipment[playerWeapon] == 4675)
return true;

return false;
}

So, you added some code and don't know what is huh? Basically, it checks your weapon. If it equals one of the IDs mentioned in the boolean, it returns true. If your weapon does not equal one checked for, it tells the server you're not using a bow.


Step 3: Cleaning up and moving the Attack NPC packet (72)
This part is possible the hardest users will find. However, if you know how to cut and paste, it will be easy.

Start by declaring a method in client.java called attackNPC and set its parameters to int attackID. What you should eventually have it this.

public void attackNPC(int attackID)
{

}

I'll explain what this is for later.

Next step, search for "case 72:". This is the case for handling packet 72, Attack NPC. If you found the right one, you should see something like this.

attacknpc = inStream.readUnsignedWordA();

Now, with what we're about to do will clean this case up a lot. Start selecting everything after case 72: and select all the way down to the break; (Don't select the break; part) and copy it (Ctrl + C, or Right click > Copy, or Edit > Copy).

Next, go back up to the attackNPC method and paste it in. I don't know what your NPC attacking looks like, so I can't explain everything. But, I can explain why you did that and what to do from here.

After pasting the code in, I want you to delete the following line. The line that reads from the inStream. This is going to be read in the packet handling case.

Now replace any "break;"s in your attackNPC method with return; because we're no longer within a case. We want to exit out of the method instead.

Now go back to the Attack NPC packet handler, case 72. Delete everything in it (Except for the antiHax() for DeltaScape, or a deathStage check). Add the following to it.

targetNpc = inStream.readUnsignedWordA();
faceNPC(targetNpc);
toAttackNpc = true;

So what did that just do? The first line assigned 'targetNpc' to the NPC slot. Like I previously said, this is needed so we know which NPC we're after.

The second line makes us move towards the NPC, and instantly. Without this, we probably wouldn't end up moving towards it...

And finally, the last line tells the server we're trying to attack an NPC. Without this, you wouldn't attack it when you got up to it.

So, why did we do all that? We had to make it postpone the attack until we actually got there. This couldn't be done without calling the attack method separately, which is what we did here. We cleared the code out of case 72 because it was un-needed and everything we've done at this point wouldn't have made a different without it.


Step 4: Attacking the NPC when you get there
Well, now that Step 3 is over with, it's time to get back to the easy stuff. In client.java, go to your process boolean. If you can't find it, make sure you searched for this.

public boolean process()

Now below the first bracket, or maybe that line alone, you're going to add some code.

if(toAttackNpc == true)
{
NPC n = server.npcHandler.npcs[targetNpc];
if(GoodDistance(n.absX, n.absY, absX, absY, 1) && !usingABow())
{
attacknpc = targetNpc;
attackNPC(targetNpc);
targetNpc = 0;
toAttackNpc = false;
}
}

Now I'll explain what each bit does.

The first line checks if we're trying to attack an NPC. If we are, then it continues. The next part declares an NPC, which is actually the one we're attacking. It knows which one we tried to attack because of the '[targetNpc]' placed in the npcs array.

The next part checks the distance, which is the big fix here. It also checks if you're using a bow. If the distance between you and the NPC is 1 and you are NOT using a bow, it continues on and attacks the NPC.

The next part assigns which NPC you are attacking. Originally this was set in case 72 of the packet handling method, but we made it be set here. The next line tells us to attack the NPC we want to attack. This was the whole point of adding the method; so we could call it from somewhere else.

The next two lines just reset the two variables we declared earlier. This tells it we're not trying to attack it anymore.


Step 5: Chickening out
This is probably the shortest step next to step 1. It's also the final step. The purpose of this step is to make it so if we try to walk away from the NPC, it tells the server we don't want to attack it anymore.

In the packet handling method (where case 72 was), search for this.

case 98:

If it returns multiple results, it should say something about walking in the commenting.

Now right under the "case 98:" part, where it has other checks, add this code.

IsAttackingNPC = false;
attacknpc = -1;

This again, tells the server to reset the NPC attack. If you don't understand, read up.






Credits

- Primadude
- Lin

Glitch

Posts : 11
Join date : 2010-02-08

Back to top Go down

[Glitch] My Big Idea List [Glitch] Empty Re: [Glitch] My Big Idea List [Glitch]

Post  Amy(: Mon Feb 15, 2010 10:16 am

Looks like this is leeched from a different forum, I see that you gave credits but atleast give the forums That you took this from some credits aswell.
Amy(:
Amy(:

Posts : 49
Join date : 2010-02-09

Back to top Go down

[Glitch] My Big Idea List [Glitch] Empty Re: [Glitch] My Big Idea List [Glitch]

Post  Sean Mon Feb 15, 2010 10:18 am

Amy(: wrote:Looks like this is leeched from a different forum, I see that you gave credits but atleast give the forums That you took this from some credits aswell.

Don't be a hater.


Glitch..Try colouring it. There is too much text of the same colour and it's really confusing and hard to read.
Sean
Sean
Admin

Posts : 56
Join date : 2009-12-23

https://kronic-scape.darkbb.com

Back to top Go down

[Glitch] My Big Idea List [Glitch] Empty Re: [Glitch] My Big Idea List [Glitch]

Post  Amy(: Mon Feb 15, 2010 10:19 am

Not hating, Just giving some suggestions.
Amy(:
Amy(:

Posts : 49
Join date : 2010-02-09

Back to top Go down

[Glitch] My Big Idea List [Glitch] Empty Reply

Post  Glitch Mon Feb 15, 2010 2:18 pm

When i get around to it ill finish it off but firstly i was wondering what do you think if i post it all like this ? yes or no

Glitch

Posts : 11
Join date : 2010-02-08

Back to top Go down

[Glitch] My Big Idea List [Glitch] Empty Re: [Glitch] My Big Idea List [Glitch]

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


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