• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua How to create promotion vocational tree?

Jabbawack

Writer / Mapper / Artist
Joined
Apr 11, 2012
Messages
51
Reaction score
3
Location
Ohio, United States of America
Hiya,
First off, let me thank you for your time looking at this post of mine.

Now, I would like to ask how I could create a vocation tree with promotions. Something like this:


............VocationA
.........._____|_____
.........|.................|
...VocationB......VocationC


I have a ton of vocations I have created that all end up splitting from VocationA into a choice of either VocationB or VocationC. From what I was given to work with (not being an excellent scripter myself), I used a promotion NPC to give the promotion from VocationA to VocationB, but I want VocationC to be a choice too.

Honestly I have no idea where to start from this, and I would appreciate (and rep++) anything that helps...

I'm using TFS 0.3.6 if that is of any use.
 
Well normally when using TFS you have to do the multiple vocation branch selection by script. by doing "doPlayerSetVocation(cid, id)"

where id is the id given in the XML file "vocations.xml"

XML:
[I]<[B]vocation id="9" -- This is what the id you set with the lua function[/B]
name="Epic Master Sorcerer"
description="an epic master sorcerer"
needpremium="0"
gaincap="10"
gainhp="5"
gainmana="30"
gainhpticks="4"
gainhpamount="10"
gainmanaticks="2"
gainmanaamount="10"
manamultiplier="1.1"
attackspeed="2000"
soulmax="200"
gainsoulticks="15"
[B]fromvoc="5" -- This is the previous vocation in the branch[/B]
lessloss="50">[/I]


so a good script for creating a vocation tree would be something like this:

remember, i don't have time to create the script i just made an example of how it could work;

Lua:
--Vocation IDs
local Apprentice = 1
local Wizard = 8
local Mage = 11

local VocationTree = 
{
[Apprentice] = {Wizard, Mage};
}
function getAvailableVocationNames(vocation)
 local t = {}
 for id, data in pairs(VocationTree[vocation]) do
  t:insert(getVocationName(vocation))
 end
 return t
end
function onEvent(cid, words)
local voc = getPlayerVocation(cid)
 if VocationTree[voc] then
  local x = getAvailableVocationNames(voc)
  doSendPlayerMessage(cid, "You can be promoted to " .. x.Serialize());
 else
  --Vocation doesn't have any more promotions
  doSendPlayerCancel(cid, "You already have the last promotion!");
 end
end
 
Looks good!

I've got all the rank numbers figured, now it all comes down to trying to get this promotion tree to work. I can maybe take the example you gave me and create a request thread for it? After I try and work on it myself first! ;P

As stated before, I'm not really at all a scripter, so I probably won't have much luck myself. Thank you for what you given me, though! (rep++)

--

If anyone else could add a bit more help to this, much would be appreciated!
 
I am intrigued about making a Vocation Tree system, have been for a long time, but never had time to do it.

It would be a significant amount of work to make the system full, and not use shortcut hacks that will lead to breakage later as you tried to expand it.

I will give a look to writing you a more significantly advanced example that MindRage's input, however elegant it may be, sometime tomorrow. Tonight, I go to Birthday Massacre at the Hawthorne Theater.

One thing I would like to know... Is there linear parts as well?

For example
Code:
                                       Divine Machinegun
                                      /
                        Holy Artillery                                      PyroShuriken
                       /              \                                    /
Paladin -> Royal Archer                God Buster           Elemental Ninja--ElectroShuriken
                       \                                   /               \
                        Khraos Sniper -> Souldrain Assassin                 CryoShuriken
                                                           \
                                                            Elita Tong -> Elita Fett -> Elita Leon
 
My idea will stem around parsing the vocations xml directly and building the tree on the fly that way the user doesn't have to edit the script. A few simple source edits will allow tags to be put in the vocation xml so that the necessary info can be extracted from the existing Lua function getVocationInfo(id)

A simple elegant extensible solution. Perhaps even make it simpler by using the existing NPC module as a template and making a new extended one so all the user has to do is use keywordHandler:addKeyword and addChildKeyword in the NPC lua.
 
I did something like that a few months ago, it was pretty bad tho, always thought of that as an awesome idea but never could implement it correctly :/
 
Just create the vocations, and let you choose only two depending on your voacion by the NPC.

example something like:
Lua:
local vocations = 
{
	--[sorc] = {master sorc}
	[1] = {5},
	--[druid] = {elder druid}
	[2] = {6},
	--[paladin] = {royal paladin}
	[3] = {7},
	--[knight] = {elite knight}
	[8] = {8},
	--[master sorc] = {epic sorc, noob sorc}
	[5] = {9, 13},
	--[elder druid] = {epic druid, noob druid}
	[6] = {10, 14}
	
	---and bla bla...
}

if msg:lower() == "promotion" then
	if not vocations[getPlayerVocation(cid)] and getPlayerVocation(cid) > 0 then
		return npcHandler:say("You already has the highest promotion.", cid)
	end
	
	local vocs = vocations[getPlayerVocation(cid)]
	local sep = ", "
	local i = 0
	local text = ""
	for _, id in pairs(vocs) do
		i = i + 1
		if i == #vocs - 1 then
			sep = " and "
		elseif i == #vocs then
			sep = "."
		end
		text = text .. "{" .. getVocationInfo(id).name .. "}" .. sep
	end
	npcHandler:say("You can choose " .. (#vocs > 1 and "one between" or "") .. " the following promotion" .. (#vocs > 1 and "s" or "") .. ": " .. text .. ". Wich will you select?", cid)
	talkState[talkUser] = 1
elseif --blablabla

Also, you must set the field 'fromvoc="x"' with the same id of the vocation id being edited at vocations.xml.
 
Yes, you can add many options with this script

Example
Lua:
local vocations = 
{
	--[sorc] = {master sorc}
	[1] = {5},
	--[druid] = {elder druid}
	[2] = {6},
	--[paladin] = {royal paladin}
	[3] = {7},
	--[knight] = {elite knight}
	[8] = {8},
	--[master sorc] = {epic sorc, noob sorc, super sorc, mega sorc}
	[5] = {9, 13, 17, 21},
	--[elder druid] = {epic druid, noob druid, super druid, mega druid, ultimate druid}
	[6] = {10, 14, 18, 22, 26}
 
	---and bla bla...
}
 
if msg:lower() == "promotion" then
	if not vocations[getPlayerVocation(cid)] and getPlayerVocation(cid) > 0 then
		return npcHandler:say("You already has the highest promotion.", cid)
	end
 
	local vocs = vocations[getPlayerVocation(cid)]
	local sep = ", "
	local i = 0
	local text = ""
	for _, id in pairs(vocs) do
		i = i + 1
		if i == #vocs - 1 then
			sep = " and "
		elseif i == #vocs then
			sep = "."
		end
		text = text .. "{" .. getVocationInfo(id).name .. "}" .. sep
	end
	npcHandler:say("You can choose " .. (#vocs > 1 and "one between" or "") .. " the following promotion" .. (#vocs > 1 and "s" or "") .. ": " .. text .. ". Wich will you select?", cid)
	talkState[talkUser] = 1
elseif --blablabla
 
Back
Top