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

TFS 1.X+ TFS 1.2 Promotion NPC

Xarvi

New Member
Joined
Aug 20, 2020
Messages
51
Reaction score
2
Hello. I get error on console when i write to NPC Hi>Promotion
2.png
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())
 
post the script again after you changed it
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 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:getItemById(PROMO.items[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())
 
the function should actually be player:getItemCount instead
and next time don't say it's the same error, actually read it first before saying that :)
 
Back
Top