Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,339
- Solutions
- 68
- Reaction score
- 1,024
This will probably work for other distros as-well...
I made this so people can add side quests into there server. The script is only set up for 1 quest. So, its meant to speed up getting little side missions around your server. It can be anything as long as the quest guy is asking for an item. Only a single item as-well. I don't know if it will be useful, but here it is.
I made this so people can add side quests into there server. The script is only set up for 1 quest. So, its meant to speed up getting little side missions around your server. It can be anything as long as the quest guy is asking for an item. Only a single item as-well. I don't know if it will be useful, but here it is.
Code:
function onCreatureAppear(cid)
end
local focuses = {}
local function isFocused(cid)
for i, v in pairs(focuses) do
if(v == cid) then
return true
end
end
return false
end
local function addFocus(cid)
if(not isFocused(cid)) then
table.insert(focuses, cid)
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
table.remove(focuses, i)
break
end
end
end
local function NpcLookDirection(cid, direction) --1(west), 2(north), 3(east), 4(south) --
doCreatureSetLookDirection(cid, direction)
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v)) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end
function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
removeFocus(cid)
if(isPlayer(cid)) then --Be sure he's online
closeShopWindow(cid)
end
end
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
closeShopWindow(cid)
removeFocus(cid)
end
end
function onThink()
for i, focus in pairs(focuses) do
if(not isCreature(focus)) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
closeShopWindow(focus)
removeFocus(focus)
end
end
end
lookAtFocus()
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
closeShopWindow(cid)
removeFocus(cid)
end
end
local npc_config = {
storage = 31000, --Every new NPC add +1. After this NPC make the next value 31001 then 31002 and so on.
--Messages to start talking to NPC--
array_start_chat = {"hi", "Hi", "hello", "Hello", "hey", "Hey"}
--Message to say yes to NPC--
array_response_yes = {"yes", "Yes", "sure", "Sure", "okay", "Okay", "alright", "Alright", "yup", "Yup"} --How you can say yes or no to the NPC
--Message to say no to NPC
array_response_no = {"no", "No", "nah", "Nah", "nope", "Nope"}
--Very first message NPC will give you when you talk to him.--
first_message = "I have a {task} for you. Can you {help} me?",
--Key word to start quest--
array_first_response = {"task, help", "Task", "Help"}
--What he needs for the quest--
quest_message_first = "Great, {Can you go pick me some berries off bushes}? I need {100 of them} for my potions.",
quest_item_needed = 1111 -- item id of quest item needed
quest_item_amount = 100 --how many are needed
--If the player says yes to doing the quest
quest_response_yes = "Thank you, I will have a reward for you when you return.",
--If the player says no to doing the quest
quest_response_no = "I knew you looked useless.",
--When the player returns again.--
message_after_quest_start = "Ahh, good to see you again. {Did you get those berries?}",
--If the player says yes and HAS quest item needed.--
message_turn_in_quest_yes = "Thank you very much!, here is your reward.",
first_quest_reward = 1111, --itemid for reward.
first_quest_amount = 1, --how many of that item.
first_quest_exp = 0, -- how much exp the first quest turn in will give
--If you want a magic effect to go on the player when he turns in quest
use_magicEffect = true
--Magic effect to send on player
first_quest_magicEffect = 10 --Magic effect to show on player
--If the player says yes and DOESN'T have the quest item.--
message_first_turn_in_quest_false = "I need {100 berries}, you do not have that many. Please go get them.",
--If the player says no
message_turn_in_quest_no = "Aff, please get {100 berries} for me! I need to make these potions.",
--after player has completed quest--
message_normal_greet = "Good to see you friend. I do not have any tasks left for you.",
--Messages to say bye to NPC
array_bye_message = {"bye", "Bye", "cya", "Cya", "goodbye", "Goodbye"}
--When player says bye to NPC--
array_bye_message_npc = {[1] = "Fair-well.",[2] = "Goodbye.",[3] = "See you next time."}
--However many messages you put for array_bye_message put here. So ^ there is 3 so it is 3
amount_bye_message_npc = 3
}
function onCreatureSay(cid, type, msg)
if((isInArray(npc_config.array_start_chat, msg)) and not (isFocused(cid)) and getPlayerStorageValue(cid, npc_config.storage) < 2) then
selfSay(npc_config.first_message, cid)
addFocus(cid)
elseif((isFocused(cid)) and (isInArray(npc_config.array_first_response, msg)) and getPlayerStorageValue(cid, npc_config.storage) < 1) then
selfSay(npc_config.quest_message_first, cid)
setPlayerStorageValue(cid, npc_config.storage, 1)
elseif((isFocused(cid)) and (isInArray(npc_config.array_response_yes, msg)) and getPlayerStorageValue(cid, npc_config.storage) == 1) then
selfSay(npc_config.quest_response_yes, cid)
setPlayerStorageValue(cid, npc_config.storage, 2)
elseif((isFocused(cid)) and (isInArray(npc_config.array_response_no, msg)) and getPlayerStorageValue(cid, npc_config.storage) == 1) then
selfSay(npc_config.message_response_no, cid)
setPlayerStorageValue(cid, npc_config.storage, 1)
elseif((isFocused(cid)) and (msg == "hi") and getPlayerStorageValue(cid, npc_config.storage) == 2) then
selfSay(npc_config.message_after_quest_yes, cid)
elseif((isFocused(cid)) and (isInArray(npc_config.array_response_yes, msg)) and getPlayerStorageValue(cid, npc_config.storage) == 2) then
if doPlayerRemoveItem(cid, npc_config.quest_item_needed, npc_config.quest_item_amount) then
selfSay(npc_config.message_turn_in_quest_yes, cid)
doPlayerAddItem(cid, npc_config.first_quest_reward, npc_config.first_quest_amount)
doPlayerAddExperiance(cid, npc_config.first_quest_exp)
setPlayerStorageValue(cid, npc_config.storage, 3)
if npc_config.use_magicEffect == true then
doSendMagicEffect(getPlayerPosition(cid), npc_config.first_quest_magicEffect)
end
else
selfSay(npc_config.message_first_turn_in_quest_false, cid)
end
elseif((isFocused(cid)) and (isInArray(npc_config.array_response_no, msg)) and getPlayerStorageValue(cid, npc_config.storage) == 2) then
selfSay(npc_config.message_turn_in_quest_no, cid)
--After all quests complete
elseif((isFocused(cid)) and (isInArray(npc_config.array_start_chat, msg)) and getPlayerStorageValue(cid, npc_config.storage) >= 3) then
selfSay(npc_config.message_normal_greet, cid)
elseif((isFocused(cid)) and (isInArray(npc_config.array_bye_message))) then
local rand_bye = math.random(1, npc_config.amount_bye_message)
selfSay(npc_config.array_bye_message_npc[rand_bye], cid)
removeFocus(cid)
end
end
Last edited: