convert to npc canary
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 config = { price = 10000, newlevel = 8, priceByReset = 0, percent = 10, maxresets = 50, levelbyreset = 0, redskull = false, -- need to be without redskull to reset? battle = true, -- need to be without battle to reset? pz = false, -- need to be in protect zone to reset? stages = { {resets = 4, level = 350, premium = 330}, {resets = 9, level = 355, premium = 340}, {resets = 14, level = 360, premium = 355}, {resets = 19, level = 365, premium = 360}, {resets = 24, level = 380, premium = 370}, {resets = 29, level = 390, premium = 380}, {resets = 34, level = 410, premium = 400}, {resets = 39, level = 430, premium = 420}, {resets = 44, level = 450, premium = 440}, {resets = 49, level = 480, premium = 470}, {resets = 54, level = 510, premium = 500}, {resets = 59, level = 550, premium = 540}, {resets = 64, level = 590, premium = 580}, {resets = 69, level = 630, premium = 620}, {resets = 74, level = 680, premium = 670}, {resets = 79, level = 730, premium = 720}, {resets = 84, level = 780, premium = 770}, {resets = 89, level = 860, premium = 840}, {resets = 94, level = 930, premium = 910}, {resets = 2^1024, level = 1010, premium = 990} } } local function getExperienceForLevel(lv) lv = lv - 1 return ((50 * lv * lv * lv) - (150 * lv * lv) + (400 * lv)) / 3 end local function getResets(uid) local player = Player(uid) local resets = 0 if player then resets = math.max(0, player:getStorageValue(500)) end return resets end local function addReset(uid) local player = Player(uid) if player then local resets = getResets(uid) local hp = player:getMaxHealth() local resethp = hp * (config.percent / 100) player:setMaxHealth(resethp) local mana = player:getMaxMana() local resetmana = mana * (config.percent / 100) player:setMaxMana(resetmana) local playerid = player:getGuid() player:remove() db.query("UPDATE `players` SET `resets`=" .. resets + 1 .. ",`experience`= 0 WHERE `players`.`id`= " .. playerid .. "") db.query("UPDATE `players` SET `level`=" .. config.newlevel .. ",`experience`= 0 WHERE `players`.`id`= " .. playerid .. "") end return true end function creatureSayCallback(cid, type, msg) if not npcHandler:isFocused(cid) then return false end local player = Player(cid) if not player then return false end local newPrice = config.price + (getResets(cid) * config.priceByReset) if config.redskull and player:getSkull() == SKULL_RED then player:sendCancelMessage("You need to be without red skull to reset.") return true elseif config.pz and not getTilePzInfo(player:getPosition()) then player:sendCancelMessage("You need to be in a protection zone to reset.") return true elseif config.battle and player:getCondition(CONDITION_INFIGHT) then player:sendCancelMessage("You need to be without battle to reset.") return true end local resetLevel = 0 for x, y in ipairs(config.stages) do if getResets(cid) <= y.resets then resetLevel = player:isPremium() and y.premium or y.level break end end if getPlayerLevel(player) < resetLevel then player:sendCancelMessage("You need level " .. resetLevel .. " or more to reset.") return true end local newminlevel = resetLevel + (getResets(cid) * config.levelbyreset) if msgcontains(msg, 'reset') then if getResets(cid) < config.maxresets then npcHandler:say('You want to reset your character? It will cost ' .. newPrice .. ' gp\'s!', cid) npcHandler.topic[cid] = 1 else npcHandler:say('You already reached the maximum reset level!', cid) end return true elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then if player:getLevel() > newminlevel then if player:removeMoney(newPrice) then addEvent(function() if isPlayer(cid) then addReset(cid) end end, 3000) local number = getResets(cid) + 1 local msg = "---[Reset: " .. number .. "]-- You have reseted! You'll be disconnected in 3 seconds." player:popupFYI(msg) npcHandler.topic[cid] = 0 npcHandler:releaseFocus(cid) else npcHandler:say('It\'s necessary to have at least ' .. newPrice .. ' gp\'s for resetting!', cid) end else npcHandler:say('The minimum level for resetting is ' .. newminlevel .. '!', cid) end return true elseif msgcontains(msg, 'no') and isInArray({1}, npcHandler.topic[cid]) then npcHandler.topic[cid] = 0 npcHandler:releaseFocus(cid) npcHandler:say('Ok.', cid) return true elseif msgcontains(msg, 'quantity') then npcHandler:say('You have a total of ' .. getResets(cid) .. ' reset(s).', cid) npcHandler.topic[cid] = 0 return true end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())