Mateus Robeerto
Excellent OT User
Good morning, can someone teach me how to use the function by NPC? I just want to learn how this function works. For example, an NPC with Master Sorcerer ID 5 and who switches to Nova with Supreme Sorcerer ID 9, as I have 4 different vocations. Can someone explain the basics of functions?
I found these functions in lib/compat: 'getPlayerVocation', 'getVocation' and 'setVocation'. I also found another function called 'getVocation'. I want to create a table with the following correspondences: id 5-9, 6-10, 7-11 and 8-12. However, I can't add the function that allows switching to new vocations. I tried to add another function that increases +4 in vocations using 'getPlayerVocation(cid)+4' but it didn't work. Can someone explain just these functions?
Can someone help me try to put a table by vocation? I want something similar to this table that I put, but so far nothing is working
I found these functions in lib/compat: 'getPlayerVocation', 'getVocation' and 'setVocation'. I also found another function called 'getVocation'. I want to create a table with the following correspondences: id 5-9, 6-10, 7-11 and 8-12. However, I can't add the function that allows switching to new vocations. I tried to add another function that increases +4 in vocations using 'getPlayerVocation(cid)+4' but it didn't work. Can someone explain just these functions?
Post automatically merged:
Can someone help me try to put a table by vocation? I want something similar to this table that I put, but so far nothing is working
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local vocations = {
[5] = {id = 9, name = "Supreme Sorcerer"},
[6] = {id = 10, name = "Supreme Druid"},
[7] = {id = 11, name = "Supreme Paladin"},
[8] = {id = 12, name = "Supreme Knight"},
}
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)
local pid = getPlayerGUID(cid)
if (not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if (msgcontains(msg, 'supreme') or msgcontains(msg, 'voc')) then
selfSay('Considering all the presented information, do you really want to perform a Master Reset? This process costs 100 vip coins and is irreversible! Say {yes} to confirm.', cid)
talkState[talkUser] = 1
elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if doPlayerRemoveItem(cid, 6527, 100) then
-- Set health to 185
doCreatureAddHealth(cid, -getCreatureHealth(cid) + 185)
setCreatureMaxHealth(cid, 185)
-- Set mana to 35
doCreatureAddMana(cid, -getCreatureMana(cid) + 35)
setCreatureMaxMana(cid, 35)
doTeleportThing(cid, getTownTemplePosition(1))
doRemoveCreature(cid)
local reset_level = "UPDATE players SET level = 30 WHERE id = " .. pid .. ";"
local reset_query = "UPDATE players SET reset = 0 WHERE id = " .. pid .. ";"
local reset_exp = "UPDATE players SET experience = 4200 WHERE id = " .. pid .. ";"
db.query(reset_exp)
db.query(reset_query)
db.query(reset_level)
local newVocation = vocations[getPlayerVocation(cid)]
if newVocation ~= nil then
doPlayerSetVocation(cid, newVocation.id)
selfSay("Congratulations! You have successfully reborn and your new vocation is " .. newVocation.name .. ".", cid)
else
selfSay("Congratulations! You have successfully reborn.", cid)
end
else
selfSay("You don't have 100 event tokens", cid)
end
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Last edited: