Запрещено публиковать исходный код без BB-кода — CODE.
- Хроники
- Interlude
- Исходники
- Присутствуют
- Сборка
- PW
Люди добрые помогите пожалуйста со скриптом не сохраняются скилы после релога ( все проверки отключены на левые скилы)
package calypso;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import net.sf.l2j.gameserver.datatables.SkillTable;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2VillageMasterInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2VillageMasterInstance.OnSubChangeListener;
import net.sf.l2j.gameserver.model.actor.player.OnPlayerEnterListener;
import net.sf.l2j.gameserver.model.actor.player.PlayerListenerList;
import scripts.items.IItemHandler;
import scripts.items.ItemHandler;
/**
*
* @author CalypsoToolz
*
*/
public class BuySkill implements OnPlayerEnterListener, OnSubChangeListener, IItemHandler {
private static final Map<Integer, L2Skill> MAP = new ConcurrentHashMap<>();
// разрешить использовать на саб-классе?
private static boolean ALLOW_ON_SUB = true;
static {
SkillTable st = SkillTable.getInstance();
// тут добавляем предмет и скилл
// MAP.put(ИД_ПРЕДМЕТА, st.getInfo(ИД_СКИЛЛА, ЛВЛ_СКИЛЛА));
MAP.put(10001, st.getInfo(1, 37));
}
@Override
public void useItem(L2PlayableInstance playable, L2ItemInstance item, boolean ctrl) {
if (playable.isPlayer()) {
L2PcInstance player = playable.getPlayer();
if (!ALLOW_ON_SUB && player.isSubClassActive()) {
player.sendCritMessage("Доступно только на основном классе!");
return;
}
if (player.destroyItemByItemId("UseItem", item.getItemId(), 1, null, true)) {
L2Skill skill = MAP.get(item.getItemId());
player.addSkill(skill, false);
player.sendCritMessage("Получен навык " + skill.getName());
player.setVar("ItemSkills#" + item.getItemId(), skill.getId() + ":" + skill.getLevel(), 0);
player.sendSkillList();
}
}
}
@Override
public int[] getItemIds() {
int[] r = new int[MAP.size()];
int i = 0;
for (int id : MAP.keySet()) {
r = id;
i++;
}
return r;
}
private static void restoreSkills(L2PcInstance player) {
SkillTable st = SkillTable.getInstance();
for(Entry<Integer, L2Skill> entry : MAP.entrySet()) {
String var = player.getVar("ItemSkills#" + entry.getKey());
if(var != null) {
String[] sAr = var.split(":");
player.addSkill(st.getInfo(Integer.parseInt(sAr[0]), Integer.parseInt(sAr[0])), false);
}
}
player.sendSkillList();
}
@Override
public void onSubChange(L2PcInstance player) {
if(player.isSubClassActive() && !ALLOW_ON_SUB)
return;
restoreSkills(player);
}
@Override
public void onPlayerEnter(L2PcInstance player) {
if(player.isSubClassActive() && !ALLOW_ON_SUB)
return;
restoreSkills(player);
}
public static void main(String[] args) {
BuySkill me = new BuySkill();
PlayerListenerList.addGlobal(me);
L2VillageMasterInstance.getSubListeners().add(me);
ItemHandler.getInstance().registerItemHandler(me);
}
}
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import net.sf.l2j.gameserver.datatables.SkillTable;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2VillageMasterInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2VillageMasterInstance.OnSubChangeListener;
import net.sf.l2j.gameserver.model.actor.player.OnPlayerEnterListener;
import net.sf.l2j.gameserver.model.actor.player.PlayerListenerList;
import scripts.items.IItemHandler;
import scripts.items.ItemHandler;
/**
*
* @author CalypsoToolz
*
*/
public class BuySkill implements OnPlayerEnterListener, OnSubChangeListener, IItemHandler {
private static final Map<Integer, L2Skill> MAP = new ConcurrentHashMap<>();
// разрешить использовать на саб-классе?
private static boolean ALLOW_ON_SUB = true;
static {
SkillTable st = SkillTable.getInstance();
// тут добавляем предмет и скилл
// MAP.put(ИД_ПРЕДМЕТА, st.getInfo(ИД_СКИЛЛА, ЛВЛ_СКИЛЛА));
MAP.put(10001, st.getInfo(1, 37));
}
@Override
public void useItem(L2PlayableInstance playable, L2ItemInstance item, boolean ctrl) {
if (playable.isPlayer()) {
L2PcInstance player = playable.getPlayer();
if (!ALLOW_ON_SUB && player.isSubClassActive()) {
player.sendCritMessage("Доступно только на основном классе!");
return;
}
if (player.destroyItemByItemId("UseItem", item.getItemId(), 1, null, true)) {
L2Skill skill = MAP.get(item.getItemId());
player.addSkill(skill, false);
player.sendCritMessage("Получен навык " + skill.getName());
player.setVar("ItemSkills#" + item.getItemId(), skill.getId() + ":" + skill.getLevel(), 0);
player.sendSkillList();
}
}
}
@Override
public int[] getItemIds() {
int[] r = new int[MAP.size()];
int i = 0;
for (int id : MAP.keySet()) {
r = id;
i++;
}
return r;
}
private static void restoreSkills(L2PcInstance player) {
SkillTable st = SkillTable.getInstance();
for(Entry<Integer, L2Skill> entry : MAP.entrySet()) {
String var = player.getVar("ItemSkills#" + entry.getKey());
if(var != null) {
String[] sAr = var.split(":");
player.addSkill(st.getInfo(Integer.parseInt(sAr[0]), Integer.parseInt(sAr[0])), false);
}
}
player.sendSkillList();
}
@Override
public void onSubChange(L2PcInstance player) {
if(player.isSubClassActive() && !ALLOW_ON_SUB)
return;
restoreSkills(player);
}
@Override
public void onPlayerEnter(L2PcInstance player) {
if(player.isSubClassActive() && !ALLOW_ON_SUB)
return;
restoreSkills(player);
}
public static void main(String[] args) {
BuySkill me = new BuySkill();
PlayerListenerList.addGlobal(me);
L2VillageMasterInstance.getSubListeners().add(me);
ItemHandler.getInstance().registerItemHandler(me);
}
}