Jump to content
  • 0

How to buy a skill?


Question

Posted

can someoine tell me how to set an npc up so you can click on a link, the npc will take an item from you, and in return you get a brand new skill on your skill list or another skill in the game.

 

 

let say I want to sell the gm haste skill for an item in the game, when i char buys the skill, it gives it to their skill list, and take the item.

 

 

this is what I would like to do. how do i set this up...please help me if you have idea.

3 answers to this question

Recommended Posts

  • 0
Posted

for a quest script...

public String onAdvEvent(L2Npc npc, L2PcInstance player, String event)
{
String html = event;

if(event.startsWith("buyskill")
{	
	String[] split = event.split("_");
	if(split.lenght < 3)
	{	
		//Handle a warning or something...
		html = "error.htm";
	}
	else
	{	
		int id = 0, lvl = 0;
		try
		{
			id = Integer.parseInt(split[1]);
			lvl = Integer.parseInt(split[2]);
		}
		catch(NumberFormatException nfe)
		{		
			//Handle it
		}
		if(id > 0 && lvl > 0)
		{
			final L2Skill sk = SkillTable.getInstance().getInfo(id, lvl);
			if(sk == null)
				html = "noexist.htm";
			else if(....)
			{
				//Check if the skill exsist into the allowed skills to buy
				//otherwise, player could buy any skill by modding the packet
			}
			else
			{		
				if(player.destroyItemByItemId("SkillBuy", YOUR_ITEM_ID, YOUR_ITEM_AMOUNT, npc, true))
				{
					player.addSkill(sk, true); //true = save to database
					player.sendSkillList();
					html = "buysuccess.htm";
				}
				else
					html = "notenoughitems.htm";
			}
		}
	}
}
return html;

}

  • 0
Posted

here. I made it to show you how its done. As you can see, its inside a method called onAdvEvent, a method that can be inherited from Quest class that is in charge of parse the quest htmls bypasses

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
×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock