creating a race/skin change script (help)

fa1thDEV

Heir
Hello, I am creating a script that you can change skin without affecting the base character, how I adapt this script to lucera?

Code:
### Eclipse Workspace Patch 1.0
#P L2jFrozen_GameServer
Index: head-src/com/l2jfrozen/gameserver/network/serverpackets/UserInfo.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/network/serverpackets/UserInfo.java   (revision 1118)
+++ head-src/com/l2jfrozen/gameserver/network/serverpackets/UserInfo.java   (working copy)
@@ -21,6 +21,7 @@
 package com.l2jfrozen.gameserver.network.serverpackets;
 
 import java.util.Map;
+import java.util.logging.Logger;
 
 import com.l2jfrozen.Config;
 import com.l2jfrozen.gameserver.datatables.sql.NpcTable;
@@ -109,15 +110,36 @@
      
        writeD(_activeChar.getObjectId());
        writeS(_activeChar.getName());
-       writeD(_activeChar.getRace().ordinal());
+     
+       if (_activeChar.getCustomRaceSkin() == -1) {
+
+           writeD(_activeChar.getRace().ordinal());
+
+       }
+       else {
+
+           writeD(_activeChar.getCustomRaceSkin());
+         
+
+       }
+           // writeD(_activeChar.getRace().ordinal());
+
        writeD(_activeChar.getAppearance().getSex() ? 1 : 0);
      
-       if (_activeChar.getClassIndex() == 0)
+       // if ((_activeChar.getClassIndex() == 0)
+       // {
+       if (_activeChar.getCustomClassSkin() == -1 && (_activeChar.getClassIndex() == 0))
        {
+
            writeD(_activeChar.getClassId().getId());
        }
-       else
+       else if(_activeChar.getCustomClassSkin()>-1)
        {
+           writeD(_activeChar.getCustomClassSkin());
+           // else
+           // writeD(_activeChar.getBaseClass());
+
+       }else {
            writeD(_activeChar.getBaseClass());
        }
      
@@ -243,8 +265,21 @@
        }
        else
        {
-           writeF(_activeChar.getBaseTemplate().collisionRadius);
-           writeF(_activeChar.getBaseTemplate().collisionHeight);
+
+         
+           if (_activeChar.getCustomRaceSkin() == -1)
+           {
+               writeF(_activeChar.getBaseTemplate().getCollisionRadius());
+               writeF(_activeChar.getBaseTemplate().getCollisionHeight());
+           }
+           else
+           {
+
+               writeF(_activeChar.getCustomSkinTemplate().getCollisionRadius());
+               writeF(_activeChar.getCustomSkinTemplate().getCollisionHeight());
+           }
+
+         
        }
      
        writeD(_activeChar.getAppearance().getHairStyle());
Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java    (revision 1118)
+++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java    (working copy)
@@ -37,6 +37,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledFuture;
@@ -461,7 +462,7 @@
     * =?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs =?,wantspeace=?,base_class =?,onlinetime=?,in_jail=?,jail_timer=?,newbie=?,nobless=?,power_grade=?,subpledge=?,last_recom_date =?,lvl_joined_academy
     * =?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=? ,char_name=?,death_penalty_level=?,good=?,evil=?,gve_kills=? WHERE obj_id=?.
     */
-   private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,str=?,con=?,dex=?,_int=?,men=?,wit=?,face=?,hairStyle=?,hairColor=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,maxload=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,newbie=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=?,pc_point=?,name_color=?,title_color=?,aio=?,aio_end=? WHERE obj_id=?";
+   private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,str=?,con=?,dex=?,_int=?,men=?,wit=?,face=?,hairStyle=?,hairColor=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,maxload=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,newbie=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=?,pc_point=?,name_color=?,title_color=?,aio=?,aio_end=? ,custom_race_skin=?,custom_class_skin=? WHERE obj_id=?";
  
    /**
     * SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, acc, crit, evasion, mAtk, mDef, mSpd, pAtk, pDef, pSpd, runSpd, walkSpd, str, con, dex, _int, men, wit, face, hairStyle, hairColor, sex, heading, x, y, z, movement_multiplier, attack_speed_multiplier,
@@ -10139,6 +10140,10 @@
                }
              
                CursedWeaponsManager.getInstance().checkPlayer(player);
+               LOGGER.info("L2PCInstace   10139***");
+               player.setCustomRaceSkin(rset.getInt("custom_race_skin"));
+               player.setCustomClassSkin(rset.getInt("custom_class_skin"));
+
              
                player.setAllianceWithVarkaKetra(rset.getInt("varka_ketra_ally"));
              
@@ -10626,8 +10631,11 @@
          
            statement.setInt(60, isAio() ? 1 : 0);
            statement.setLong(61, getAioEndTime());
+           statement.setInt(62, getCustomRaceSkin());
+           statement.setInt(63, getCustomClassSkin());
+           statement.setInt(64, getObjectId());
+
          
-           statement.setInt(62, getObjectId());
          
            statement.execute();
            DatabaseUtils.close(statement);
@@ -16640,6 +16687,9 @@
        L2World.getInstance().removeFromAllPlayers(this); // force remove in case of crash during teleport
      
    }
+   private int _customClassSkin = -1;
+   private int _customRaceSkin = -1;
+
  
    /** ShortBuff clearing Task */
    private ScheduledFuture<?> _shortBuffTask = null;
