Creatureevent:
local points_per_level = xxx --Quantos pontos por nível o jogador irá ganhar.
function onAdvance(cid, skill, oldLevel, newLevel)
local level_difference, points_gain, points_count = newLevel - oldLevel, points_per_level, getPlayerStorageValue(cid, 3920) < 0 and 0 or getPlayerStorageValue(cid, 3920)
if newLevel <= getPlayerStorageValue(cid, 3919) or skill ~= SKILL__LEVEL then
return true
elseif level_difference > 1 then
points_gain = points_gain * level_difference
end
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..points_gain.."x point(s) to trade in a NPC for more HP and mana. You have now <"..(points_count + points_gain).."> point(s).")
setPlayerStorageValue(cid, 3919, newLevel)
setPlayerStorageValue(cid, 3920, points_count + points_gain)
return true
end
local config = {
health = {points = xxx, amount = xxx}, --{points = quantidade_de_pontos, amount = quantidade_de_HP_ganha},
mana = {points = xxx, amount = xxx} --{points = quantidade_de_pontos, amount = quantidade_de_mana_ganha}
}
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)
msg = msg:lower()
if not npcHandler:isFocused(cid) then
return false
end
local talkUser, player_points = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid, getPlayerStorageValue(cid, 3920)
if msgcontains(msg, "points") or msgcontains(msg, "trade") then
selfSay("I can give you a little more HP and mana in exchange for some points. What do you think? Do you accept my offer?", cid)
talkState[talkUser] = 1
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
selfSay("Well, I can give you {"..config.health.amount.." extra HP} for {"..config.health.points.." points}, and {"..config.mana.amount.." extra mana} for {"..config.mana.points.." points}.", cid)
selfSay("Would you like more {hp} or more {mana}?", cid)
talkState[talkUser] = 2
elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
selfSay("No problem, sir.", cid)
talkState[talkUser] = 0
elseif talkState[talkUser] == 2 then
local info_table = {
["hp"] = {setCreatureMaxHealth, getCreatureMaxHealth, doCreatureAddHealth, config.health.points, config.health.amount},
["mana"] = {setCreatureMaxMana, getCreatureMaxMana, doCreatureAddMana, config.mana.points, config.mana.amount}
}
local func = info_table[msg]
if not func then
selfSay("I told you to tell me if you'd like more {hp} or more {mana}.", cid)
elseif player_points < func[4] then
selfSay("You do not have enough points to exchange.", cid)
else
if player_points >= func[4] * 2 then
local multiplier = math.floor(player_points / func[4])
func[4] = func[4] * multiplier
func[5] = func[5] * multiplier
end
selfSay("Here you are: "..func[5].." more "..msg.." for "..func[4].." points.", cid)
setPlayerStorageValue(cid, 3920, player_points - func[4])
func[1](cid, func[2](cid) + func[5])
func[3](cid, func[2](cid))
talkState[talkUser] = 0
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())





info
Grupo: Campones
Registrado: 01/10/15
Posts: 72
Reputação: +4
Fala Galerinha estou precisando de um sitemas onde o player ao upar ganha X pontos e estes pontos ele pode trocar por LIFE ou MANA em um npc
estilo TIBIA GTA