Explicação:
Você compra no npc a exp que você perdeu na sua última morte.
Lib > functions.lua adc
death_tabble = {before_exp = 135215,after_exp = 135216, check = 251201}
creaturescript/script
exp_buy.lua
function onLogin(cid)
registerCreatureEvent(cid, "Exp_P")
if getPlayerStorageValue(cid, death_tabble.check) >= 1 then
setPlayerStorageValue(cid, death_tabble.after_exp, getPlayerExperience(cid))
setPlayerStorageValue(cid, death_tabble.check, -1)
end
return true
end
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
setPlayerStorageValue(cid, death_tabble.before_exp, getPlayerExperience(cid))
setPlayerStorageValue(cid, death_tabble.check, 1)
return TRUE
end
creaturescript.xml
<event type="preparedeath" name="Exp_P" event="script" value="exp_buy.lua"/>
<event type="login" name="Exp_L" event="script" value="exp_buy.lua"/>
NPC:
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
local msg = string.lower(msg)
local itemid,count = 9020,10 -- edite o id e count do item aqui
if isInArray({"recover","recuperar","exp","experience"}, msg) then
npcHandler:say("você deseja recuperar a exp perdida após á sua morte por "..count.." "..getItemNameById(itemid).."? {yes}", cid)
talkState[talkUser] = 1
elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerStorageValue(cid, death_tabble.before_exp) ~= -1 and getPlayerExperience(cid) < getPlayerStorageValue(cid, death_tabble.before_exp) then
if doPlayerRemoveItem(cid, itemid, count) == TRUE then
local count = (getPlayerStorageValue(cid, death_tabble.before_exp) - getPlayerStorageValue(cid, death_tabble.after_exp))
doPlayerAddExp(cid, count)
npcHandler:say("Obrigado! aqui está sua experiência.", cid)
else
npcHandler:say("Desculpe, você não tem "..getItemNameById(itemid).." suficientes!", cid)
talkState[talkUser] = 0
end
else
npcHandler:say("Desculpe, você não morreu ou já recuperou sua exp perdida!", cid)
talkState[talkUser] = 0
end
elseif msg == "no" then
selfSay("Then not", cid)
talkState[talkUser] = 0
npcHandler:releaseFocus(cid)
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())