Create new L2Macro & L2ShortCut error

If something doesn't fit in any other forum then post it here.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
patersvk
Posts: 11
Joined: Fri Dec 02, 2011 11:14 pm

Create new L2Macro & L2ShortCut error

Post by patersvk »

Hi, I'm a newbie so sorry for stupid questions.
This time I have a problem with creating a new L2Makra, L2ShortCut and sending to the client.

Code: Select all

 ...L2MacroCmd[] commands = new L2MacroCmd[0];commands[0] = new L2MacroCmd(0, 3, 0, 0, ".helper;"); L2Macro mc = new L2Macro(1000, 3, "Helper", "", "", commands);this.activeChar.getMacros().registerMacro(mc);L2ShortCut sc = new L2ShortCut(0, 3, 4, 1000, 0, 0);new ShortCuts(this.activeChar).registerShortCut(sc); this.activeChar.getMacros().sendUpdate();this.activeChar.sendPacket(new ShortCutInit(this.activeChar));... 
Error: java.lang.ArrayIndexOutOfBoundsException: 0
Macro or ShortCut are not created.
I do not know what I call key.



If insert in DB

Code: Select all

 ...PreparedStatement statement = con.prepareStatement("INSERT INTO character_macroses (charId,id,icon,name,descr,acronym,commands) values(?,?,?,?,?,?,?)");statement.setInt(1, this.activeChar.getObjectId());statement.setInt(2, 1000);statement.setInt(3, 3);statement.setString(4, "Helper");statement.setString(5, "");statement.setString(6, "");statement.setString(7, "3,0,0,.helper;");statement.execute(); statement = con.prepareStatement("INSERT INTO character_shortcuts (charId,slot,page,type,shortcut_id,level,class_index) values(?,?,?,?,?,?,?)");statement.setInt(1, this.activeChar.getObjectId());statement.setInt(2, 0);statement.setInt(3, 3);statement.setInt(4, 4);statement.setInt(5, 1000);statement.setString(6, "0");statement.setInt(7, 0);statement.execute();...this.activeChar.getMacros().restore();this.activeChar.getMacros().sendUpdate();new ShortCuts(this.activeChar).restore();this.activeChar.sendPacket(new ShortCutInit(this.activeChar));... 
Performs all goes well, the macro will create a ShortCut.
On the Client updates the Macro but not ShortCut

Please help me to create a Macro ShortCut without insert into DB and how to update the packet sent to the client, it ShortCut.
User avatar
BiggBoss
L2j Veteran
L2j Veteran
Posts: 1104
Joined: Wed Apr 15, 2009 3:11 pm
Location: Spain

Re: Create new L2Macro & L2ShortCut error

Post by BiggBoss »

L2MacroCmd[] commands = new L2MacroCmd[0];

duuuuude
Image
patersvk
Posts: 11
Joined: Fri Dec 02, 2011 11:14 pm

Re: Create new L2Macro & L2ShortCut error

Post by patersvk »

I do what I do. Instead dude you could write as it should be correct.
djmouse
Posts: 135
Joined: Tue Feb 07, 2012 4:48 am

Re: Create new L2Macro & L2ShortCut error

Post by djmouse »

It can't be zero length
patersvk
Posts: 11
Joined: Fri Dec 02, 2011 11:14 pm

Re: Create new L2Macro & L2ShortCut error

Post by patersvk »

I understand this, but whatever I try any way so it does not work correctly.

Code: Select all

 List<L2MacroCmd> commands = null;L2MacroCmd mcmd;L2ShortCut sc;L2Macro m; mcmd = new L2MacroCmd(0, 3, 0, 0, ".helper;");commands.add(mcmd);m = new L2Macro(1000, 3, "Helper", "", "", commands.toArray(new L2MacroCmd[commands.size()]));sc = new L2ShortCut(0, 3, 4, 1000, 0, 0);new ShortCuts(this.activeChar).registerShortCut(sc); //this.activeChar.getMacros().restore();this.activeChar.getMacros().sendUpdate();//new ShortCuts(this.activeChar).restore();this.activeChar.sendPacket(new ShortCutInit(this.activeChar)); 
Arantir
Posts: 151
Joined: Wed Jan 04, 2012 7:10 pm

Re: Create new L2Macro & L2ShortCut error

Post by Arantir »

omg, you always do exactly the same mistake =)

1. You couldn't get element from empty array.
2. You couldn't add element to undefined object (null).

You should learn a little bit more about programming.

Code: Select all

// at least one element should be thereL2MacroCmd[] commands = new L2MacroCmd[1];  // correct, because commands[0] existscommands[0] = new L2MacroCmd(0, 3, 0, 0, ".helper;"); 

Code: Select all

 // assign a defined object - some listList<L2MacroCmd> commands = new ArrayList<>(); // correct, because commands is an object of class List (and not null), so you can call List's methods on it.commands.add(new L2MacroCmd(0, 3, 0, 0, ".helper;"));
patersvk
Posts: 11
Joined: Fri Dec 02, 2011 11:14 pm

Re: Create new L2Macro & L2ShortCut error

Post by patersvk »

Yes that is exactly what I'm learning along L2J
Even if you know tell me how / what to send packet to client to be updated ShortCut him?

not working

Code: Select all

this.activeChar.sendPacket (new ShortCutInit (this.activeChar));

// I've figured it out.
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7005
Joined: Tue Aug 11, 2009 3:36 am

Re: Create new L2Macro & L2ShortCut error

Post by Zoey76 »

@patersvk don't worry if they are hard on you :P you are trying to learn and that is important, is also important to check code examples and some textbook along with the trial-and-error system, otherwise you may end up learning bad practices of programming or not learning at all and giving up :|
Powered by Eclipse 4.30 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.2.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
Post Reply