@@ -19644,4 +19694,41 @@
        _currentPetSkill = new SkillDat(currentSkill, ctrlPressed, shiftPressed);
    }
  
+   public void setCustomClassSkin(int valor)
+   {
+       _customClassSkin = valor;
+   }
+
+   public void setCustomRaceSkin(int valor)
+   {
+       _customRaceSkin = valor;
+   }
+
+   public int getCustomClassSkin()
+   {
+       return _customClassSkin;
+   }
+
+   public int getCustomRaceSkin()
+   {
+       return _customRaceSkin;
+   }
+
+   public L2PcTemplate getCustomSkinTemplate()
+   {
+       return CharTemplateTable.getInstance().getTemplate(getCustomClassSkin());
+   }
+
+   public void render() {
+       final com.l2jfrozen.gameserver.network.serverpackets.DeleteObject deletePacket = new com.l2jfrozen.gameserver.network.serverpackets.DeleteObject(this);
+       for (L2Object obj : getKnownList().getKnownObjects().values()) {
+           if ((obj != null) && obj.isPlayer()) {                
+                   ((L2PcInstance) obj).sendPacket(deletePacket);
+             
+           }
+       }
+       broadcastStatusUpdate();
+       broadcastUserInfo();
+       //broadcastPacket(deletePacket);
+   }
 }
\ No newline at end of file
Index: head-src/com/l2jfrozen/gameserver/network/serverpackets/CharSelectInfo.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/network/serverpackets/CharSelectInfo.java (revision 1118)
+++ head-src/com/l2jfrozen/gameserver/network/serverpackets/CharSelectInfo.java (working copy)
          
