U3Games

Lineage II | Desarrollo & Soporte => Desarrollo de Servidores => Implementaciones => Mensaje iniciado por: Swarlog en Ago 11, 2022, 01:34 AM

Título: Sell Skills (fissban)
Publicado por: Swarlog en Ago 11, 2022, 01:34 AM
Primero aclarare q este npc no ah sido testeado ya q lo escribi en el trabajo en mi rato libre pero se los dejare a ustedes.

La intencion con este npc es q venda skills a los chars por un precio a estipular q lo pueden ajustar facilmente desde el script y asi mismo con la cantidad de skills q pueden aprender los chars y q skills.
Si necesitan ayuda sobre como modificar estos valores se los puedo detallar rapidamente.

Deberan crear un npc con el ID 21 o bien ajustar el Id del npc a su gusto en el script.
Registrarlo en script.cfg
......creo q es todo lo q les faltaria

/*
 * Copyright (C) 2004-2014 L2J DataPack
 *
 * This file is part of L2J DataPack.
 *
 * L2J DataPack is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * L2J DataPack is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package custom.Fissban.NpcRegaloSkills;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.holders.SkillHolder;
import com.l2jserver.gameserver.model.quest.Quest;
import com.l2jserver.gameserver.model.quest.QuestState;

/**
 * @author fissban
 */
public class NpcRegaloSkills extends Quest
{
    // Npc
    private static final int NPC = 21;
    // Cantidad maxima q un user puede aprender de skills.
    private static final int MAX_SKILLS_ADD = 5;
    // Precio por aprender cada skills....
    private static final int ITEMD_ID = 57; // Adena
    private static final int ITEM_COUNT = 1000; // Cantidad
    // Skills a regalar (SkillId - SkillLvl)
    private static final List<SkillHolder> SKILLS = new ArrayList<>();
    {
        SKILLS.add(new SkillHolder(1085, 113));// Acumen
        SKILLS.add(new SkillHolder(1035, 104));// Mental Shield
        SKILLS.add(new SkillHolder(1036, 112));// Magic Barrier
        SKILLS.add(new SkillHolder(1040, 113));// Shield
        SKILLS.add(new SkillHolder(1045, 116));// Blessed Body
        SKILLS.add(new SkillHolder(1048, 116));// Blessed Soul
        SKILLS.add(new SkillHolder(1059, 103));// Empower
        SKILLS.add(new SkillHolder(1062, 2));// Berserker Spirit
        SKILLS.add(new SkillHolder(1068, 3));// Might
        SKILLS.add(new SkillHolder(1077, 3));// Focus
        SKILLS.add(new SkillHolder(1078, 6));// Concentration
        SKILLS.add(new SkillHolder(1086, 2));// Haste
        SKILLS.add(new SkillHolder(1087, 3));// Agility
        SKILLS.add(new SkillHolder(1204, 2));// Wind Walk
        SKILLS.add(new SkillHolder(1240, 3));// Guidance
        SKILLS.add(new SkillHolder(1242, 3));// Death Whisper
        SKILLS.add(new SkillHolder(1243, 6));// Bless Shield
        SKILLS.add(new SkillHolder(1268, 4));// Vampiric Rage
    }
   
    private NpcRegaloSkills()
    {
        super(-1, NpcRegaloSkills.class.getSimpleName(), "custom/Fissban");
        addStartNpc(NPC);
        addFirstTalkId(NPC);
        addTalkId(NPC);
    }
   
    @Override
    public String onFirstTalk(L2Npc npc, L2PcInstance activeChar)
    {
        return GenerateHtmlIndex(activeChar);
    }
   
    @Override
    public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
    {
        if (event.equals("verSkills"))
        {
            return GenerateHtmlRegalos(player);
        }
        if (event.startsWith("regalarSkills"))
        {
            QuestState qs = player.getQuestState(getName());
            // Verificamos la cant de skills q ah aprendido el char
            if (qs.getInt("skills") >= MAX_SKILLS_ADD)
            {
                return "maxSkills.htm";
            }
           
            StringTokenizer st = new StringTokenizer(event, " ");
            st.nextToken(); // regalarSkills
           
            try
            {
                player.addSkill(SKILLS.get(Integer.parseInt(st.nextToken())).getSkill(), true);
                st.takeItems(ITEMD_ID, ITEM_COUNT);
                player.sendMessage("has aprendio un nuevo skills!"); // se podria cambiar por un html no?
               
                qs.set("skills", qs.getInt("skills") + 1); // incrementamos la cant de skills q ah aprendido el char
            }
            catch (Exception e)
            {
                _log.warning("WTF...tenemos un player q intenta aprender un skill fuera de la lista?");
                _log.warning("contactar con fissban por asesoria :P");
            }
           
        }
        return null;
    }
   
