Hello,
I would like to implement a reputation system to the script bellow. Everytime the player complete a task, he would get a amount of reputation (the amount will vary according to the task). The reputation will allow the player to enter specific places. When the player have 500 reputation he is "supplier", then he can enter in a specific place. When player have 1000 reputation he is "master" and he can enter into another specific place.
Also I would like to be able to repeat tasks.
I will be glad if someone can help me with it.
I would like to implement a reputation system to the script bellow. Everytime the player complete a task, he would get a amount of reputation (the amount will vary according to the task). The reputation will allow the player to enter specific places. When the player have 500 reputation he is "supplier", then he can enter in a specific place. When player have 1000 reputation he is "master" and he can enter into another specific place.
Also I would like to be able to repeat tasks.
npc/script/tasknpc
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
npcHandler:addModule(FocusModule:new())
local npcMissions = {
[1] = {name = "Iron Maul", -- Collect Items only
arrayName = {"Iron Maul", "iron Maul", "Iron maul", "iron maul"},
storageMission = 43003,
storageRequired = nil,
messageTaskInfo = "I need you to bring me 1 Iron Maul.",
messageTaskComplete = "Thank you, our troops have a fair chance now.",
collectItems = { -- Collect Items task
[1] = {itemid = 26580, amount = 1}
},
--Rewards--
exp = 500,
rewardItems = {
[1] = {itemid = 2148, amount = 100}
},
setStorage = nil
},
[2] = {name = "Ornate Sword", -- Collect Items only
arrayName = {"Ornate Sword", "ornate Sword", "Ornate sword", "ornate sword"},
storageMission = 43004,
storageRequired = nil,
messageTaskInfo = "I need you to bring me 1 Ornate Sword.",
messageTaskComplete = "Thank you, our troops have a fair chance now.",
collectItems = { -- Collect Items task
[1] = {itemid = 27452, amount = 1}
},
--Rewards--
exp = 500,
rewardItems = {
[1] = {itemid = 2148, amount = 100}
},
setStorage = nil
},
[3] = {name = "Stone Axe", -- Collect Items only
arrayName = {"Stone Axe", "stone Axe", "Stone axe", "stone axe"},
storageMission = 43005,
storageRequired = nil,
messageTaskInfo = "I need you to bring me 1 Stone Axe.",
messageTaskComplete = "Thank you, our troops have a fair chance now.",
collectItems = { -- Collect Items task
[1] = {itemid = 26580, amount = 1}
},
--Rewards--
exp = 500,
rewardItems = {
[1] = {itemid = 2148, amount = 100}
},
setStorage = nil
},
}
local npcStory = { -- This story is told when the player first talks to the npc.
"Not now adventurer. I have to find a way to supply the troops.",
"The local blacksmith disappeared and the city's army needs weapons and equipment.",
"I don't know what to do. We can't lose the battle, if you meet someone that can craft, please send our way!",
"Please god send us some {help}!"
}
local MESSAGES_GREET = { -- Messages are based on the npcStorage for the player. This table handles all greeting interaction between the npc and player.
--Storage / message
-- The player gets his storage for the npc set as soon as he talks to the npc
-- Everytime a player accepts and completes one of the tasks/missions his npcStorage is increased by 1. That is how the code keeps track of how the npc should respond to the player.
[1] = "Hello again |PLAYERNAME|. Do you want to {help} me?",
[2] = "I am glad you decided to help, our troops have a chance now, but they still need more equipment and weapons.",
[3] = "Thanks for killing those rats. I have another {task} I need {help} with.",
[4] = "The trolls are powerful. Be sure to take strong gear with you.",
[5] = "Thank you for all your help."
}
local MESSAGES_GOODBYE = { -- This works the same as MESSAGES_GREET. Depending on how many tasks the player has done for the npc. The npc will say different things when he says goodbye to the player.
[1] = "Thanks for nothing |PLAYERNAME|.",
[2] = "Thank you for your help. Goodbye.",
[3] = "You have helped so much. I will be sure to tell other of you."
}
local arrayGreetings = {"hi", "Hi", "hello", "Hello", "hey", "Hey"}
local arrayFarewell = {"bye", "Bye", "goodbye", "Goodbye", "good-bye", "Good-Bye", "Good-bye"}
local messageHearStoryAgain = "story"
local messageCheckTasks = {"help", "Help", "task", "Task", "tasks", "Tasks"}
local messageShowTasks = "Here is what I need help with:"
local messageCompletedAllTasks = "Thank you for all you have done. I dont need anymore help."
local npcStorage = 45000
function onCreatureSay(cid, type, msg)
local player = Player(cid)
local playerGreetMessage = MESSAGES_GREET[player:getStorageValue(npcStorage)]
local playerGoodbyeMessage = MESSAGES_GOODBYE[player:getStorageValue(npcStorage)]
if isInArray(arrayGreetings, msg) and not npcHandler:isFocused(cid) and player:getStorageValue(npcStorage) == -1 then
npcHandler:addFocus(cid)
npcHandler:say(npcStory, cid, false, true, 4000)
player:setStorageValue(npcStorage, 1)
elseif isInArray(arrayGreetings, msg) and not npcHandler:isFocused(cid) then
npcHandler:addFocus(cid)
if string.find(playerGreetMessage, "|PLAYERNAME|") then
local newMsg = string.gsub(playerGreetMessage, "|PLAYERNAME|", player:getName())
selfSay(newMsg, cid)
else
selfSay(playerGreetMessage, cid)
end
elseif isInArray(arrayFarewell, msg) and npcHandler:isFocused(cid) then
if string.find(playerGoodbyeMessage, "|PLAYERNAME|") then
local newMsg = string.gsub(playerGoodbyeMessage, "|PLAYERNAME|", player:getName())
selfSay(newMsg, cid)
else
selfSay(playerGoodbyeMessage, cid)
end
npcHandler:releaseFocus(cid)
elseif isInArray(messageCheckTasks, msg) and npcHandler:isFocused(cid) then
local text = messageShowTasks
local tmpTable = {}
for i = 1, #npcMissions do
if player:getStorageValue(npcMissions[i].storageMission) < 2 then
if npcMissions[i].storageRequired then
local showTask = true
for x = 1, #npcMissions[i].storageRequired do
if player:getStorageValue(npcMissions[i].storageRequired[x]) ~= 2 then
showTask = false
break
end
end
if showTask then
tmpTable[#tmpTable + 1] = npcMissions[i].name
end
else
tmpTable[#tmpTable + 1] = npcMissions[i].name
end
end
end
if #tmpTable > 0 then
for i = 1, #tmpTable do
if i == #tmpTable then
text = text.." {"..tmpTable[i].."}"
else
text = text.." {"..tmpTable[i].."},"
end
end
selfSay(text, cid)
else
selfSay(messageCompletedAllTasks, cid)
end
elseif msg and npcHandler:isFocused(cid) then
local MISSION = nil
for i = 1, #npcMissions do
if isInArray(npcMissions[i].arrayName, msg) then
MISSION = npcMissions[i]
break
end
end
if MISSION == nil then
return false
end
if player:getStorageValue(MISSION.storageMission) == 2 then
selfSay("You have already completed {"..MISSION.name.."}.", cid)
return false
end
local canDoTask = true
if MISSION.storageRequired then
for i = 1, #MISSION.storageRequired do
if player:getStorageValue(MISSION.storageRequired) ~= 2 then
canDoTask = false
break
end
end
end
if not canDoTask then
selfSay("You are not ready for {"..MISSION.name.."}.", cid)
return false
end
if player:getStorageValue(MISSION.storageMission) == 1 then
local isTaskDone = true
if MISSION.monsters then
for i = 1, #MISSION.monsters do
if player:getStorageValue(MISSION.monsters[i].storage) ~= MISSION.monsters[i].amount then
isTaskDone = false
break
end
end
end
if MISSION.collectItems then
for i = 1, #MISSION.collectItems do
if player:getItemCount(MISSION.collectItems[i].itemid) < MISSION.collectItems[i].amount then
isTaskDone = false
break
end
end
end
if isTaskDone then
if MISSION.monsters then
for i = 1, #MISSION.monsters do
player:setStorageValue(MISSION.monsters[i].storage, -1)
end
end
if MISSION.collectItems then
for i = 1, #MISSION.collectItems do
player:removeItem(MISSION.collectItems[i].itemid, MISSION.collectItems[i].amount)
end
end
if MISSION.exp then
player:addExperience(MISSION.exp)
end
if MISSION.rewardItems then
for i = 1, #MISSION.rewardItems do
player:addItem(MISSION.rewardItems[i].itemid, MISSION.rewardItems[i].amount, true)
end
end
selfSay(MISSION.messageTaskComplete, cid)
player:setStorageValue(npcStorage, player:getStorageValue(npcStorage) + 1)
player:setStorageValue(MISSION.storageMission, 2)
return false
end
local text = "["..MISSION.name.."]: "
if MISSION.monsters then
for i = 1, #MISSION.monsters do
if i == #MISSION.monsters then
text = text.."("..player:getStorageValue(MISSION.monsters[i].storage).."/"..MISSION.monsters[i].amount..") "..MISSION.monsters[i].name.." "
else
text = text.."("..player:getStorageValue(MISSION.monsters[i].storage).."/"..MISSION.monsters[i].amount..") "..MISSION.monsters[i].name..", "
end
end
end
if MISSION.collectItems then
for i = 1, #MISSION.collectItems do
if i == #MISSION.collectItems then
text = text.."("..player:getItemCount(MISSION.collectItems[i].itemid).."/"..MISSION.collectItems[i].amount..") "..ItemType(MISSION.collectItems[i].itemid):getName().." "
else
text = text.."("..player:getItemCount(MISSION.collectItems[i].itemid).."/"..MISSION.collectItems[i].amount..") "..ItemType(MISSION.collectItems[i].itemid):getName()..", "
end
end
end
selfSay(text, cid)
return false
end
selfSay(MISSION.messageTaskInfo, cid)
player:setStorageValue(MISSION.storageMission, 1)
player:setStorageValue(npcStorage, player:getStorageValue(npcStorage) + 1)
if MISSION.monsters then
for i = 1, #MISSION.monsters do
player:setStorageValue(MISSION.monsters[i].storage, 0)
end
end
end
return true
end
I will be glad if someone can help me with it.