@@ -231,9 +238,9 @@
      
        try
        {
+
            con = L2DatabaseFactory.getInstance().getConnection(false);
-           final PreparedStatement statement = con.prepareStatement("SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxMp, curMp, acc, crit, evasion, mAtk, mDef, mSpd, pAtk, pDef, pSpd, runSpd, walkSpd, str, con, dex, _int, men, wit, face, hairStyle, hairColor, sex, heading, x, y, z, movement_multiplier, attack_speed_multiplier, colRad, colHeight, exp, sp, karma, pvpkills, pkkills, clanid, maxload, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, base_class FROM characters WHERE account_name=?");
-           statement.setString(1, _loginName);
+           final PreparedStatement statement = con.prepareStatement("SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxMp, curMp, acc, crit, evasion, mAtk, mDef, mSpd, pAtk, pDef, pSpd, runSpd, walkSpd, str, con, dex, _int, men, wit, face, hairStyle, hairColor, sex, heading, x, y, z, movement_multiplier, attack_speed_multiplier, colRad, colHeight, exp, sp, karma, pvpkills, pkkills, clanid, maxload, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, base_class,custom_race_skin,custom_class_skin FROM characters WHERE account_name=?");          statement.setString(1, _loginName);
            final ResultSet charList = statement.executeQuery();
          
            while (charList.next())// fills the package
@@ -334,11 +341,16 @@
        charInfopackage.setExp(chardata.getLong("exp"));
        charInfopackage.setSp(chardata.getInt("sp"));
        charInfopackage.setClanId(chardata.getInt("clanid"));
-     
+
+       final int customRaceSkin = chardata.getInt("custom_race_skin");
+
+       if (customRaceSkin == -1)
        charInfopackage.setRace(chardata.getInt("race"));
-     
+       else
+       charInfopackage.setCustomRaceSkin(customRaceSkin);
+
        charInfopackage.setAccessLevel(chardata.getInt("accesslevel"));
-     
+       final int customClassSkin = chardata.getInt("custom_class_skin");
        final int baseClassId = chardata.getInt("base_class");
        final int activeClassId = chardata.getInt("classid");
      
@@ -392,13 +404,19 @@
        /*
         * Check if the base class is set to zero and alse doesn't match with the current active class, otherwise send the base class ID. This prevents chars created before base class was introduced from being displayed incorrectly.
         */
-       if (baseClassId == 0 && activeClassId > 0)
-       {
+
+       if (customClassSkin == -1)
+           if (baseClassId == 0 && activeClassId > 0)
            charInfopackage.setBaseClassId(activeClassId);
-       }
+           else
+               charInfopackage.setBaseClassId(baseClassId);
        else
        {
-           charInfopackage.setBaseClassId(baseClassId);
+           charInfopackage.setCustomClassSkin(customClassSkin);
+           // if (baseClassId == 0 && activeClassId > 0)
+           // charInfopackage.setBaseClassId(activeClassId);
+           // else
+           // charInfopackage.setBaseClassId(baseClassId);
        }
      
        charInfopackage.setDeleteTimer(deletetime);
Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2ChangeSkinManagerInstance.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2ChangeSkinManagerInstance.java (nonexistent)
+++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2ChangeSkinManagerInstance.java (working copy)
@@ -0,0 +1,146 @@
+/*
+ * This program 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.
+ *
+ * This program 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 com.l2jfrozen.gameserver.model.actor.instance;
+
+import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
+import com.l2jfrozen.gameserver.model.base.ClassId;
+
+/**
+ * @author execanciani & Toxico
+ */
+public class L2ChangeSkinManagerInstance extends L2NpcInstance
+{
+   public enum Races
+   {
+       FIGHTER(com.l2jfrozen.gameserver.model.base.Race.human, ClassId.fighter),
+       MAGE(com.l2jfrozen.gameserver.model.base.Race.human, ClassId.mage),
+       ELVENFIGHTER(com.l2jfrozen.gameserver.model.base.Race.elf, ClassId.elvenFighter),
+       ELVENMAGE(com.l2jfrozen.gameserver.model.base.Race.elf, ClassId.elvenMage),
+       DARKFIGHTER(com.l2jfrozen.gameserver.model.base.Race.darkelf, ClassId.darkFighter),
+       DARKMAGE(com.l2jfrozen.gameserver.model.base.Race.darkelf, ClassId.darkMage),
+       ORCFIGHTER(com.l2jfrozen.gameserver.model.base.Race.orc, ClassId.orcFighter),
+       ORCMAGE(com.l2jfrozen.gameserver.model.base.Race.orc, ClassId.orcMage),
+       DWARVEN(com.l2jfrozen.gameserver.model.base.Race.dwarf, ClassId.dwarvenFighter);
+     
+       private com.l2jfrozen.gameserver.model.base.Race races;
+       private ClassId classId;
+     
+       private Races(com.l2jfrozen.gameserver.model.base.Race races, ClassId classid)
+       {
+           this.races = races;
+           this.classId = classid;
+       }
+     
+       public int getRaceId()
+       {
+           return races.ordinal();
+       }
+     
+       public int getClassId()
+       {
+           return classId.getId();
+       }
+   }
+
+
+   public L2ChangeSkinManagerInstance(int objectId, L2NpcTemplate template)
+   {
+       super(objectId, template);
+     
+   }
+ 
+   @Override
+   public void onBypassFeedback(L2PcInstance player, String command)
+   {
+       Races races = null;
+       if (command.startsWith("HumanFighter"))
+       {
+           races = Races.FIGHTER;
+       }
+     
+       else if (command.startsWith("HumanMage"))
+       {
+           races = Races.MAGE;
+       }
+     
+       else if (command.startsWith("ElfFighter"))
+       {
+           races = Races.ELVENFIGHTER;
+       }
+     
+       else if (command.startsWith("ElfMage"))
+       {
+           races = Races.ELVENMAGE;
+       }
+     
+       else if (command.startsWith("DarkElfFighter"))
+       {
+           races = Races.DARKFIGHTER;
+       }
+     
+       else if (command.startsWith("DarkElfMage"))
+       {
+           races = Races.DARKMAGE;
+       }
+     
+       else if (command.startsWith("OrcFighter"))
+       {
+           races = Races.ORCFIGHTER;
+       }
+     
+       else if (command.startsWith("OrcMage"))
+       {
+           races = Races.ORCMAGE;
+       }
+     
+       else if (command.startsWith("Dwarven"))
+       {
+           races = Races.DWARVEN;
+
+       }
+       else if (command.startsWith("BackMainSkin"))
+       {
+           player.setCustomClassSkin(-1);
+           player.setCustomRaceSkin(-1);
+       }
+       setRaceCustomSkin(player, races);
+     
+       player.broadcastUserInfo();
+       player.broadcastUserInfo();
+
+   }
+ 
+   @Override
+   public String getHtmlPath(int npcId, int val)
+   {
+       String filename = "";
+       if (val == 0)
+           filename = "" + npcId;
+       else
+           filename = npcId + "-" + val;
+     
+       return "data/html/mods/ChangeSkin/" + filename + ".htm";
+   }
+ 
+   private static void setRaceCustomSkin(L2PcInstance player, Races valor)
+   {
+       if ((player == null) || (valor == null))
+       {
+           return;
+       }
+       player.setCustomRaceSkin(valor.getRaceId());
+       player.setCustomClassSkin(valor.getClassId());
+   }
+}
Index: head-src/com/l2jfrozen/gameserver/model/CharSelectInfoPackage.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/model/CharSelectInfoPackage.java  (revision 1118)
+++ head-src/com/l2jfrozen/gameserver/model/CharSelectInfoPackage.java  (working copy)
@@ -50,6 +50,9 @@
    private int _karma = 0;
    private int _augmentationId = 0;
    private int _accessLevel;
+   private int _customClassSkin = -1;
+   private int _customRaceSkin = -1;
+
  
    /**
     * @param objectId
@@ -304,6 +307,26 @@
    {
        return _accessLevel;
    }
+   public void setCustomClassSkin(int valor)
+   {
+       _customClassSkin = valor;
+   }
+
+   public void setCustomRaceSkin(int valor)
+   {
+       _customRaceSkin = valor;
+   }
+
+   public int getCustomClassSkin()
+   {
+       return _customClassSkin;
+   }
+
+   public int getCustomRaceSkin()
+   {
+       return _customRaceSkin;
+   }
+
  
    public void setAccessLevel(final int accessLevel)
    {
Index: head-src/com/l2jfrozen/gameserver/network/serverpackets/CharInfo.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/network/serverpackets/CharInfo.java   (revision 1118)
+++ head-src/com/l2jfrozen/gameserver/network/serverpackets/CharInfo.java   (working copy)
@@ -218,15 +227,25 @@
            writeD(_heading);
            writeD(_activeChar.getObjectId());
            writeS(_activeChar.getName());
-           writeD(_activeChar.getRace().ordinal());
+
+           if (_activeChar.getCustomRaceSkin() == -1)
+               writeD(_activeChar.getRace().ordinal());
+               else
+               writeD(_activeChar.getCustomRaceSkin());
            writeD(_activeChar.getAppearance().getSex() ? 1 : 0);
          
-           if (_activeChar.getClassIndex() == 0)
+           // if ((_activeChar.getClassIndex() == 0)
+           // {
+           if (_activeChar.getCustomClassSkin() == -1 && _activeChar.getClassIndex() == 0)
            {
                writeD(_activeChar.getClassId().getId());
            }
-           else
+           else if(_activeChar.getCustomClassSkin()>-1)
            {
+               writeD(_activeChar.getCustomClassSkin());
+               // else
+               // writeD(_activeChar.getBaseClass());
+           }else {
                writeD(_activeChar.getBaseClass());
            }
 
Last edited:
Code:
SQL: alter table characters add ( `custom_race_skin` smallint(5) NOT NULL DEFAULT '0',  `custom_class_skin` smallint(5) NOT NULL DEFAULT '0',);

html:
Code:
<html><body><center><button value="Human Fighter" action="bypass -h npc_%objectId%_HumanFighter" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Human Mage" action="bypass -h npc_%objectId%_HumanMage" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Elf Fighter" action="bypass -h npc_%objectId%_ElfFighter" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Elf Mage" action="bypass -h npc_%objectId%_ElfMage" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Dark Elf Fighter" action="bypass -h npc_%objectId%_DarkElfFighter" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Dark Elf Mage" action="bypass -h npc_%objectId%_DarkElfMage" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Orc Fighte" action="bypass -h npc_%objectId%_OrcFighter" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Orc Mage" action="bypass -h npc_%objectId%_OrcMage" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
<button value="Dwarven" action="bypass -h npc_%objectId%_Dwarven" width=204 height=20 back="sek.cbui75" fore="sek.cbui76"><br1>
SI NO QUERES MAS TU CAMBIO DE SKIN<br1>
CON LA SIGUIENTE OPCION PUEDES<br1>
VOLVER A TENER TU CUERPO ANTERIOR<br1>
<button value="Back Main Skin" action="bypass -h npc_%objectId%_BackMainSkin" width=204 height=20 back="sek.cbui75" fore="sek.cbui76">
</center></body></html>

NPC:
50009 30519 Change Skin Manager 1 L2JaCis 0 Monster.angel 7,00 18,00 70 male L2ChangeSkinManager 40 3862 1494 11,85 2,45 40 43 30 21 20 10 490 10 1335 470 780 809 278 0 333 0 0 0 88 132 0 0 0 LAST_HIT
 
Last edited:
Back
Top