What's new

Promotion npc tfs 1.2

sempele

Active User
Joined
Nov 19, 2010
Messages
107
Reaction score
3
Cześć. Pomoże ktoś poprawić skrypt ? Chodzi o to, że NPC sprawdza czy mamy potrzebne przedmioty, gdy mamy otrzymujemy promocję, ale przedmioty dalej zostają w plecaku, nie znikają
Code:
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, 2}}, level = 20, name = "first"},
    [2] = {items = {{11754, 1}}, 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 - 1 < 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:getItemCount(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())
 

Placek

Blue Waffle
Joined
Sep 30, 2008
Messages
6,793
Reaction score
672
Age
8
Ło boże ale brzydki skrypt.
Ale generalnie brakuje jednego fora na itemy w miejscu gdzie masz dodawanie promocji.
Coś na zasadzie:
Code:
  for i = 1, #PROMO.items do
    player:doItemRemove(PROMO.items[i][1], PROMO.items[i][2])
  end
# obok
       player:setVocation(Vocation(vocId + vocationCount))
Nie wiem tylko czy jest coś takiego jak player:doItemRemove, bo może się to nazywać inaczej. Nie chce mi się szukać dokumentacji, ale powinieneś dać radę :D
 
Top