Jump to content

Question

Posted

Hope someone can help

I wrote script to restore buffs here is the function.

the problem is that it restores only first buff from sql record

Example of Sql Record

-- ----------------------------
-- Table structure for `community_skillsave`
-- ----------------------------
DROP TABLE IF EXISTS `community_skillsave`;
CREATE TABLE `community_skillsave` (
  `charId` int(10) DEFAULT NULL,
  `skills` text,
  `pet` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of community_skillsave
-- ----------------------------
INSERT INTO `community_skillsave` VALUES ('268480452', '1240;1048;', null);

 

Restore Java Script

private void RESTOR(L2PcInstance activeChar)
{
	Connection con = null;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement stat = con.prepareStatement("SELECT * FROM community_skillsave WHERE charId=?;");
		stat.setInt(1, activeChar.getObjectId());
		ResultSet rset = stat.executeQuery();
		rset.next();

		String allskills = rset.getString(2);
		StringTokenizer stBuff = new StringTokenizer(allskills, ";");
		while (stBuff.hasMoreTokens())
		{
			int skilltoresatore = Integer.parseInt(stBuff.nextToken());
			int skilllevel = SkillTable.getInstance().getMaxLevel(skilltoresatore);
			L2Skill skill = SkillTable.getInstance().getInfo(skilltoresatore, skilllevel);

			PreparedStatement st = con.prepareStatement("SELECT COUNT(*) FROM community_skillsave WHERE skills=?;");
			st.setInt(1, skilltoresatore);
			ResultSet rs = st.executeQuery();
			rs.next();

			if (rs.getInt(1) != 0)
			{
				skill.getEffects(activeChar, activeChar);
			}
			else
			{
				activeChar.sendMessage("Buff: " + skill.getName() + " (" + skill.getId() + "), can't be restored!");
			}

			rs.close();
			st.close();
		}
		rset.close();
		stat.close();
	}
	catch (SQLException e)
	{
	}
	finally
	{
		L2DatabaseFactory.close(con);
	}
}

 

thanks to everyone

2 answers to this question

Recommended Posts

  • 0
Posted

I don't understand at all the use of your StringTokenizer stBuff.

 

If you want to retrieve from a DB, then use :

while (rset.next())
{

For a simple DB load you don't need to use StringTokenizer AT ALL. Eventually to split a String from a config file, but that's clearly not what you try to do.

 


 

PS : I understood lol. What you try to do is ugly. Make one line per skillId. It will be faster than to try to retrieve a string, split it and then doing the same action.

 

INSERT INTO `community_skillsave` VALUES ('268480452', '1240', null);
INSERT INTO `community_skillsave` VALUES ('268480452', '1048', null);

  • 0
Posted

I reworked it, but main goal that i want to achieve is to get skills from sql with 1024;1035; etc

Because i save buff with bypass :  bypass -h _bbs_buff_Player;264;266;267;268;270;304;529;364;

 

thats why i want to restore with the same method, reworked Restore function restores only first one again :(

 

private void SAVE(L2PcInstance activeChar)
{
	Connection con = null;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement stat = con.prepareStatement("SELECT *FROM community_skillsave WHERE charId=?;");
		stat.setInt(1, activeChar.getObjectId());
		ResultSet rset = stat.executeQuery();
		rset.next();

		String allbuff = "";
		int charId = rset.getInt("charId");
		L2Effect[] skill = activeChar.getAllEffects();//TODO Check Buff Skills to not bug with other effects

		for (int j = 0; j < skill.length; ++j)
		{
			allbuff = allbuff + new StringBuilder().append(skill[j].getSkill().getId()).append(";").toString();
		}

		if (charId == 0)
		{
			PreparedStatement statement1 = con.prepareStatement("INSERT INTO community_skillsave (charId,skills) values (?,?)");
			statement1.setInt(1, activeChar.getObjectId());
			statement1.setString(2, allbuff);
				activeChar.sendMessage("Buff Saved Successfully!");
			statement1.execute();
			statement1.close();
		}
		else
		{
			PreparedStatement statement = con.prepareStatement("UPDATE community_skillsave SET skills=? WHERE charId=?;");
			statement.setString(1, allbuff);
			statement.setInt(2, activeChar.getObjectId());
				activeChar.sendMessage("Buff Updated Successfully!");				
			statement.execute();
			statement.close();
		}
		rset.close();
		stat.close();
	}
	catch (SQLException e)
	{
	}
	finally
	{
		L2DatabaseFactory.close(con);
	}
}

private void RESTOR(L2PcInstance activeChar)
{
	Connection con = null;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement stat = con.prepareStatement("SELECT * FROM community_skillsave WHERE charId=?;");
		stat.setInt(1, activeChar.getObjectId());
		ResultSet rset = stat.executeQuery();

	    while (rset.next())
	    {			
	    	String allskills = rset.getString("skills");
	    	int charId = rset.getInt("charId");
	    	StringTokenizer BuffId = new StringTokenizer(allskills, ";");
			int skillid = Integer.parseInt(BuffId.nextToken());
			int skilllevel = SkillTable.getInstance().getMaxLevel(skillid);
			L2Skill skill = SkillTable.getInstance().getInfo(skillid, skilllevel);		    	

			if (charId != 0)
			{
				skill.getEffects(activeChar, activeChar);
			}
			else
			{
				activeChar.sendMessage("Buff: " + skill.getName() + " (" + skill.getId() + "), can't be restored!");
			}
	    }
		rset.close();
		stat.close();
	}
	catch (SQLException e)
	{
	}
	finally
	{
		L2DatabaseFactory.close(con);
	}
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • 👑 [FOR SALE] Lineage 2 Premium UCP – Modern Web Panel with Progression & Reward Systems. Looking for the ultimate edge to make your server boom and boost revenue? Introducing the L2 Premium UCP—the most comprehensive and modern User Control Panel on the market. Developed with a total focus on player experience (UX) and administrative automation. Say goodbye to outdated, buggy panels. Give your server the look and feel of an official game!  
    • Here I agree with you, because I get tired of clients like you and I don’t see any problems. Since you act in such a strange way, I’ll mirror it back to you, little brother.   Alice will even post a correspondence with you where you've been asking the same stupid questions (about prices or products) for three years and let everyone look and draw two personal conclusions about you (you're a little child)     If anyone wants to add you as a buyer to their group, let them take you hand and foot. I'll even help you pack you into an iron box.   Let's look at your last reply where you wish me luck in sales but then immediately run off to complain on the forum  yes, that's what people like you do and yes, I don't want to see people like you in my group or anywhere near it.   We're freelancing here, and yes, at first I check for loyalty and patience with clients, but when year after year they only ask me about prices - you know, if someone needs this, it's definitely not me.   Go with God, little brother, and find happiness in your life and stop making kindergarten on forums.😂   I don't need clients like that for free - who can't even look at payment methods and immediately become aggressive - and you always use free goods, just like your favorites from the Brazilian forum, you apparently have a fever about this - I have nothing against it - we had a nice conversation, everything is fine.            
    • Looking to release interface source from newer clients, if you got a client message me on discord: ilikebeer.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..