Page 1 of 1

Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 11:25 am
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.

Re: Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 12:03 pm
by BiggBoss
L2MacroCmd[] commands = new L2MacroCmd[0];

duuuuude

Re: Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 1:55 pm
by patersvk
I do what I do. Instead dude you could write as it should be correct.

Re: Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 2:05 pm
by djmouse
It can't be zero length

Re: Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 2:14 pm
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)); 

Re: Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 3:13 pm
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;"));

Re: Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 4:04 pm
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.

Re: Create new L2Macro & L2ShortCut error

Posted: Tue Feb 05, 2013 5:52 pm
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 :|