Hello there. It might be the first time posting here so please forgive me if i do something wrong.
I am using one of the latest revisions of the L2JServer for H5 Chronicle with some custom things i have made so far on my own.
Sorry but i still can't figure out how to report the revision of the datapack and core!
The thing is that i want to change the level of a monster (only an instance of it) for an event i'm creating. For what i've checked so far i cannot find a "setLevel()" method on any of the classes assosiated with L2Npc and the only solution seems to be to set a new StatsSet to the L2NpcTemplate object. Still i cannot find a way to get this StatsSet without changing any of the core code.
Being a Java developer for years and years i can program lots of things but when it comes to that big projects i want an experts opinion before changing anything.
Just to sum up the question: " Is there a way to change the level of an Instance of monster from code? "
Thanks in advance.
Changing level of a monster from code.
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
-
- Posts: 12
- Joined: Thu Feb 03, 2011 10:34 am
Changing level of a monster from code.
Java and Android Developer.
New in L2J Development. Work in progress
New in L2J Development. Work in progress
- Avanael92
- Advanced User
- Posts: 189
- Joined: Thu Aug 07, 2014 5:26 pm
- Location: Germany
Re: Changing level of a monster from code.
You can create custom NPC mobs based on XML in data/stats/npcs/custom, even the same ones with different IDs and levels, then you only have to spawn them from code
In case you don't know already, you have to enable to allow custom settings in config which is inside the General.properties.
In case you don't know already, you have to enable to allow custom settings in config which is inside the General.properties.
-
- L2j Senior Developer
- Posts: 795
- Joined: Sun Aug 14, 2005 11:27 am
Re: Changing level of a monster from code.
There is a way and that is, as you found out already, through the StatsSet. The Problem with an NPC is that it's level is always the one in the template and a template is immutable. The StatsSet is loaded into the template fields and then the StatsSet is not stored, that is why you can't get a stats set from a template.
In L2Character, you have the setTemplate method. Here you can replace the current L2NpcTemplate with a new one. So you would have to construct it using a StatsSet in the same way as the code which loads the templates from the xml files.
You probably also need to refresh the NpcStatus (HP MP etc.) object of the npc in case you want the current vital status of the npc to change. Additionally you need to broadcast the NPC info when you are done, so the changes are reflected to the players around.
To sum it up: The current implementation doesn't allow NPCs to level up and thus needs some manual work to accomplish this.
In L2Character, you have the setTemplate method. Here you can replace the current L2NpcTemplate with a new one. So you would have to construct it using a StatsSet in the same way as the code which loads the templates from the xml files.
You probably also need to refresh the NpcStatus (HP MP etc.) object of the npc in case you want the current vital status of the npc to change. Additionally you need to broadcast the NPC info when you are done, so the changes are reflected to the players around.
To sum it up: The current implementation doesn't allow NPCs to level up and thus needs some manual work to accomplish this.
Away cause of a bulding side in my place.
H5 GeoData from Nos & FBIagent
GoD Ch3 Lindvior GeoData from Nos & FBIagent
Yet another Buffer (Freya & HighFive)
Party Teleporter (Freya & HighFive)
FBIagent
H5 GeoData from Nos & FBIagent
GoD Ch3 Lindvior GeoData from Nos & FBIagent
Yet another Buffer (Freya & HighFive)
Party Teleporter (Freya & HighFive)
FBIagent
-
- Advanced User
- Posts: 1440
- Joined: Wed Apr 15, 2009 10:07 am
Re: Changing level of a monster from code.
That would be nice to have in order to make mobs scale with the level of the player.
-
- Posts: 12
- Joined: Thu Feb 03, 2011 10:34 am
Re: Changing level of a monster from code.
Well i found out a solution that doesn't involve all these actions that HorridoJoho said are needed.
As for the answer that Avanael92 gave me, i prefer to change it dynamically, not have them static in xmls.
You have to add this method to the L2NpcTemplate class anywhere you want (ok after getLevel() method is alright).
Once you do that then you have to create an L2Spawn object and then get the template and set the level.
and then you have a monster of the level you want.
This way you can create dynamic mobs based on the templateId you can add (same as setLevel but you have to add it) and more.
Changing the stats of an Npc seems to be harder though because of the immutable HashMaps used to define them. So changing the level only is not gonna give you the results you want. I'm still working on it.
@HorridoJoho, i think that broadcasting the change won't have any effect. Once the mob is spawned and a player teleports near it, the player already has the info about the npc.
As for the answer that Avanael92 gave me, i prefer to change it dynamically, not have them static in xmls.
You have to add this method to the L2NpcTemplate class anywhere you want (ok after getLevel() method is alright).
Code: Select all
public void setLevel(int level)
{
_level = (byte) level;
}
Code: Select all
L2Spawn mySpawn = new L2Spawn(npc_id);
mySpawn.getTemplate().setLevel(level_prefered);
SpawnTable.getInstance().addNewSpawn(mySpawn, //prefered option true or false // read documentation);
mySpawn.init();
This way you can create dynamic mobs based on the templateId you can add (same as setLevel but you have to add it) and more.
Changing the stats of an Npc seems to be harder though because of the immutable HashMaps used to define them. So changing the level only is not gonna give you the results you want. I'm still working on it.
@HorridoJoho, i think that broadcasting the change won't have any effect. Once the mob is spawned and a player teleports near it, the player already has the info about the npc.
Java and Android Developer.
New in L2J Development. Work in progress
New in L2J Development. Work in progress
-
- L2j Senior Developer
- Posts: 795
- Joined: Sun Aug 14, 2005 11:27 am
Re: Changing level of a monster from code.
Yes it is possible by adding a L2NpcTemplate#setLevel method, but that would change the level for all NPCs having the same template. I'd rather would change the logic of NpcStat#getLevel and L2Npc#getLevel. Both currently return the level from the template.
The proper way would be to use the _level field in the CharStat class:
- Remove the method NpcStat#getLevel
- In NpcStat#NpcStat call setLevel(activeChar.getTemplate().getLevel()) after the super call
- Modify the L2Npc#getLevel method to return NpcStat#getLevel
- Add a L2Npc#setLevel method which calls NpcStat#setLevel
I am not entirely sure about that but keep in mind that the level change is not automatically broadcast to nearby players. If there are any visual indicators about the level of the NPC, a broadcast is needed for sorrounding pleayer so thoose visual indicators are also updated.
---
When you want to modify the NPC stats, you need to tinker with the Stat calculators. They are stored inside the L2Character. It is an array which maps to the ordinaries of the Stat enum fields. One idea could be to scale the base stats by doing something like:
Code: Select all
npc.getTemplate().getPAtk() * npc.getLevel() / npc.getTemplate().getLevel()
Away cause of a bulding side in my place.
H5 GeoData from Nos & FBIagent
GoD Ch3 Lindvior GeoData from Nos & FBIagent
Yet another Buffer (Freya & HighFive)
Party Teleporter (Freya & HighFive)
FBIagent
H5 GeoData from Nos & FBIagent
GoD Ch3 Lindvior GeoData from Nos & FBIagent
Yet another Buffer (Freya & HighFive)
Party Teleporter (Freya & HighFive)
FBIagent