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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...