Jump to content
  • 0

[Help] Pvp points from Mobs


Question

Posted

Hello i have pvp points on my server. From each killed pleyera gets his 10% pvpPoints and that points has stored in db new column in characters

Wanna know how to add these points to the mobs and get them together with exp and sp.

but if exp is set to 7000 is a mob would give me 7 pvppoints.

hope u understand me cuz my english is more funny than the understandable.

Recommended Posts

  • 0
Posted

Have a little free time in work and for now have this

 

package com.l2jserver.gameserver.model.actor.instance;

import com.l2jserver.gameserver.instancemanager.RaidBossPointsManager;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Summon;
import com.l2jserver.gameserver.model.entity.Hero;
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
import com.l2jserver.util.Rnd;

/**
* This class manages special pvpkill rewards mobs.
*/
public class L2PvpMobInstance extends L2MonsterInstance
{
public L2PvpMobInstance(int objectId, L2NpcTemplate template)
{
	super(objectId, template);
	setInstanceType(InstanceType.L2PvpMobInstance);
}

/**
* Manages the doDie event<BR><BR>
*
* @param killer The L2Character that killed this instance.<BR><BR>
*/
@Override
public boolean doDie(L2Character killer)
{
	if (!super.doDie(killer))
		return false;
	L2PcInstance player = null;  				    // check if the killer is different of null (to avoid NPE error)			

		if  (killer instanceof L2PcInstance)   		// check if the killer was a player or a summon
			player = (L2PcInstance) killer;
		else if (killer instanceof L2Summon)
			player = ((L2Summon) killer).getOwner();// if killer is a summon, redirect to a L2PcInstance type
		{											// do a custom calcul using mob level
													// add the custom calcul result to the L2PcInstance total pvp points
			if(player != null)						// if killer is a player
			{										
				if (player.getParty() != null)
				{
					for (L2PcInstance member : player.getParty().getPartyMembers())
					{ 								 //here calculate for party (Right)?
				}
			}
		}

		if											// do a custom calcul using mob level
		{											// add the custom calcul result to the L2PcInstance total pvp points

		}
	}









	return true;
}
}

 

need to add calculate, can use your calculate but when i back from work ;]

  • 0
Posted

Well, it's the begin... I won't cry for now :P.

 

All my comments are right, so if there is an "if", be sure to make a "if" check :P. I refer to :

 

L2PcInstance player = null;

 

Which isn't a check at all :P. The concerned check is a check on killer. But you're right, you have to initialize a L2PcInstance type (could be the same name, killer, but player is fine as well).

 

You're right about the summon check, good hit :).

 

My imbricated "if" example was AN EXEMPLE, don't use it. Just inspire from it. The good path to follow is the commentaries one, coded just top of the if example.

 

When you do a commentary do like that :

 

//A commentary
if blablabla
{
   //result
   result
}

 

Using tabulations. Because the code you show is perfectly messed in presentation and pretty hard to read. I made efforts in my last post, do the same :P.

 

What about the GetParty ? You hope to share pvp points between party members ? The idea could be good if it was xp, but pvppoints... Lol :). Except you got another idea, you haven't to use it.

 

I let you time to upload a decent code ^^.

 

And take care about {   }, you miss some.

  • 0
Posted

Ok party deleted. That is black magic for me but all time learning abut java.

 

	/**
* Manages the doDie event<BR><BR>
*
* @param killer The L2Character that killed this instance.<BR><BR>
*/
@Override
public boolean doDie(L2Character killer)
{
	if (!super.doDie(killer))
		return false;
	L2PcInstance player = null;  				    // check if the killer is different of null (to avoid NPE error)			

		if  (killer instanceof L2PcInstance)   		// check if the killer was a player or a summon
			player = (L2PcInstance) killer;
		else if (killer instanceof L2Summon)
			player = ((L2Summon) killer).getOwner();// if killer is a summon, redirect to a L2PcInstance type
			{											// do a custom calcul using mob level
													// add the custom calcul result to the L2PcInstance total pvp points
			}						// if killer is a player
				if	(player != null)									// do a custom calcul using mob level
					{											// add the custom calcul result to the L2PcInstance total pvp points
						addPvpPoints (player, getNpcId(), (getLevel()-79*2));
					}
				{
		return true;
	}
}

