Thorn
Spriting since 2013
Hello guys! I have a script for a npc that allows people to be promoted again.I have knights, elite knights and senior knights...and well ofc all the other vocations respective's promotions
So this npc is supose to promote you if youhave the first promotion(elite, elder, etc)
but right now, when players say the keyword "senior", he says: you already have the X(senior) promotion :/
can anyone plz help me figuring this out? i can't fully understand the script
Thanks in advance!!
So this npc is supose to promote you if youhave the first promotion(elite, elder, etc)
but right now, when players say the keyword "senior", he says: you already have the X(senior) promotion :/
can anyone plz help me figuring this out? i can't fully understand the script
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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 vocationCount = 4
local config = {
["first"] = { lvl = 20, cost = 1, id = 1 },
["senior"] = { lvl = 200, cost = 500000, id = 2 }
}
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
local pname = msg:lower()
local getPromotion = config[pname]
if not getPromotion then
return selfSay("The promotion you ask for does not exist.", cid)
end
local vocid = player:getVocation():getId()
local count = math.floor(vocid / vocationCount)
local canPromotion = (count - getPromotion.id)
if canPromotion < -1 then
return selfSay("You still can not acquire this promotion.", cid)
elseif canPromotion == 1 then
return selfSay("You can not degrade your promotion.", cid)
elseif canPromotion == 0 then
return selfSay(string.format("You already have the %s promotion.", pname), cid)
end
if player:getLevel() < getPromotion.lvl then
return selfSay(string.format("You need level %u+ for the %s promotion.", getPromotion.lvl, pname), cid)
end
if not player:removeMoney(getPromotion.cost) then
return selfSay("You do not have enough money.", cid)
end
local newVocation = Vocation(vocid + vocationCount)
player:setVocation(newVocation)
selfSay(string.format("You have been successfully promoted to %s.", newVocation:getName()), cid)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thanks in advance!!