• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ TFS 1.5 8.6 NPC with missions

granitowyx

New Member
Joined
Jan 27, 2022
Messages
23
Reaction score
0
GitHub
rupafin123
Hello. I need NPC script. Npc give mission to player and when player make all missions get possibility to travel to island.
For example
1 mission: bring to npc 200 small emerald
2 mission: kill 200 dragons
3 mission: touch statue in city
4 mission: bring 5 dragon scale mail
5 mission: kill 1 morgaroth
And after all misions player can travel with this npc to island for 100 cc.
Can somebody help me?
 
bump
I made all mission without 3 mission. I want that player must touch 3 statues, when he touch the statue get message that he touch statue and after touch 3 statues he can back to npc for reward
 
Mission 3, untested
Lua:
local config = {
    actionId = 45000, -- place on each statue
    missionStorage = 45000, -- storage of this mission
    missionStorageValueStart = 1, -- value given to start mission by npc
    missionStorageValueEnd = 2, -- value to check at npc for completed mission (which you then update to 3, to fully complete the mission)
    statues = {
        {45001, Position(1111, 1111, 7)}, -- {storage, positionOfStatue}
        {45002, Position(2222, 2222, 7)},
        {45003, Position(3333, 3333, 7)}
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- check if mission is in progress
    if player:getStorageValue(config.missionStorage) ~= config.missionStorageValueStart then
        -- give player some feedback if mission is completed.
        if player:getStorageValue(config.missionStorage) == config.missionStorageValueEnd then
            player:sendCancelMessage("You have fondled all the statues. Return to the npc.")
        end
        return true
    end
    
    -- find which statue was used
    local index = 0
    for i = 1, #config.statues do
        if config.statues[i][2] == toPosition then
            index = config.statues[i]
            break
        end
    end
    if index == 0 then
        print("Error: Statue position is incorrect.")
        player:sendCancelMessage("Contact Gamemaster. Error code: granitowyx_0001")
        return true
    end
    
    -- check is statue has been touched previously
    if player:getStorageValue(index[1]) ~= -1 then
        player:sendCancelMessage("You have already fondled this statue.")
        return true
    end
    
    -- give player storage for touching statue
    player:say("You have fondled this statue successfully!", TALKTYPE_MONSTER_SAY)
    player:setStorageValue(index[1], 1)
    
    -- check if all 3 statues have been touched. if they have all been touched, give progression to mission
    local finished = true
    for i = 1, #config.statues do
        if player:getStorageValue(config.statues[i][1]) == -1 then
            finished = false
            break
        end
    end
    if finished then
        player:setStorageValue(config.missionStorage, config.missionStorageValueEnd)
    end
    return true
end

action:aid(config.actionId)
action:register()
 
I give up. Can sb make this whole script?
1 mission: bring to npc 200 small emerald
2 mission: kill 200 dragons
3 mission: touch statue in city
4 mission: bring 5 dragon scale mail
5 mission: kill 1 morgaroth
And after all misions player can travel with this npc to island for 100 cc.
 
Guys how to make this 3 mission: touch statues in city
????

Am I invisible?
 
Mission 3, untested
Lua:
local config = {
    actionId = 45000, -- place on each statue
    missionStorage = 45000, -- storage of this mission
    missionStorageValueStart = 1, -- value given to start mission by npc
    missionStorageValueEnd = 2, -- value to check at npc for completed mission (which you then update to 3, to fully complete the mission)
    statues = {
        {45001, Position(1111, 1111, 7)}, -- {storage, positionOfStatue}
        {45002, Position(2222, 2222, 7)},
        {45003, Position(3333, 3333, 7)}
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- check if mission is in progress
    if player:getStorageValue(config.missionStorage) ~= config.missionStorageValueStart then
        -- give player some feedback if mission is completed.
        if player:getStorageValue(config.missionStorage) == config.missionStorageValueEnd then
            player:sendCancelMessage("You have fondled all the statues. Return to the npc.")
        end
        return true
    end

    -- find which statue was used
    local index = 0
    for i = 1, #config.statues do
        if config.statues[i][2] == toPosition then
            index = config.statues[i]
            break
        end
    end
    if index == 0 then
        print("Error: Statue position is incorrect.")
        player:sendCancelMessage("Contact Gamemaster. Error code: granitowyx_0001")
        return true
    end
 
    -- check is statue has been touched previously
    if player:getStorageValue(index[1]) ~= -1 then
        player:sendCancelMessage("You have already fondled this statue.")
        return true
    end
 
    -- give player storage for touching statue
    player:say("You have fondled this statue successfully!", TALKTYPE_MONSTER_SAY)
    player:setStorageValue(index[1], 1)
 
    -- check if all 3 statues have been touched. if they have all been touched, give progression to mission
    local finished = true
    for i = 1, #config.statues do
        if player:getStorageValue(config.statues[1]) == -1 then
            finished = false
            break
        end
    end
    if finished then
        player:setStorageValue(config.missionStorage, config.missionStorageValueEnd)
    end
    return true
end

action:aid(config.actionId)
action:register()
I changed position of statues and added this script to data/scripts made 3 satues on map with action id 45000. Npc give missionStorageValueStart because I checked it in database but nothing happens when i touch statue no errors.
 

Alright, I went and tested it myself..

View attachment bandicam 2022-02-28 11-44-21-336.mp4

Here's the scripts I tested with.

data/scripts/actions_npcTest.lua
Lua:
local config = {
    actionId = 45000, -- place on each statue
    missionStorage = 45000, -- storage of this mission
    missionStorageValueStart = 1, -- value given to start mission by npc
    missionStorageValueEnd = 2, -- value to check at npc for completed mission (which you then update to 3, to fully complete the mission)
    statues = {
        {45001, Position(245, 246, 7)}, -- {storage, positionOfStatue}
        {45002, Position(247, 246, 7)},
        {45003, Position(249, 246, 7)}
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- check if mission is in progress
    if player:getStorageValue(config.missionStorage) ~= config.missionStorageValueStart then
        -- give player some feedback if mission is completed.
        if player:getStorageValue(config.missionStorage) == config.missionStorageValueEnd then
            player:sendCancelMessage("You have fondled all the statues. Return to the npc.")
        end
        return true
    end
 
    -- find which statue was used
    local index = 0
    for i = 1, #config.statues do
        if config.statues[i][2] == toPosition then
            index = config.statues[i]
            break
        end
    end
    if index == 0 then
        print("Error: Statue position is incorrect.")
        player:sendCancelMessage("Contact Gamemaster. Error code: granitowyx_0001")
        return true
    end
 
    -- check is statue has been touched previously
    if player:getStorageValue(index[1]) ~= -1 then
        player:sendCancelMessage("You have already fondled this statue.")
        return true
    end
 
    -- give player storage for touching statue
    player:say("You have fondled this statue successfully!", TALKTYPE_MONSTER_SAY)
    player:setStorageValue(index[1], 1)
 
    -- check if all 3 statues have been touched. if they have all been touched, give progression to mission
    local finished = true
    for i = 1, #config.statues do
        if player:getStorageValue(config.statues[i][1]) == -1 then
            finished = false
            break
        end
    end
    if finished then
        player:setStorageValue(config.missionStorage, config.missionStorageValueEnd)
    end
    return true
end

action:aid(config.actionId)
action:register()
data/npc/Mission Giver.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Mission Giver" script="mission3.lua" walkinterval="1000" access="3" floorchange="0">
    <health now="100" max="100"/>
    <look type="130" head="77" body="63" legs="58" feet="115" addons="0"/>
</npc>
data/npc/scripts/mission3.lua
Lua:
local config = {
    actionId = 45000, -- place on each statue
    missionStorage = 45000, -- storage of this mission
    missionStorageValueStart = 1, -- value given to start mission by npc
    missionStorageValueEnd = 2, -- value to check at npc for completed mission (which you then update to 3, to fully complete the mission)
    statues = {
        {45001, Position(245, 246, 7)}, -- {storage, positionOfStatue}
        {45002, Position(247, 246, 7)},
        {45003, Position(249, 246, 7)}
    }
}

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

local function greetCallback(cid)
    npcHandler.topic[cid] = 0
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
 
    local player = Player(cid)

    if msgcontains(msg, "mission") then
        local storageValue = player:getStorageValue(config.missionStorage)
        if storageValue < config.missionStorageValueStart then
            npcHandler:say("Would you like to do mission 3?", cid)
            npcHandler.topic[cid] = 1
        elseif storageValue == config.missionStorageValueStart then
            npcHandler:say("You haven't touched all of the statues yet.", cid)
            npcHandler.topic[cid] = 0
        elseif storageValue == config.missionStorageValueEnd then
            npcHandler:say("Great work! Thanks for fondling all those statues.", cid)
            player:setStorageValue(config.missionStorage, config.missionStorageValueEnd + 1)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("I have no more missions for you.", cid)
            npcHandler.topic[cid] = 0
        end
        return true
     
    elseif npcHandler.topic[cid] == 1 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("Another time then.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        npcHandler:say("Great. Go touch 3 statues.", cid)
        player:setStorageValue(config.missionStorage, config.missionStorageValueStart)
        npcHandler.topic[cid] = 0
        return true
     
    end
    return true
end

local function onAddFocus(cid)
    npcHandler.topic[cid] = 0
end

local function onReleaseFocus(cid)
    npcHandler.topic[cid] = 0
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

--npcHandler:setMessage(MESSAGE_GREET, "Welcome. Are you looking to get a {promotion}?")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Alright, I went and tested it myself..

View attachment 65921

Here's the scripts I tested with.

data/scripts/actions_npcTest.lua
Lua:
local config = {
    actionId = 45000, -- place on each statue
    missionStorage = 45000, -- storage of this mission
    missionStorageValueStart = 1, -- value given to start mission by npc
    missionStorageValueEnd = 2, -- value to check at npc for completed mission (which you then update to 3, to fully complete the mission)
    statues = {
        {45001, Position(245, 246, 7)}, -- {storage, positionOfStatue}
        {45002, Position(247, 246, 7)},
        {45003, Position(249, 246, 7)}
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- check if mission is in progress
    if player:getStorageValue(config.missionStorage) ~= config.missionStorageValueStart then
        -- give player some feedback if mission is completed.
        if player:getStorageValue(config.missionStorage) == config.missionStorageValueEnd then
            player:sendCancelMessage("You have fondled all the statues. Return to the npc.")
        end
        return true
    end
 
    -- find which statue was used
    local index = 0
    for i = 1, #config.statues do
        if config.statues[i][2] == toPosition then
            index = config.statues[i]
            break
        end
    end
    if index == 0 then
        print("Error: Statue position is incorrect.")
        player:sendCancelMessage("Contact Gamemaster. Error code: granitowyx_0001")
        return true
    end
 
    -- check is statue has been touched previously
    if player:getStorageValue(index[1]) ~= -1 then
        player:sendCancelMessage("You have already fondled this statue.")
        return true
    end
 
    -- give player storage for touching statue
    player:say("You have fondled this statue successfully!", TALKTYPE_MONSTER_SAY)
    player:setStorageValue(index[1], 1)
 
    -- check if all 3 statues have been touched. if they have all been touched, give progression to mission
    local finished = true
    for i = 1, #config.statues do
        if player:getStorageValue(config.statues[i][1]) == -1 then
            finished = false
            break
        end
    end
    if finished then
        player:setStorageValue(config.missionStorage, config.missionStorageValueEnd)
    end
    return true
end

action:aid(config.actionId)
action:register()
data/npc/Mission Giver.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Mission Giver" script="mission3.lua" walkinterval="1000" access="3" floorchange="0">
    <health now="100" max="100"/>
    <look type="130" head="77" body="63" legs="58" feet="115" addons="0"/>
</npc>
data/npc/scripts/mission3.lua
Lua:
local config = {
    actionId = 45000, -- place on each statue
    missionStorage = 45000, -- storage of this mission
    missionStorageValueStart = 1, -- value given to start mission by npc
    missionStorageValueEnd = 2, -- value to check at npc for completed mission (which you then update to 3, to fully complete the mission)
    statues = {
        {45001, Position(245, 246, 7)}, -- {storage, positionOfStatue}
        {45002, Position(247, 246, 7)},
        {45003, Position(249, 246, 7)}
    }
}

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

local function greetCallback(cid)
    npcHandler.topic[cid] = 0
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
 
    local player = Player(cid)

    if msgcontains(msg, "mission") then
        local storageValue = player:getStorageValue(config.missionStorage)
        if storageValue < config.missionStorageValueStart then
            npcHandler:say("Would you like to do mission 3?", cid)
            npcHandler.topic[cid] = 1
        elseif storageValue == config.missionStorageValueStart then
            npcHandler:say("You haven't touched all of the statues yet.", cid)
            npcHandler.topic[cid] = 0
        elseif storageValue == config.missionStorageValueEnd then
            npcHandler:say("Great work! Thanks for fondling all those statues.", cid)
            player:setStorageValue(config.missionStorage, config.missionStorageValueEnd + 1)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("I have no more missions for you.", cid)
            npcHandler.topic[cid] = 0
        end
        return true
    
    elseif npcHandler.topic[cid] == 1 then
        if not msgcontains(msg, "yes") then
            npcHandler:say("Another time then.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        npcHandler:say("Great. Go touch 3 statues.", cid)
        player:setStorageValue(config.missionStorage, config.missionStorageValueStart)
        npcHandler.topic[cid] = 0
        return true
    
    end
    return true
end

local function onAddFocus(cid)
    npcHandler.topic[cid] = 0
end

local function onReleaseFocus(cid)
    npcHandler.topic[cid] = 0
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

--npcHandler:setMessage(MESSAGE_GREET, "Welcome. Are you looking to get a {promotion}?")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Nice, gonna use that too, thank you!
 
guys how to connect mission scripts like player says first time to NPC (hi > mission) then make first mission and give it back and after it player says mission and he gets mission 2 from NPC etc.. The player must complete the missions sequentially. Can somebody make script with mission1 (bring 200 small emerald) and mission3 which is done by Xikini.
 
You have a pretty good base there, so instead of bumping the thread every day, why dont you try to make it youself? You would have already done it and dont say "I do not how to script sorry", it has been more than 1 month
 
Back
Top