Resolved How I add effect when change subclass first time?

fa1thDEV

Baron
Customer
What should I do so that when a player throws “sub” for the first time, it alerts the global chat and rumbles the floor?

Example:

Announcement: the %player% has made his first subclass!
Announcement: the %player% has made his second subclass!
Announcement: %player% has made his third subclass, congratulations!

Example of abnormals:

JavaScript:
var1.broadcastPacket(new L2GameServerPacket[]{new ExRedSky(10)});
var1.broadcastPacket(new L2GameServerPacket[]{new Earthquake(var1.getLoc(), 30, 12)});

I need help, I'm learning about scripts, but I don't get any help :/
 
You could perhaps try to use OnSetActiveSubClassListener. Also, double check the sub count thingy however it's being saved into memory. I am guessing you'd like to send the effect globally though; then you can use GameObjectsStorage.getAllPlayersForIterate() + isOnline check.

Java:
package services;

import l2.gameserver.listener.actor.player.OnSetActiveSubClassListener;
import l2.gameserver.model.Player;
import l2.gameserver.model.actor.listener.CharListenerList;
import l2.gameserver.network.l2.components.ChatType;
import l2.gameserver.network.l2.s2c.Earthquake;
import l2.gameserver.network.l2.s2c.ExRedSky;
import l2.gameserver.network.l2.s2c.L2GameServerPacket;
import l2.gameserver.network.l2.s2c.Say2;
import l2.gameserver.scripts.ScriptFile;

public class SubClassAnn implements OnSetActiveSubClassListener, ScriptFile
{
    private static final SubClassAnn INSTANCE = new SubClassAnn();
 
    @Override
    public void onSetActiveSub(Player player, int idk)
    {
        if (player == null)
            return;
   
        int subclassCount = player.getSubClasses().size() - 1;
        String announcement = switch (subclassCount)
        {
            case 1 -> "The " + player.getName() + " has made their first subclass!";
            case 2 -> "The " + player.getName() + " has made their second subclass!";
            case 3 -> player.getName() + " has made their third subclass, congratulations!";
            default -> null;
        };
   
        if (announcement != null)
        {
            Say2 globalAnnouncement = new Say2(0, ChatType.ANNOUNCEMENT, "", announcement);
            player.sendPacket(globalAnnouncement);
            player.broadcastPacket(new L2GameServerPacket[] {new ExRedSky(10)});
            player.broadcastPacket(new L2GameServerPacket[] {new Earthquake(player.getLoc(), 30, 12)});
        }
    }
 
    @Override
    public void onLoad()
    {
        CharListenerList.addGlobal(INSTANCE);
    }
 
    @Override
    public void onReload()
    {
        onShutdown();
        onLoad();
    }
 
    @Override
    public void onShutdown()
    {
        CharListenerList.removeGlobal(INSTANCE);
    }
}
 
Last edited:
You could perhaps try to use OnSetActiveSubClassListener. Also, double check the sub count thingy however it's being saved into memory. I am guessing you'd like to send the effect globally though; then you can use GameObjectsStorage.getAllPlayersForIterate() + isOnline check.

Java:
package services;

import l2.gameserver.listener.actor.player.OnSetActiveSubClassListener;
import l2.gameserver.model.Player;
import l2.gameserver.model.actor.listener.CharListenerList;
import l2.gameserver.network.l2.components.ChatType;
import l2.gameserver.network.l2.s2c.Earthquake;
import l2.gameserver.network.l2.s2c.ExRedSky;
import l2.gameserver.network.l2.s2c.L2GameServerPacket;
import l2.gameserver.network.l2.s2c.Say2;
import l2.gameserver.scripts.ScriptFile;

public class SubClassAnn implements OnSetActiveSubClassListener, ScriptFile
{
    private static final SubClassAnn INSTANCE = new SubClassAnn();
 
    @Override
    public void onSetActiveSub(Player player, int idk)
    {
        if (player == null)
            return;
  
        int subclassCount = player.getSubClasses().size() - 1;
        String announcement = switch (subclassCount)
        {
            case 1 -> "The " + player.getName() + " has made their first subclass!";
            case 2 -> "The " + player.getName() + " has made their second subclass!";
            case 3 -> player.getName() + " has made their third subclass, congratulations!";
            default -> null;
        };
  
        if (announcement != null)
        {
            Say2 globalAnnouncement = new Say2(0, ChatType.ANNOUNCEMENT, "", announcement);
            player.sendPacket(globalAnnouncement);
            player.broadcastPacket(new L2GameServerPacket[] {new ExRedSky(10)});
            player.broadcastPacket(new L2GameServerPacket[] {new Earthquake(player.getLoc(), 30, 12)});
        }
    }
 
    @Override
    public void onLoad()
    {
        CharListenerList.addGlobal(INSTANCE);
    }
 
    @Override
    public void onReload()
    {
        onShutdown();
        onLoad();
    }
 
    @Override
    public void onShutdown()
    {
        CharListenerList.removeGlobal(INSTANCE);
    }
}
ty trance <3

btw, I have not found any guide, I have already copied this code to test it, but when I put the .ext in gameserver, and start the server, nothing happens... how do I activate it?
 
ty trance <3

btw, I have not found any guide, I have already copied this code to test it, but when I put the .ext in gameserver, and start the server, nothing happens... how do I activate it?

Add debugging messages for the code itself and onLoad to make sure it does something.
 
the problem that the code has, is that it throws the announcement when the user ALREADY HAS the SUB_CLASS and returns to its MAIN_CLASS, if I already have a SUB_CLASS it will give the announcement of the first one, but if I give for the first time the SECOND SUB_CLASS.... nothing happens.

@Deazer @Trance
 

That's normal because there is no check if announcement was made or not for that player.
You need to save and then check it.


Java:
if (player.getVarInt("CustomSubAnn1", 0) == 1)

...

existing +1
  
player.setVar("CustomSubAnn1", player.getVarInt("CustomSubAnn1", 0) + 1, -1);

or

set 1

player.setVar("CustomSubAnn1", 1, -1);

I hope you get the idea.
 
That's normal because there is no check if announcement was made or not for that player.
You need to save and then check it.


Java:
if (player.getVarInt("CustomSubAnn1", 0) == 1)

...

existing +1
 
player.setVar("CustomSubAnn1", player.getVarInt("CustomSubAnn1", 0) + 1, -1);

or

set 1

player.setVar("CustomSubAnn1", 1, -1);

I hope you get the idea.
Not working :/

why the code and the class working on "ACTIVE"subclass, if the player is not on active subclass not working, here a example video:

 
BUT I have a big question, where work the subclass system?, when you get a new subclass the system in the client chat advise you "you get a new subclass" if I overwrite that script and add the effects?
 
Back
Top