demonrage
New Member
- Joined
- Oct 28, 2014
- Messages
- 22
- Reaction score
- 2
Hello guys, could someone help me set this NPC to ask for an item when it resets.
otx2
Npc:
otx2
Npc:
LUA:
local config = {
minlevel = 800, --- initial level to reset
price = 10000000, ---initial price to reset
priceByReset = 10000000, --- price added per reset
maxresets = 5,
levelbyreset = 0 --- how much more level will you need in the next reset
}
function getResets(uid)
resets = getPlayerStorageValue(uid, 14335)
if resets < 0 then
resets = 0
end
return resets
end
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
function addReset(cid)
if(npcHandler:isFocused(cid)) then
npcHandler:releaseFocus(cid)
end
talkState[talkUser] = 0
resets = getResets(cid)
setPlayerStorageValue(cid, 14335, resets+1)
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
doRemoveCreature(cid)
local description = resets+1
db.query("UPDATE `players` SET `description` = ' [Reset: "..description.."]' WHERE `players`.`id`= ".. playerid .."")
return true
end
local newPrice = config.price + (getResets(cid) * config.priceByReset)
local newminlevel = config.minlevel + (getResets(cid) * config.levelbyreset)
if msgcontains(msg, 'awaken') then
if getResets(cid) < config.maxresets then
selfSay('Voce gostaria de despertar? Isso vai custar '..newPrice..' gp\'s' , cid)
talkState[talkUser] = 1
else
selfSay('Voce ja atingiu o nivel maximo de awakens!', cid)
end
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerMoney(cid) < newPrice then
selfSay('E necessesario ter '..newPrice..' gp\'s para Awaken!', cid)
elseif getPlayerLevel(cid) < newminlevel then
selfSay('O level minimo para Awaken e '..newminlevel..'!', cid)
else
doPlayerRemoveMoney(cid,newPrice)
playerid = getPlayerGUID(cid)
addEvent(function()
if isPlayer(cid) then
addReset(cid)
end
end, 3000)
local number = getResets(cid)+1
local msg ="---[Awaken: "..number.."]-- Voce Despertou! Voce sera disconectado em 3 segundos."
doPlayerPopupFYI(cid, msg)
talkState[talkUser] = 0
npcHandler:releaseFocus(cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no')) and isInArray({1}, talkState[talkUser]) == TRUE then
talkState[talkUser] = 0
npcHandler:releaseFocus(cid)
selfSay('Ok.', cid)
elseif msgcontains(msg, 'quantity') then
selfSay('You have a total of '..getResets(cid)..' Awaken(s).', cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())