[TUT 503] Player vs Player(Melee)

Junior Spellweaver
Joined
Aug 12, 2006
Messages
115
Reaction score
2
BEFORE YOU ATTEMPT TO TRY THIS OUT , PLEASE MAKE A BACKUP!!!

Add this to Player.java
Code:
    public void applyDead()
    {
        if(deathDelay == 8)
        {
            if(faceToRequest != 65535)
            {
                requestFaceTo(65535);
            }
            requestAnim(836, 0);
        }
        if(deathDelay <= 1)
        {
            frame.sendMessage(this, "Oh dear you are dead!");
            isDead = false;
			attackPlayer = 0;
			attackingPlayer = false;
            teleportToX = 3200;
            teleportToY = 3200;
            for(int i = 0; i < skillLvl.length; i++)
            {
                skillLvl[i] = getLevelForXP(i);
                frame.sendSkillLvl(this, i);
            }
            subtractDamage(999999);
            requestAnim(-1, 0);
        }
    }
Add this under process:
Code:
        if(isDead && deathDelay >= 0)
        {
            deathDelay--;
            applyDead();
        }
		if(attackingPlayer == true)
        {
            PlayerAttack pl = new PlayerAttack(this);
            pl.attackPlayer();
            //pl = null;
        }
add under process:
Code:
		if (combatDelay > 0) {
			combatDelay--;
		}


Make a new class called PlayerAttack.java and add this in there(into players folder)
Code:
package RS2E.Players;

import RS2E.*;

public class PlayerAttack
{
	public PlayerAttack(Player _p)
	{
		p = _p;
	}

    public void attackPlayer()
    {
		if(p == null || p.disconnected[0] || p.isDead)
        {
            return;
        }
		if(p.faceToRequest != (p.attackPlayer + 32768))
		{
			p.requestFaceTo(p.attackPlayer + 32768);
		}
		int wepId = p.equipment[3];
		Player plr = GameEngine.players[p.attackPlayer];
		int hitDiff = random(getMeleePower());
		if(p.combatDelay <= 0) {
			if(GameEngine.getDistance(plr.absX, plr.absY, p.absX, p.absY) != 1)
			{
				return;
			}
			p.requestAnim(getItemAttack(wepId), 0);
			plr.killedBy[p.playerId] += hitDiff;
			plr.appendHit(hitDiff, 0);
			p.attackPlayer = plr.playerId;
			p.attackingPlayer = true;
			if (plr.attackRetaliate)
			{
				if(plr.faceToRequest != (plr.attackPlayer + 32768))
				{
					plr.requestFaceTo(plr.attackPlayer + 32768);
				}
				plr.attackPlayer = p.playerId;
				plr.attackingPlayer = true;
			}
			p.combatDelay = getCombatDelay(wepId);
	    if(p.skillLvl[3] <= 0)
        {
            p.isDead = true;
            p.deathDelay = 5;
            if(plr.faceToRequest != 65535)
            {
                plr.requestFaceTo(65535);
            }
        }
		}
	}
    public int getMeleePower()
    {
        if(p == null)
        {
            return 1;
        }
        double maxHit = 1.06 + (p.equipmentBonus[10] * p.skillLvl[2]) * 0.00178;
        if(fullDharokEquipped())
        {
            maxHit += (p.getLevelForXP(3) - p.skillLvl[3]) / 2;
        }
        return (int)(maxHit += p.skillLvl[2] * 0.16);
    }
	public void resetAttack()
	{
		if(p == null)
		{
			return;
		}
		p.attackingPlayer = false;
		p.attackPlayer = 0;
	}
	public int getItemAttack(int ID)
	{
		String weapon = GameEngine.item.getItemName(ID);
		if (weapon.equalsIgnoreCase("Unarmed"))
		{
			return 422;
		}
		if (weapon.endsWith(" godsword")) {
			return 7041;
		}
		return 422;
	}
	public int getCombatDelay(int ID)
	{
		String weapon = GameEngine.item.getItemName(ID);
		if (weapon.equalsIgnoreCase("Unarmed"))
		{
			return 5;
		}
		if (weapon.endsWith(" godsword")) {
			return 7;
		}
		return 5;
	}
	
    private int random(int range)
    {
        return (int)(Math.random() * (range + 1));
    }
	
    public boolean fullDharokEquipped()
    {
        if(p == null)
        {
            return false;
        }
        return (p.equipment[0] == 4716 && p.equipment[4] == 4720 && p.equipment[7] == 4722 && p.equipment[3] == 4718);
    }
	private Player p;
}
Add these to PlayerInstances:
Code:
	public boolean attackingPlayer = false;
	public boolean attackRetaliate = true;
	public int attackPlayer = 0;

	public int combatDelay = 0;
It only does unarmed attack and godsword attacks


add this at the top of handlepacket:
Code:
import RS2E.Players.PlayerAttack;
add this in GameEngine:
Code:
    public static int getDistance(int coordX1, int coordY1, int coordX2, int coordY2)
    {
        int deltaX = coordX2 - coordX1;
        int deltaY = coordY2 - coordY1;
        return ((int)Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)));
    }

Heres the packet
Code:
		case 255: // Attack Player.
			if(p == null) {
				return;
			}
			p.attackPlayer = p.inStream.readUnsignedWordBigEndianA();
			PlayerAttack pl = new PlayerAttack(p);
			pl.attackPlayer();
			p.attackingPlayer = true;
			pl = null;
            break;

Replace case 75 with this:
Code:
        case 75: //Other click walk.
            Walk walk = new Walk(p, packetId, packetSize);
            walk = null;
			p.attackingPlayer = false;
			p.attackPlayer = 0;
            break;

THIS TUTORIAL HAS BEEN MADE BY AlexMason FROM RUNE-SERVER . ALL CREDITS TO AlexMason.
 
now thier was a tut for 1vs1 pking but u cant Do it i tryed to a add to my server but it says somthing about no victim class or sum ****! but bascialy if u could release a 1v1 pking or a Freedule or Staking! code before i can That would be greatly appeciated! if not ill finish mine in next 2 weeks! im still decideding if i wanna release all my Work! i have been working on for 3years now straight coding!


but very Nice tut bud! many new people could use this!
 
Last edited:
Its for 503 server tho .

Don't know if you knew that .
I think it will not work on 317/377

But I got it working on my 503.

Also I have dueling in dueling arena.
But I'm not allowed to release that.
 
Its for 503 server tho .

Don't know if you knew that .
I think it will not work on 317/377

But I got it working on my 503.

Also I have dueling in dueling arena.
But I'm not allowed to release that.

ow for real na i respect that bud defently! um i didnt know it was for only 503 server... lol sorry.. um ok well if need help coding sumthing let me know ok! i can have the code finished in a day or 2 max im currently working on Clan chat/Massive Quest free quest and member quest!


should be done also made a pking Shop that subtracts from yr pking pkts that u get so basically this is how it goes


dima mees00 Kills jdjdj 10pk pkts +++ect

then goto type in pkshop a box comes up and u can pick from items depending on yr pk pkts

pretty sick huh let me know i could add in yr server! very helpfull all players love it! im pretty dam sure im first one that has done this!
 
I have Assault minigame , basically coded the same way as your PK.
You kill - you get points - you can trade them for points.
 
I have Assault minigame , basically coded the same way as your PK.
You kill - you get points - you can trade them for points.

ya thats sick im about to code some sick minigames too! whats the name of yr server bud? mines Questscapev2

 
I haven't thought about the name yet , It's RuneScape v1.9 now atm.
 
I haven't thought about the name yet , It's RuneScape v1.9 now atm.

hmmm Runescape The Return of the Dead! lol just a lil example lol screwing around


well do u guys need any help? coding it or wat not i own a couple Dedicated server lines with 2teribite connection aka(2000gb bandwith)wth 3gb ram and Quadintelrprocessors 3.4ghz let me know we can probably help u out or somthing!
 
Back