    /**
     * Generamos el html inicial
     * @param player
     * @return
     */
    private static String GenerateHtmlIndex(L2PcInstance player)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("<html><body><title>L2jAdmins</title>");
        sb.append("<center>");
        sb.append("<br>");
        sb.append("Bienvenido <font color=\"LEVEL\">" + player.getName() + "</font>");
        sb.append("<br>");
        sb.append("<center>");
        sb.append("Usted podra comprar algunos skills para su char<br>");
        sb.append("pero no seran gratuitos..no no no!<br>");
        sb.append("por la suma de " + ITEM_COUNT + " de " + ItemTable.getInstance().getTemplate(ITEMD_ID).getName() + "<br>");
        sb.append("pasa por nuestra tiendra y ve nuestros skills");
        sb.append("<button value=\"Ver Skills\" action=\"bypass -h Quest NpcRegaloSkills verSkills\" width=120 height=30 back=L2UI_CH3.bigbutton2_down fore=L2UI_CH3.bigbutton2></td>");
        sb.append("</center>");
        sb.append("</body></html>");
       
        return sb.toString();
    }
   
    /**
     * Generamos los html para cada lista de Skills a regalar
     * @param player
     * @return
     */
    private static String GenerateHtmlRegalos(L2PcInstance player)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("<html><body><title>L2jAdmins</title>");
        sb.append("<center>");
        sb.append("<br>");
        sb.append("Bienvenido <font color=\"LEVEL\">" + player.getName() + "</font>");
        sb.append("<br>");
       
        int cont = 0;
       
        for (SkillHolder skill : SKILLS)
        {
            if (skill.getSkill() == null)
            {
                _log.warning("skill null -->> " + cont);
                _log.warning("contactar a fissban por este nullPoint");
                cont++;
                continue;
            }
            sb.append("<table bgcolor=\"13458B\" width=260 height=36>");
            sb.append("<tr>");
            sb.append("<td width=32 height=32><img src=\"Icon.skill" + getSkillIcon(skill.getSkillId()) + "\"  width=32 height=32></td>");
            sb.append("<td align=center width=196 height=32><button value=\"Aprender " + skill.getSkill().getName() + "\" action=\"bypass -h Quest NpcRegaloSkills regalarSkills " + cont + "\" width=120 height=30 back=L2UI_CH3.bigbutton2_down fore=L2UI_CH3.bigbutton2></td>");
            sb.append("<td width=32 height=32><img src=\"Icon.skill" + getSkillIcon(skill.getSkillId()) + "\"  width=32 height=32></td>");
            sb.append("</tr>");
            sb.append("</table>");
            cont++;
        }
       
        sb.append("</center>");
        sb.append("</body></html>");
       
        return sb.toString();
    }
   
    /**
     * Generamos el ID de la imagen de un skill a partir de su ID
     * @param id
     * @return
     */
    private static String getSkillIcon(int id)
    {
        String formato;
        if (id == 4)
        {
            formato = "0004";
        }
        else if ((id > 9) && (id < 100))
        {
            formato = "00" + id;
        }
        else if ((id > 99) && (id < 1000))
        {
            formato = "0" + id;
        }
        else if (id == 1517)
        {
            formato = "1536";
        }
        else if (id == 1518)
        {
            formato = "1537";
        }
        else if (id == 1547)
        {
            formato = "0065";
        }
        else if (id == 2076)
        {
            formato = "0195";
        }
        else if ((id > 4550) && (id < 4555))
        {
            formato = "5739";
        }
        else if ((id > 4698) && (id < 4701))
        {
            formato = "1331";
        }
        else if ((id > 4701) && (id < 4704))
        {
            formato = "1332";
        }
        else if (id == 6049)
        {
            formato = "0094";
        }
        else
        {
            formato = String.valueOf(id);
        }
        return formato;
    }
   
    public static void main(String[] args)
    {
        new NpcRegaloSkills();
    }
}
Título: Re:Sell Skills (fissban)
Publicado por: lordofcaos en Ago 11, 2022, 07:34 PM
interesante intentare agregarlo a mi server nada mas que editare los skill haber si funciona para que vendan skill pasivos. haber que tal
Título: Re:Sell Skills (fissban)
Publicado por: lordofcaos en Ago 12, 2022, 06:45 AM
Bueno resulta que implemente el código modifique los import para mi proyecto, y revise el código levanto consola y marca error en algo que si esta en mi dp y no le encuentro lógica al error.

st.takeItems(ITEMD_ID, ITEM_COUNT);Mi codigo en mi datapack seria /*
 * Copyright (C) 2004-2014 L2J DataPack
 *
 * This file is part of L2J DataPack.
 *
 * L2J DataPack is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * L2J DataPack is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package custom.Fissban;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.l2jmaster.gameserver.datatables.ItemTable;
import org.l2jmaster.gameserver.model.actor.L2Npc;
import org.l2jmaster.gameserver.model.actor.instance.L2PcInstance;
import org.l2jmaster.gameserver.model.holders.SkillHolder;
import org.l2jmaster.gameserver.model.quest.Quest;
import org.l2jmaster.gameserver.model.quest.QuestState;
import org.l2jmaster.gameserver.util.Util;

/**
 * @author fissban
 */
