[Sorry i never has studdy english so i am sorry if it's dificult to understand me] (sorry :$)
Well I am trying to do a NPC that can offer others task or mission, for this i create a table on my DB (database) the name of the table is quest and have this colums (id, description) and in the table of players I add this column (quest_id) i make a FOREINGN KEY with them and now i can select a few quest on my characters
I put an example of my tables, Now i have this code for my NPC
I separate the code with some spacers to see better the code i want to do. The problem is this:
I create the NPC and put it somewhere, i speak to him and say "mision" and he tell my the text but in the database i put quest_id to 1 and when he speak he say that is on 0, The NPC is not taking the good number on the database and i think the code is good because when i search it on the Query DB show me this:
If a good scripter can help me to take the good number because i think is a fail of typedata or something similar but i dont understand a lot in lua code. If someone solve this, this NPC can help a lot in otland because you can create your own task and mission with any problems only you need follow the history quest_id 1 later 2 ... 3 and going ahead and if you jump to other num of quest only you need an if comparing the current quest_id to the next id_quest.
Thank you!
- - - Updated - - -
SOLVED
I solve this isue with this code:
Solved by myself.
Well I am trying to do a NPC that can offer others task or mission, for this i create a table on my DB (database) the name of the table is quest and have this colums (id, description) and in the table of players I add this column (quest_id) i make a FOREINGN KEY with them and now i can select a few quest on my characters
LUA:
TABLE PLAYERS TABLE QUEST
ID PLAYER QUEST_ID |||| ID DESCRIPTION
1 GOD XXXX 1 |||| 0 No quest
2 Player XX 0 |||| 1 Quest of honor
I put an example of my tables, Now i have this code for my NPC
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local questnum = {}
local talkUser = {}
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
if(msgcontains(msg, 'mision')) then
questnum = db.getResult("SELECT `quest_id` FROM `players` WHERE `name`=\"" .. getCreatureName(cid) .. "\";")
selfSay('Tu id es ' .. cid .. ' Viste?', cid)
selfSay('Tu id de mision es ' .. #questnum .. ' Viste?', cid)
selfSay("Tu id de mision es " .. #db.getResult("SELECT `quest_id` FROM `players` WHERE `name`=\"" .. getCreatureName(cid) .. "\";") .. " Viste?", cid)
selfSay('Quieres que te encomiende una mision ¿no? Bueno como sabras para ganarte mi respeto tendras que ir haciendo misiones poco a poco, para que pueda encargarte cada vez missiones que te traigan mas recompensas.', cid)
selfSay('Bueno ahora mismo atravesamos un momento muy amargo en la ciudad ya que las alcantarillas han sido invadidas por mounstruos. Una patrulla anda en las alcantarillas, busca al capitan y pidele que te entregue un libro. ¿Aceptas la mision?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
talkState[talkUser] = 0
selfSay('¡Bien! Muchas gracias por acerte cargo de esta tarea. La haria encantado pero perdi mi espada y hasta que no la encuentre no podre ayudar en las labores de defensa.')
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Si no quieres por ahora, mas tarde podras realizar mis misiones. Recuerda que te llevaras dinero honor gloria y mucha experiencia.', cid)
end
if(msgcontains(msg, 'libro')) then
selfSay('¿Has traido el libro que te pedi?', cid)
talkState[talkUser] = 2
elseif(msgcontains(msg, 'si') and talkState[talkUser] == 2) then
if(getPlayerItemCount(cid, 1950) >= 1) then
talkState[talkUser] = 0
selfSay('¡Bien! Este libro me sera de mucha utilidad.')
doPlayerAddExperience(cid, 3000)
doPlayerAddMoney(cid, 3000)
doPlayerRemoveItem(cid,1950,1)
else
talkState[talkUser] = 0
selfSay('No tienes el libro. Vuelve a las cloacas y busca al capitan para que te lo de.', cid)
end
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Si aun no lo has encontrado no se a que esperas. Vuelve cuando lo hayas encontrado. Busca al capitan en las alcantarillas', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
I separate the code with some spacers to see better the code i want to do. The problem is this:
I create the NPC and put it somewhere, i speak to him and say "mision" and he tell my the text but in the database i put quest_id to 1 and when he speak he say that is on 0, The NPC is not taking the good number on the database and i think the code is good because when i search it on the Query DB show me this:
LUA:
quest_id
1
If a good scripter can help me to take the good number because i think is a fail of typedata or something similar but i dont understand a lot in lua code. If someone solve this, this NPC can help a lot in otland because you can create your own task and mission with any problems only you need follow the history quest_id 1 later 2 ... 3 and going ahead and if you jump to other num of quest only you need an if comparing the current quest_id to the next id_quest.
Thank you!
- - - Updated - - -
SOLVED
I solve this isue with this code:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local questnum = {}
local pase = 0
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 getDBVal(query, typ, val)
local query = db.getResult(query)
if(query:getID() ~= -1) then
return ((typ == "string") and (query:getDataString(val))) or ((typ == "int") and (query:getDataInt(val)))
end
return nil
end
questnum = getDBVal("SELECT `quest_id` FROM `players` WHERE `name`=\"" .. getCreatureName(cid) .. "\";", "int", "quest_id")
if(msgcontains(msg, 'mision') and questnum == 0) then
selfSay('Quieres que te encomiende una mision ¿no? Bueno como sabras para ganarte mi respeto tendras que ir haciendo misiones poco a poco, para que pueda encargarte cada vez missiones que te traigan mas recompensas.', cid)
selfSay('Bueno ahora mismo atravesamos un momento muy amargo en la ciudad ya que las alcantarillas han sido invadidas por mounstruos. Una patrulla anda en las alcantarillas, busca al capitan y pidele que te entregue un libro. ¿Aceptas la mision?', cid)
pase = 1
elseif(msgcontains(msg, 'si') and pase == 1) then
pase = 0
db.query("UPDATE players SET `quest_id` = 1 WHERE name = \"" .. getCreatureName(cid) .. "\";")
selfSay('¡Bien! Muchas gracias por acerte cargo de esta tarea. La haria encantado pero perdi mi espada y hasta que no la encuentre no podre ayudar en las labores de defensa.')
elseif(msgcontains(msg, 'no') and pase == 1) then
pase = 0
selfSay('Si no quieres por ahora, mas tarde podras realizar mis misiones. Recuerda que te llevaras dinero honor gloria y mucha experiencia.', cid)
end
if(msgcontains(msg, 'mision') and questnum == 1) then
selfSay('Deberías ir a las alcantarillas de la ciudad y buscar al capitan el te dirá que debes hacer.', cid)
end
if(msgcontains(msg, 'mision') and questnum == 2) then
selfSay('Deberías ir a las alcantarillas de la ciudad y buscar al capitan el te dirá que debes hacer.', cid)
end
if(msgcontains(msg, 'mision') and questnum == 3) then
selfSay('¿Has traido el libro que te pedi?', cid)
pase = 2
elseif(msgcontains(msg, 'si') and pase == 2) then
if(getPlayerItemCount(cid, 1950) >= 1) then
pase = 0
db.query("UPDATE players SET `quest_id` = 4 WHERE name = \"" .. getCreatureName(cid) .. "\";")
selfSay('¡Bien! Este libro me sera de mucha utilidad.')
doPlayerAddExperience(cid, 3000)
doPlayerAddMoney(cid, 3000)
doPlayerRemoveItem(cid,1950,1)
else
pase = 0
selfSay('No tienes el libro. Vuelve a las cloacas y busca al capitan para que te lo de.', cid)
end
elseif(msgcontains(msg, 'no') and pase == 2) then
pase = 0
selfSay('Si aun no lo has encontrado no se a que esperas. Vuelve cuando lo hayas encontrado. Busca al capitan en las alcantarillas', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Solved by myself.
Last edited: