• 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!

Sub-Class System Npc

luigilc

Lua Learner
Joined
Mar 24, 2010
Messages
863
Reaction score
36
Location
A music box
A few days ago in the support board Darkhaos came up with this script for a sub-class system npc, but I have no clue how to edit to make it work properly, what it should do is: When I have X vocation I can choose which 'sub-class' I want.
Here is the script he posted(with my edited vocations):
Lua:
local vocations = 
{
	--[Apprentice] = {Mage, Ranger, Warrior}
	[0] = {1, 2, 3}
	
	-----[Mage Sub-Classes]-----
	
	--[Mage] = {Elementalist, Wizard}
	[1] = {4, 5},
	--[Elementalist] = {Pyromancer, Stormcaller}
	[4] = {10, 11},
	--[Wizard] = {warlock, necromancer}
	[5] = {12, 13},
	--[Pyromancer] = {Fiery lord, pyro maniac}
	[10] = {22, 23},
	--[Stormcaller] = {Arcano, Cold Conjurer}
	[11] = {24, 25}
	--[Warlock] = {Archwizard, Overlord}
	[10] = {26, 27},
	--[Necromancer] = {Cultist, Lich}
	[11] = {248, 29}
 
    -----[Ranger Sub-Classes]-----
	
	--[Ranger] = {Archer, Outlaw}
	[2] = {6, 7},
	--[Archer] = {Shooter, Lancer}
	[6] = {14, 15},
	--[Outlaw] = {rogue, bard}
	[7] = {16, 17},
	--[Shooter] = {Sharpshooter, Tactician}
	[14] = {30, 31},
	--[Lancer] = {Hunter, Saboteur}
	[15] = {32, 33}
	--[Rogue] = {Assassin, Nightblader}
	[16] = {34, 35},
	--[Bard] = {Composer, Orchestral Maestro}
	[17] = {36, 37}
	
    -----[Warrior Sub-Classes]-----
	
	--[Warrior] = {Sentinel, Warlord}
	[3] = {8, 9},
	--[Sentinel] = {Champion, Inquisitor}
	[8] = {18, 19},
	--[Warlord] = {blader, barbarian}
	[9] = {20, 21},
	--[Champion] = {Paragon, Guardian}
	[18] = {38, 39},
	--[Inquisitor] = {Templar, Justicar}
	[19] = {40, 41}
	--[Blader] = {Blade Dancer, Blade Conjurer}
	[20] = {42, 43},
	--[Barbarian] = {Void Knight, Avenger}
	[21] = {44, 45}
}
 
if msg:lower() == "promotion" then
	if not vocations[getPlayerVocation(cid)] and getPlayerVocation(cid) > 0 then
		return npcHandler:say("You already have 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
If anyone can make the full script I'll appreciatte it big time, thanks!
 
Try this one
Not tested.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)                  npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                                      npcHandler:onThink() end

local vocations = 
{
	--[Apprentice] = {Mage, Ranger, Warrior}
	[0] = {1, 2, 3},
 
	-----[Mage Sub-Classes]-----
 
	--[Mage] = {Elementalist, Wizard}
	[1] = {4, 5},
	--[Elementalist] = {Pyromancer, Stormcaller}
	[4] = {10, 11},
	--[Wizard] = {warlock, necromancer}
	[5] = {12, 13},
	--[Pyromancer] = {Fiery lord, pyro maniac}
	[10] = {22, 23},
	--[Stormcaller] = {Arcano, Cold Conjurer}
	[11] = {24, 25},
	--[Warlock] = {Archwizard, Overlord}
	[10] = {26, 27},
	--[Necromancer] = {Cultist, Lich}
	[11] = {248, 29},
 
    -----[Ranger Sub-Classes]-----
 
	--[Ranger] = {Archer, Outlaw}
	[2] = {6, 7},
	--[Archer] = {Shooter, Lancer}
	[6] = {14, 15},
	--[Outlaw] = {rogue, bard}
	[7] = {16, 17},
	--[Shooter] = {Sharpshooter, Tactician}
	[14] = {30, 31},
	--[Lancer] = {Hunter, Saboteur}
	[15] = {32, 33},
	--[Rogue] = {Assassin, Nightblader}
	[16] = {34, 35},
	--[Bard] = {Composer, Orchestral Maestro}
	[17] = {36, 37},
 
    -----[Warrior Sub-Classes]-----
 
	--[Warrior] = {Sentinel, Warlord}
	[3] = {8, 9},
	--[Sentinel] = {Champion, Inquisitor}
	[8] = {18, 19},
	--[Warlord] = {blader, barbarian}
	[9] = {20, 21},
	--[Champion] = {Paragon, Guardian}
	[18] = {38, 39},
	--[Inquisitor] = {Templar, Justicar}
	[19] = {40, 41},
	--[Blader] = {Blade Dancer, Blade Conjurer}
	[20] = {42, 43},
	--[Barbarian] = {Void Knight, Avenger}
	[21] = {44, 45}
}

local promotions = {}
local choose = {}
function creatureSayCallback(cid, type, msg)
 
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
 
	if msg:lower() == "promotion" then
		if not vocations[getPlayerVocation(cid)] and getPlayerVocation(cid) > 0 then
			return npcHandler:say("You already have the highest promotion.", cid)
		end
	 
		promotions[cid] = {}
		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
			table.insert(promotions[cid], getVocationInfo(id).name:lower())
		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 talkState[talkUser] == 1 and isInArray(promotions[cid], msg:lower()) then
		npcHandler:say("Are you sure do you want to be promoted to {" .. msg:lower() .. "}?", cid)
		talkState[talkUser] = 2
		choose[cid] = getVocationByName(msg)
	elseif talkState[talkUser] == 2 then
		if msg:lower() == "yes" then
			doPlayerSetVocation(cid, choose[cid])
			npcHandler:say("Congratulations! You have been promoted to " .. getVocationInfo(choose[cid]).name .. ".", cid)
			choose[cid] = nil
			promotions[cid] = nil
			talkState[talkUser] = 0
		else
			npcHandler:say("Ok then.", cid)
			choose[cid] = nil
			promotions[cid] = nil
			talkState[talkUser] = 0
		end
	end
	return true
end
			
			
function getVocationByName(name)
	for k, v in pairs(vocations) do
		for _, voc in ipairs(v) do
			if getVocationInfo(voc).name:lower() == name:lower() then
				return voc
			end
		end
	end
	return 0
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Thanks that worked just great!
Just 1 thing, how can I edit it to check player lvl? Like for 1st promotion u need lvl 8, second lvl 30, third lvl 50 forth lvl 100?
If you could do that I'd be very happy!

You must spread some Reputation around before giving it to Darkhaos again.

- - - Updated - - -

Bump
 
Can anyone edit it to check player lvl? Like for 1st promotion u need lvl 8, second lvl 30, third lvl 50 forth lvl 100?
If you could do that I'd be very happy!
 
Back
Top