public class NpcRegaloSkills extends Quest
{
    // Npc
    private static final int NPC = 20026;
    // Cantidad maxima q un user puede aprender de skills.
    private static final int MAX_SKILLS_ADD = 5;
    // Precio por aprender cada skills....
    private static final int ITEMD_ID = 57; // Adena
    private static final int ITEM_COUNT = 1000; // Cantidad
    // Skills a regalar (SkillId - SkillLvl)
    private static final List<SkillHolder> SKILLS = new ArrayList<>();
    {
        SKILLS.add(new SkillHolder(1085, 113));// Acumen
        SKILLS.add(new SkillHolder(1035, 104));// Mental Shield
        SKILLS.add(new SkillHolder(1036, 112));// Magic Barrier
        SKILLS.add(new SkillHolder(1040, 113));// Shield
        SKILLS.add(new SkillHolder(1045, 116));// Blessed Body
        SKILLS.add(new SkillHolder(1048, 116));// Blessed Soul
        SKILLS.add(new SkillHolder(1059, 103));// Empower
        SKILLS.add(new SkillHolder(1062, 2));// Berserker Spirit
        SKILLS.add(new SkillHolder(1068, 3));// Might
        SKILLS.add(new SkillHolder(1077, 3));// Focus
        SKILLS.add(new SkillHolder(1078, 6));// Concentration
        SKILLS.add(new SkillHolder(1086, 2));// Haste
        SKILLS.add(new SkillHolder(1087, 3));// Agility
        SKILLS.add(new SkillHolder(1204, 2));// Wind Walk
        SKILLS.add(new SkillHolder(1240, 3));// Guidance
        SKILLS.add(new SkillHolder(1242, 3));// Death Whisper
        SKILLS.add(new SkillHolder(1243, 6));// Bless Shield
        SKILLS.add(new SkillHolder(1268, 4));// Vampiric Rage
    }
   
    private NpcRegaloSkills()
    {
        super(-1, NpcRegaloSkills.class.getSimpleName(), "custom/Fissban");
        addStartNpc(NPC);
        addFirstTalkId(NPC);
        addTalkId(NPC);
    }
   
    @Override
    public String onFirstTalk(L2Npc npc, L2PcInstance activeChar)
    {
        return GenerateHtmlIndex(activeChar);
    }
   
    @Override
    public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
    {
        if (event.equals("verSkills"))
        {
            return GenerateHtmlRegalos(player);
        }
        if (event.startsWith("regalarSkills"))
        {
            QuestState qs = player.getQuestState(getName());
            // Verificamos la cant de skills q ah aprendido el char
            if (qs.getInt("skills") >= MAX_SKILLS_ADD)
            {
                return "maxSkills.htm";
            }
           
            StringTokenizer st = new StringTokenizer(event, " ");
            st.nextToken(); // regalarSkills
           
            try
            {
                player.addSkill(SKILLS.get(Integer.parseInt(st.nextToken())).getSkill(), true);   
st.takeItems(ITEMD_ID, ITEM_COUNT);
                player.sendMessage("has aprendio un nuevo skills!"); // se podria cambiar por un html no?
               
                qs.set("skills", qs.getInt("skills") + 1); // incrementamos la cant de skills q ah aprendido el char
            }
            catch (Exception e)
            {
                _log.warning("WTF...tenemos un player q intenta aprender un skill fuera de la lista?");
                _log.warning("contactar con fissban por asesoria :P");
            }
           
        }
        return null;
    }
   
    /**
     * Generamos el html inicial
     * @param player
     * @return
     */
    private static String GenerateHtmlIndex(L2PcInstance player)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("<html><body><title>L2jAdmins</title>");
        sb.append("<center>");
        sb.append("<br>");
        sb.append("Bienvenido <font color=\"LEVEL\">" + player.getName() + "</font>");
        sb.append("<br>");
        sb.append("<center>");
        sb.append("Usted podra comprar algunos skills para su char<br>");
        sb.append("pero no seran gratuitos..no no no!<br>");
        sb.append("por la suma de " + ITEM_COUNT + " de " + ItemTable.getInstance().getTemplate(ITEMD_ID).getName() + "<br>");
        sb.append("pasa por nuestra tiendra y ve nuestros skills");
        sb.append("<button value=\"Ver Skills\" action=\"bypass -h Quest NpcRegaloSkills verSkills\" width=120 height=30 back=L2UI_CH3.bigbutton2_down fore=L2UI_CH3.bigbutton2></td>");
        sb.append("</center>");
        sb.append("</body></html>");
       
        return sb.toString();
    }
   
    /**
     * Generamos los html para cada lista de Skills a regalar
     * @param player
     * @return
     */
    private static String GenerateHtmlRegalos(L2PcInstance player)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("<html><body><title>L2jAdmins</title>");
        sb.append("<center>");
        sb.append("<br>");
        sb.append("Bienvenido <font color=\"LEVEL\">" + player.getName() + "</font>");
        sb.append("<br>");
       
        int cont = 0;
       
        for (SkillHolder skill : SKILLS)
        {
            if (skill.getSkill() == null)
            {
                _log.warning("skill null -->> " + cont);
                _log.warning("contactar a fissban por este nullPoint");
                cont++;
                continue;
            }
            sb.append("<table bgcolor=\"13458B\" width=260 height=36>");
            sb.append("<tr>");
            sb.append("<td width=32 height=32><img src=\"Icon.skill" + getSkillIcon(skill.getSkillId()) + "\"  width=32 height=32></td>");
            sb.append("<td align=center width=196 height=32><button value=\"Aprender " + skill.getSkill().getName() + "\" action=\"bypass -h Quest NpcRegaloSkills regalarSkills " + cont + "\" width=120 height=30 back=L2UI_CH3.bigbutton2_down fore=L2UI_CH3.bigbutton2></td>");
            sb.append("<td width=32 height=32><img src=\"Icon.skill" + getSkillIcon(skill.getSkillId()) + "\"  width=32 height=32></td>");
            sb.append("</tr>");
            sb.append("</table>");
            cont++;
        }
       
        sb.append("</center>");
        sb.append("</body></html>");
       
        return sb.toString();
    }
   
    /**
     * Generamos el ID de la imagen de un skill a partir de su ID
     * @param id
     * @return
     */
    private static String getSkillIcon(int id)
    {
        String formato;
        if (id == 4)
        {
            formato = "0004";
        }
        else if ((id > 9) && (id < 100))
        {
            formato = "00" + id;
        }
        else if ((id > 99) && (id < 1000))
        {
            formato = "0" + id;
        }
        else if (id == 1517)
        {
            formato = "1536";
        }
        else if (id == 1518)
        {
            formato = "1537";
        }
        else if (id == 1547)
        {
            formato = "0065";
        }
        else if (id == 2076)
        {
            formato = "0195";
        }
        else if ((id > 4550) && (id < 4555))
        {
            formato = "5739";
        }
        else if ((id > 4698) && (id < 4701))
        {
            formato = "1331";
        }
        else if ((id > 4701) && (id < 4704))
        {
            formato = "1332";
        }
        else if (id == 6049)
        {
            formato = "0094";
        }
        else
        {
            formato = String.valueOf(id);
        }
        return formato;
    }
   
    public static void main(String[] args)
    {
        new NpcRegaloSkills();
    }
}

pero sale este error molesto que no entiendo porque !!!! si la linea que da problema es igual a otros archivos que si funcionan!!
error.jpg
Título: Re:Sell Skills (fissban)
Publicado por: Jerry en Ago 13, 2022, 02:12 AM
Cambia el

st.takeItems(ITEMD_ID, ITEM_COUNT);
por

qs.takeItems(ITEMD_ID, ITEM_COUNT);
Título: Re:Sell Skills (fissban)
Publicado por: lordofcaos en Ago 13, 2022, 06:15 AM
Debes de estar registrado para poder ver el contenido indicado. Registrate o ConectateCambia el

st.takeItems(ITEMD_ID, ITEM_COUNT);
por

qs.takeItems(ITEMD_ID, ITEM_COUNT);

Excelente, ahora bien el npc funciona en una parte adjunto fotos:

Cuando Hablamos con el NPC
(https://i.ibb.co/whpPxpK/npc-inicio.jpg)

Una vez que hablamos con el npc Area de pedir Skill:
(https://i.ibb.co/rdKfJR9/dentro.jpg)

Ahora le damos a pedir un skill y sale este Error:
(https://i.ibb.co/9gKGWVx/error-al-intentar-comprar-el-skill.jpg)

En consola sale esto:
(https://i.ibb.co/qyKqs33/consola.jpg)

Segun lo que entiendo el error sale en la linea 93 que corresponde a la siguiente:
// Verificamos la cant de skills q ah aprendido el char
      //linea 93>>      if (qs.getInt("skills") >= MAX_SKILLS_ADD)
            {
                return "maxSkills.htm";
            }
Título: Re:Sell Skills (fissban)
Publicado por: Swarlog en Ago 14, 2022, 01:05 AM
Metele a esa línea un check null, y añadele un print para ver que esta pasando.

Posiblemente el valor de la skill sea nulo, revisa paso atras.. a ver donde falla.