Witam, poszukuję kogoś, kto pomoże mi napisać NPC do Canary 13.40, który będzie miał 10 misji polegających na zabijaniu potworów i bossów oraz dostarczaniu przedmiotów. NPC, których próbuję dodać, nie liczą zabitych potworów.
Witam, poszukuję kogoś, kto pomoże mi napisać NPC do Canary 13.40, który będzie miał 10 misji polegających na zabijaniu potworów i bossów oraz dostarczaniu przedmiotów. NPC, których próbuję dodać, nie liczą zabitych potworów.
local internalNpcName = "Benjamin"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}
npcConfig.name = internalNpcName
npcConfig.description = internalNpcName
npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 2
npcConfig.outfit = {
lookType = 128,
lookHead = 116,
lookBody = 79,
lookLegs = 117,
lookFeet = 76,
lookAddons = 0
}
npcConfig.flags = {
floorchange = false
}
npcConfig.voices = {
interval = 15000,
chance = 50,
{ text = 'Welcome to the post office!' },
{ text = 'If you need help with letters or parcels, just ask me. I can explain everything.' },
{ text = 'Hey, send a letter to your friend now and then. Keep in touch, you know.' }
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
npcType.onThink = function(npc, interval)
npcHandler:onThink(npc, interval)
end
npcType.onAppear = function(npc, creature)
npcHandler:onAppear(npc, creature)
end
npcType.onDisappear = function(npc, creature)
npcHandler:onDisappear(npc, creature)
end
npcType.onMove = function(npc, creature, fromPosition, toPosition)
npcHandler:onMove(npc, creature, fromPosition, toPosition)
end
npcType.onSay = function(npc, creature, type, message)
npcHandler:onSay(npc, creature, type, message)
end
npcType.onCloseChannel = function(npc, creature)
npcHandler:onCloseChannel(npc, creature)
end
local function creatureSayCallback(npc, creature, type, message)
local player = Player(creature)
local playerId = player:getId()
if not npcHandler:checkInteraction(npc, creature) then
return false
end
if MsgContains(message, "measurements") then
local player = Player(creature)
if player:getStorageValue(Storage.Postman.Mission07) >= 1 and player:getStorageValue(Storage.Postman.MeasurementsBenjamin) ~= 1 then
npcHandler:say("Oh they don't change that much since in the old days as... <tells a boring and confusing story about a cake, a parcel, himself and two squirrels, at least he tells you his measurements in the end> ", npc, creature)
player:setStorageValue(Storage.Postman.Mission07, player:getStorageValue(Storage.Postman.Mission07) + 1)
player:setStorageValue(Storage.Postman.MeasurementsBenjamin, 1)
npcHandler:setTopic(playerId, 0)
else
npcHandler:say("...", npc, creature)
npcHandler:setTopic(playerId, 0)
end
end
return true
end
npcHandler:setMessage(MESSAGE_GREET, "Hello. How may I help you |PLAYERNAME|? Ask me for a {trade} if you want to buy something. I can also explain the {mail} system.")
npcHandler:setMessage(MESSAGE_FAREWELL, "It was a pleasure to help you.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)
npcConfig.shop = {
{ itemName = "label", clientId = 3507, buy = 1 },
{ itemName = "letter", clientId = 3505, buy = 8 },
{ itemName = "parcel", clientId = 3503, buy = 15 }
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks)
end
-- On sell npc shop message
npcType.onSellItem = function(npc, player, itemId, subtype, amount, ignore, name, totalCost)
player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("Sold %ix %s for %i gold.", amount, name, totalCost))
end
-- On check npc shop message (look item)
npcType.onCheckItem = function(npc, player, clientId, subType)
end
npcType:register(npcConfig)
local internalNpcName = "Missionary"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}
npcConfig.name = internalNpcName
npcConfig.description = internalNpcName
npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 2
npcConfig.outfit = {
lookType = 128,
lookHead = 116,
lookBody = 79,
lookLegs = 117,
lookFeet = 76,
lookAddons = 0
}
npcConfig.flags = {
floorchange = false
}
npcConfig.voices = {
interval = 15000,
chance = 50,
{ text = 'New Missions!' },
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
npcType.onThink = function(npc, interval)
npcHandler:onThink(npc, interval)
end
npcType.onAppear = function(npc, creature)
npcHandler:onAppear(npc, creature)
end
npcType.onDisappear = function(npc, creature)
npcHandler:onDisappear(npc, creature)
end
npcType.onMove = function(npc, creature, fromPosition, toPosition)
npcHandler:onMove(npc, creature, fromPosition, toPosition)
end
npcType.onSay = function(npc, creature, type, message)
npcHandler:onSay(npc, creature, type, message)
end
npcType.onCloseChannel = function(npc, creature)
npcHandler:onCloseChannel(npc, creature)
end
local function creatureSayCallback(npc, creature, type, message)
local player = Player(creature)
local playerId = player:getId()
if not npcHandler:checkInteraction(npc, creature) then
return false
end
if MsgContains(message, "mission") then
local player = Player(creature)
if player:getStorageValue(250000) >= 10 then
npcHandler:say("You have killed 10 of this monsters, here is your reward. ", npc, creature)
player:setStorageValue(250000, 0)
player:addItem(2160, 10)
npcHandler:setTopic(playerId, 0)
else
npcHandler:say("You should kill 10 Demons.", npc, creature)
npcHandler:setTopic(playerId, 0)
end
end
return true
end
npcHandler:setMessage(MESSAGE_GREET, "Hello. How may I help you |PLAYERNAME|? Ask me for a {mission} to kill monsters.")
npcHandler:setMessage(MESSAGE_FAREWELL, "It was a pleasure to help you.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
npc:sellItem(player, itemId, amount, subType, 0, ignore, inBackpacks)
end
-- On sell npc shop message
npcType.onSellItem = function(npc, player, itemId, subtype, amount, ignore, name, totalCost)
player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("Sold %ix %s for %i gold.", amount, name, totalCost))
end
-- On check npc shop message (look item)
npcType.onCheckItem = function(npc, player, clientId, subType)
end
npcType:register(npcConfig)
local monsters = {
["demon"] = {storage = 250000},
}
local monstersOnKill = CreatureEvent("MonstersOnKill")
function monstersOnKill.onKill(creature, target)
local targetMonster = target:getMonster()
if not targetMonster or targetMonster:getMaster() then
return true
end
local monsterConfig = monsters[targetMonster:getName():lower()]
if not monsterConfig then
return true
end
for key, value in pairs(targetMonster:getDamageMap()) do
local attackerPlayer = Player(key)
if attackerPlayer then
if monsterConfig.storage then
attackerPlayer:setStorageValue(monsterConfig.storage, 1)
end
end
end
return true
end
monstersOnKill:register()
Probably, not sure but;thank you, I put the npc in the NPC folder and put it in the game, after writing hi it gives me the task to kill demons. I put monsteronkill.lua in the script folder while killing demons and it still doesn't count them, I set storage. I don't have any errors in the console, do I need to reset this onkill somewhere as an event or is it enough to add it to the script?





