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

promotions problem...

MadMOOK

Hoo
Joined
Apr 20, 2011
Messages
802
Reaction score
43
@Ninja , @Limos
10.10 0.3.7
This script works untill I log off on character and I lose the new promotion!
Code:
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 =
{
--[Base Vocations] = {Sorcerer, Druid, Paladin, Knight}
[0] = {1, 2, 3, 4},

-----[Sorcerer Sub-Classes]-----
--[Sorcerer] = {Arcmage, Wizard}
[5] = {9, 13},

-----[Druid Sub-Classes]-----
--[Druid] = {Priest, Shaman}
[6] = {10, 14},

-----[Paladin Sub-Classes]-----
--[Paladin] = {Marksman, Master Archer}
[7] = {11, 15},

-----[Knight Sub-Classes]-----
--[Knight] = {Guardian, Barbarian}
[8] = {12, 16},
}

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 true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top