/**
 * @param player
 * @param npcId
 * @param i
 */
private void addPvpPoints(L2PcInstance player, int npcId, int i)
{
	// TODO Auto-generated method stub

}
}

 

 

  • 0
Posted

You don't specialy need to create a void method addPvpPoints neither :P.

 

Try to complete/correct all checks first. It's like my last post was nothing :'(.

 

Try to post when you think you completed all, we will correct together. Because if I correct each time you post, this topic will be 1000 pages long :D.

 

Before L2PcInstance player = null;, you have to put the // check if the killer is different of null (to avoid NPE error) + the check ofc... I prefer say that if you think adding only the comment..

 

About the mob lvl calcul you don't need nothing special more than doing :

 

numberToAdd = (getLevel()-79)*2;
And add numberToAdd to pvp total of "player", like you did in your player vs player code.

 

I don't get why you do 500 methods :P. Circling the calcul, you only have some checks to made, and I put them all in //comments.

  • 0
Posted

tell me if that is right

 

 L2PcInstance player = (L2PcInstance) killer;
          if (killer != null)			    // check if the killer is different of null (to avoid NPE error)

  • 0
Posted

I read your PM, all i can say is try it more :P. If you want to pay for something as simple as that, you should forget to develop at all. Plus, that won't correct your errors in your future programs.

 

Why to give a man a fish when you can give him a polefish, well you got it.

 

I agree there is some difficulties, but all my answers were helpfull and made 50% of the work (logical parts are made, you just have the copy/paste work).

 

You are better than many of self-calling L2J developers aswell. Just try harder, and give me a decent code (even bugged, i don't care) but with all supposed checks made. Don't give me piece per piece, as I said it could make the thread 5000 posts.

 

----

 

And this null check about killer means : if L2Character killer is different of nothing. Your exemple is wrong in the way than the null check is useless, and you can have NPE error (when this check exists to avoid it).

 

An NPE error occurs when the asking object (in this exemple, L2Character killer) is empty. It can happens very rarely (exemple, you disconnect, so instance doesn't exist anymore), but it can happens, and the result is a NullPointerException (aka a NPE). To avoid that, we check before all things if killer is null.

 

If killer isn't empty, we continue the program, else we skip.

 

Try to include too my last code as calculation method.

 

You can compare with the existing files too. You have 12xx files to help you. Try to find another null check for killer (search tool for eclipse = ctrl+F), and see what happens in others files and adapt it for your case.

  • 0
Posted

Now this I am afraid to write anything. ;] Examined the other files and came to me something like that:

 

package com.l2jserver.gameserver.model.actor.instance;

import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Summon;
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;

/**
* This class manages special pvpkill rewards mobs.
*/
public class L2PvpMobInstance extends L2MonsterInstance
{
public L2PvpMobInstance(int objectId, L2NpcTemplate template)
{
	super(objectId, template);
	setInstanceType(InstanceType.L2PvpMobInstance);
}

/**
* Manages the doDie event<BR><BR>
*
* @param killer The L2Character that killed this instance.<BR><BR>
*/
@Override
public boolean doDie(L2Character killer)
{
	if (!super.doDie(killer))
		return false;
	L2PcInstance player = null;

	if (killer instanceof L2PcInstance)
		player = (L2PcInstance) killer;
	else if (killer instanceof L2Summon)
		player = ((L2Summon) killer).getOwner();

	if (killer != null)
	{				
		numberToAdd = (getLevel()-79)*2;
			setPvpPoints(killer.getPvpPoints() + numberToAdd);	
	}						
	return true;
}
}

 

 

Very long I sat there and read other server files. Please answer, write that everything is bad, or just have errors. currently does not work after compiling.

 

(and pls write where im wrong)

 

 

 

  • 0
Posted

My first squeleton was "wrong" (well too much codes). The light version is shown in this one, don't refer to the first squeleton.

 

Use comments from my code squeleton.

 

I said to you the killer check is the first. You use

 

		if (killer instanceof L2PcInstance)
		player = (L2PcInstance) killer;
	else if (killer instanceof L2Summon)
		player = ((L2Summon) killer).getOwner();

 

Which itself is a good code, but what about if killer == null in this case ? You got a NPE error.

 

You have to circling each lower comment by upper levels. I give you the first 2 checks from my squeleton, and organize your check as the 3rd check :

 

	/**
* Manages the doDie event<BR><BR>
*
* @param killer The L2Character that killed this instance.<BR><BR>
*/
@Override
public boolean doDie(L2Character killer)
{
	if (!super.doDie(killer))
		return false;

	L2PcInstance player = null;

	// check if the killer is different of null (to avoid NPE error)
	if (killer != null)
	{
		// check if the killer was a player or a summon, because L2Character can be many things.
		if (killer instanceof L2PcInstance || killer instanceof L2SummonInstance)
		{
			if (killer instanceof L2PcInstance)
				player = (L2PcInstance) killer;
			// if killer is a summon, redirect to his owner
			else if (killer instanceof L2Summon)
				player = ((L2Summon) killer).getOwner();

			// do a custom calcul using mob level

			// add the custom calcul result to the player total pvp points

		}						
	return true;
}

 

I explain something more, try to understand :

 

The goal is to aim with efficiency what instance is the "killer". L2Character is too much as it can be around 6 differents type of things, including L2PcInstance (players) and L2SummonInstance (their summons).

 

When you do this sort of check :

 

			if (killer instanceof L2PcInstance)
			player = (L2PcInstance) killer;

 

You are saying :

if the L2Character instance named "killer" is a L2PcInstance,

"killer" is a player instance, and stored in "player" variable.

 

About "player" variable you initialized it yourself, perhaps without understanding what is it :

 

L2PcInstance player = null;

 

With that code you initialize a variable named "player", with is a part of L2PcInstance, and which is null.

 

Why to create a null variable, when we try by all costs to remove all null checks ? Well if you take care of the code, you can understand we initialize a null variable but we fill it with data when we do that :

 

			if (killer instanceof L2PcInstance)
			player = (L2PcInstance) killer;

 

So if "killer" isn't null from the first check, that can only means "player" couldn't be too. As you use "killer" to fill "player". Got it ? It's logical.

 

I hope you get it from now, after all those instances morph, than you MUSTN'T use "killer", but "player" to make all your checks !

 

About my actual shared code, try to compile it, and give me eventual errors. About missing method etc, import good files and that's all. At worst there should have one, at best 0.

 

-----

 

About checks

 

The first check is a basic check, than many others methods got and must have. It's a security check to avoid NPEs. I hope you get it, at worst you can search NullPointerException over the internet, you will have results.

 

The second check is to "separate" our conditions. We need L2PcInstance and L2Summon, not others L2Character types. Imagine an aggressive door (o_____o). It's a L2Character. Imagine the door kills the mob (!!!!!!!!!!!!!). If this check isn't made, and as a L2Door is a part of L2Character, all things are calculated ! But, as a door desn't have pvp points it will throw an error for sure, and bug your gameserver. This is the reason of this check : avoid all L2Characters to be able to use this part of code, and restrains only for players and summons.

 

The third statement is a "organized" one. Both results, in any case, is the fill of "player" variable with something. But as a L2Summon is different from an L2PcInstance, and as you coded it (well, c/ped it :P), the calcul of player is different. The finality is the same, the ID number of this particular L2PcInstance.

 

----

 

About summons

 

Imagine a summoner kill with weapon someone. His ID is 666 (IDs aren't like that, just example). You ask the calcul of mob lvl, and then ask to the server to get pvpkills from L2PcInstance 666 and add the first calcul result to it.

 

Now a summoner got a summon, the summon kills someone. Both instances got their own IDs. But L2Summon is a L2Summon, we can't make comparison between 2 differents instances. We have to ask to the server who is the linked master. As this code already exists, we just use it. If ID of summon is 444 and L2PcInstance link master is 666, it sends back 666, which is a L2PcInstance variable and can be used in our calculs.

 

I hope you get i all, some things are more harder to understand than others, but now you're in the final part : mob level calcul, and add the result to the player pvpkills.

  • 0
Posted

 

 

@Override

public boolean doDie(L2Character killer) //here is a error <- eclipse quick fix say "this method must return as result of type boolean"

{

 

And calcul will be looks like:

 

numberToAdd = (getLevel()-79)*2;
setPvpPoints(killer.getPvpPoints() + numberToAdd);	

But in "numberToAdd" have always error and eclipse quick fix not help much. and i add msg.

 

killer.sendMessage("You have earned " + numberToAdd + " PvP Points");

 

msg working good but saying u have earned 0 pvp points ;/

  • 0
Posted

numberToAdd have to been initalized, in the same place where "player" is initialized.

 

http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

 

Here is a help about data types possibilities. In this case, this is an int. Check how variables are initialized in any files of L2J, they're basically at the top of the class.

 

Exemple in L2SiegeClan (this one because i'm working about).

// ===============================================================
// Data Field
private int _clanId        = 0;
private List<L2Npc> _flag  = new FastList<L2Npc>();
private int _numFlagsAdded = 0;

 

About boolean error, you surely missed the return true from my code. Normally my code can't have this error, so you missed something.

 

Last thing, why the fock are you using killer ? I said 2 times already (this is the third time) you mustn't use it to make your checks (only basic ones). What's wrong in my posts you don't understand ? Use the damn "player".

 

Very last thing, when you try to use

setPvpPoints(killer.getPvpPoints() + numberToAdd);

well first about "killer" use I hope for god's sake you finally understood what I said (else I'm gonna cry), second when you put this one, you will get error. Why ? Because your code will search the setPvpPoints method inside this instance (L2PvpMobInstance), when it's supposed to be stored in L2PcInstance (as your code have been copied/pasted from it). I let you search about, but it's really simple. Don't search very far. All you have to remember is this method is based on L2PcInstance, and we have defined one in our code (not killer, the other one you never use...).

 

 

And read my posts more than once time, because I feel like I post for nothing.

  • 0
Posted

I read a lot of times, but the little I understand, perhaps because of poorly know English and the translator translates strangely.

 

Nothing else I am doing just as I get back from work the whole time sitting in the eclipse and still make a difference in L2Character, L2PcInstance, L2PvpMobInstance

 

compiling, checking, changing, constantly trying to add something else to change.

  • 0
Posted

Wow im done it works corectly.  I think it works well but did little testing, the following points for every kill

 

Thank you very very very very very very very much. ;]

 

 

 

 

package com.l2jserver.gameserver.model.actor.instance;

import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Summon;
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;

/**
* This class manages special pvpkill rewards mobs.
*/
public class L2PvpMobInstance extends L2MonsterInstance
{
public L2PvpMobInstance(int objectId, L2NpcTemplate template)
{
	super(objectId, template);
	setInstanceType(InstanceType.L2PvpMobInstance);
}

/**
* Manages the doDie event<BR><BR>
*
* @param killer The L2Character that killed this instance.<BR><BR>
*/
@Override
public boolean doDie(L2Character killer)
{
	if (!super.doDie(killer))
		return false;

	L2PcInstance player = null;

	// check if the killer is different of null (to avoid NPE error)
	if (killer != null)
	{
		// check if the killer was a player or a summon, because L2Character can be many things.
		if (killer instanceof L2PcInstance || killer instanceof L2SummonInstance)
		{
			if (killer instanceof L2PcInstance)
				player = (L2PcInstance) killer;
			// if killer is a summon, redirect to his owner
			else if (killer instanceof L2Summon)
				player = ((L2Summon) killer).getOwner();

			{
				int numberToAdd = (getLevel()-79)*2;
				player.setPvpPoints(player.getPvpPoints() + numberToAdd);
				player.sendMessage("You have earned " + numberToAdd + " PvP Points");
			}
		}	

	}
	return true;
}
}

  • 0
Posted

Well done :) You saw, it was easy.

 

Remove both { }, it's used only if there was an if before.

 

You should declare numberToAdd in the top of the file too, but there is no real problem. It's just a convention.

 

int numberToAdd = 0;

 

Complete code :

 

package com.l2jserver.gameserver.model.actor.instance;

import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Summon;
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;

/**
* This class manages special pvpkill rewards mobs.
*/
public class L2PvpMobInstance extends L2MonsterInstance
{
public L2PvpMobInstance(int objectId, L2NpcTemplate template)
{
	super(objectId, template);
	setInstanceType(InstanceType.L2PvpMobInstance);
}

/**
* Manages the doDie event<BR><BR>
*
* @param killer The L2Character that killed this instance.<BR><BR>
*/
@Override
public boolean doDie(L2Character killer)
{
	if (!super.doDie(killer))
		return false;

	L2PcInstance player = null;
	int numberToAdd = 0;

	// check if the killer is different of null (to avoid NPE error)
	if (killer != null)
	{
		// check if the killer was a player or a summon, because L2Character can be many things.
		if (killer instanceof L2PcInstance || killer instanceof L2SummonInstance)
		{
			if (killer instanceof L2PcInstance)
				player = (L2PcInstance) killer;
			// if killer is a summon, redirect to his owner
			else if (killer instanceof L2Summon)
				player = ((L2Summon) killer).getOwner();

			// do a custom calcul using mob level
			numberToAdd = (getLevel()-79)*2;

			// add the custom calcul result to the player total pvp points and send a message
			player.setPvpPoints(player.getPvpPoints() + numberToAdd);
			player.sendMessage("You have earned " + numberToAdd + " PvP Points");
		}	
	}
	return true;
}
}

 

--------

 

About if, while, for, etc :

 

When you have only one thing, you can forget using {} :

			if (killer instanceof L2PcInstance)
				player = (L2PcInstance) killer;
			else if (killer instanceof L2Summon)
				player = ((L2Summon) killer).getOwner();

 

The next code is the same, but for me it's harder to read and very long :

 

			if (killer instanceof L2PcInstance)
			{
				player = (L2PcInstance) killer;
			}
			else if (killer instanceof L2Summon)
			{
				player = ((L2Summon) killer).getOwner();
			}

 

The use of {} is needed when your if got many results. You can't remove them else it will bug.

 

----

 

After all that, you can propose to make a diff patch about your work, in the developement section. Use [sHARE] as tag :).

  • 0
Posted

However I would like to add a party for supporters and healers, and when the party is exp points let them works on every party member.

 

And i [share] this like a diff and add 3 NPC 1; echange points for items (aromor, weapon)

2; exhcange items for points ex.(drop from RB 1 items give 500 pvp points)

3; wnat addd teleporter who tale u tp place when u have a number of points but they do not take <-- this need to thik about it.

  • 0
Posted

Well, this is work for sure :D.

 

First you should make a diff patch right now before doing all those things. You will have a secured copy of your work, if you fail in the future (like, a BIG fail) you would be happy to find a fresh clean custom code to apply it easily on a fresh L2J copy. You would be happy to know than my first project have failed because I hadn't any copy (around 1 month of work).

 

About NPC exchanger, I made one for my personal project, and which trade custom karma value for AA. So it's doable and I could help you when you have code. Ofc it's a new instance, you can name it L2PvPExchanger.

 

About party support, you will have to rewrite both your L2PcInstance and L2PvpMobInstance custom codes. The goal is to first pick up the L2PcInstance, second  is to pick the party of this L2PcInstance (or the party of the summoner's owner), and third to share experience / pvp points between them. About sharing pvp points, you have to use for. I'm too interested by this point, because I got others things to think about my project actually and I never checked it in depth.

 

Teleporter is the easiest thing. Instead of adena check, you put a getPvpKills check. Still, you have to create a new instance as L2PvpMob one. Would be L2PvPTeleporter, based on a clean copy of L2Teleporter.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...