Hello. I get error on console when i write to NPC Hi>Promotion
Script:
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() 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 promotions = {--itemid/amount
[1] = {items = {{2160, 5}, {9662, 5}}, level = 20, name = "first"},
[2] = {items = {{2160, 10}, {9662, 10}}, level = 50, name = "second"}
}
local vocationCount = 4
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "promotion") then
local PROMO = false
local vocId = player:getVocation():getId()
if vocId <= vocationCount then
PROMO = promotions[1]
elseif vocId > vocationCount and vocId < vocationCount * 2 then
PROMO = promotions[2]
end
if not PROMO then
return selfSay("You already have both promotions.", cid)
end
if player:getLevel() < PROMO.level then
return selfSay("You must be level "..PROMO.level.." for the "..PROMO.name.." promotion.", cid)
end
local hasItems = true
local text = "You need"
for i = 1, #PROMO.items do
if player:getItem(PROMO.items[i][1]) < PROMO.items[i][2] then
hasItems = false
local itemName = ItemType(PROMO.items[i][1]):getName()
if i == #PROMO.items then
text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."
else
text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."
end
end
end
if not hasItems then
return selfSay(text, cid)
end
player:setVocation(Vocation(vocId + vocationCount))
selfSay("You have recieved the "..PROMO.name.." promotion.", cid)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new()) npcHandler:onThink() end
local promotions = {--itemid/amount
[1] = {items = {{2160, 5}, {9662, 5}}, level = 20, name = "first"},
[2] = {items = {{2160, 10}, {9662, 10}}, level = 50, name = "second"}
}
local vocationCount = 4
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "promotion") then
local PROMO = false
local vocId = player:getVocation():getId()
if vocId <= vocationCount then
PROMO = promotions[1]
elseif vocId > vocationCount and vocId < vocationCount * 2 then
PROMO = promotions[2]
end
if not PROMO then
return selfSay("You already have both promotions.", cid)
end
if player:getLevel() < PROMO.level then
return selfSay("You must be level "..PROMO.level.." for the "..PROMO.name.." promotion.", cid)
end
local hasItems = true
local text = "You need"
for i = 1, #PROMO.items do
if player:getItem(PROMO.items[i][1]) < PROMO.items[i][2] then
hasItems = false
local itemName = ItemType(PROMO.items[i][1]):getName()
if i == #PROMO.items then
text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."
else
text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."
end
end
end
if not hasItems then
return selfSay(text, cid)
end
player:setVocation(Vocation(vocId + vocationCount))
selfSay("You have recieved the "..PROMO.name.." promotion.", cid)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())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 promotions = {--itemid/amount
[1] = {items = {{2160, 5}, {9662, 5}}, level = 20, name = "first"},
[2] = {items = {{2160, 10}, {9662, 10}}, level = 50, name = "second"}
}
local vocationCount = 4
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "promotion") then
local PROMO = false
local vocId = player:getVocation():getId()
if vocId <= vocationCount then
PROMO = promotions[1]
elseif vocId > vocationCount and vocId < vocationCount * 2 then
PROMO = promotions[2]
end
if not PROMO then
return selfSay("You already have both promotions.", cid)
end
if player:getLevel() < PROMO.level then
return selfSay("You must be level "..PROMO.level.." for the "..PROMO.name.." promotion.", cid)
end
local hasItems = true
local text = "You need"
for i = 1, #PROMO.items do
if player:getItem(PROMO.items[i][1]) < PROMO.items[i][2] then
hasItems = false
local itemName = ItemType(PROMO.items[i][1]):getName()
if i == #PROMO.items then
text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."
else
text = text.." "..PROMO.items[i][2].." "..itemName.."('s).."
end
end
end
if not hasItems then
return selfSay(text, cid)
end
player:setVocation(Vocation(vocId + vocationCount))
selfSay("You have recieved the "..PROMO.name.." promotion.", cid)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())