• 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!

Lua TFS 1.4.2 [10.98] Custom code request

XiolenceOT

New Member
Joined
Jun 5, 2023
Messages
42
Reaction score
4
Greetings, I would like if possible, an NPC that you can talk to to get a certain outfit, but only after you have brought back a certain item, or number of items/coins.

Like, talk to them once, set the storage and when you talk to them again they ask if you've brought what they asked for.

Pretty please, I've tried others on search but I just get mad NPChandler and index issues
 
Greetings, I would like if possible, an NPC that you can talk to to get a certain outfit, but only after you have brought back a certain item, or number of items/coins.

Like, talk to them once, set the storage and when you talk to them again they ask if you've brought what they asked for.

Pretty please, I've tried others on search but I just get mad NPChandler and index issues
No worries, this is quite doable.

Can you post what you want the npc to say?
What items / gold are required?

Basically write out how you want the npc to be, exactly.
 
No worries, this is quite doable.

Can you post what you want the npc to say?
What items / gold are required?

Basically write out how you want the npc to be, exactly.
Thanks! Just want it to require an item, and a quantity of items, and reward addons for an outfit, not the outfit itself but the first or second addons. So I can edit it and use it for others throughout my server if thats possible :)

"Greeting Traveler, looking for an adventure?"
"If you bring me X, I can give you Z, do you agree?"

and the second time talking to them they ask " Did you bring me what I asked for?"

And I can edit the rest myself as needed please
 
Thanks! Just want it to require an item, and a quantity of items, and reward addons for an outfit, not the outfit itself but the first or second addons. So I can edit it and use it for others throughout my server if thats possible :)

"Greeting Traveler, looking for an adventure?"
"If you bring me X, I can give you Z, do you agree?"

and the second time talking to them they ask " Did you bring me what I asked for?"

And I can edit the rest myself as needed please
Alright.

Try this.

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

local mission = {
    storage = 45001,
    reward = {
        female = {
            outfitLooktype = 136, -- data/XML/outfits.xml
            addon = 3 -- addon 1, addon 2, or addon 3 (both 1 & 2)
        },
        male = {
            outfitLooktype = 128, -- as currently scripted, it will reward the player
            addon = 3 -- for both the female and male outfit addons.
        }
    },
    requiredGold = 10000,
    requiredItems =
    {
        {itemId = 1111, amount = 1},
        {itemId = 2222, amount = 20}
    }
}

local function getMissionRequiredItems()
    local text = ""
    for i = 1, #mission.requiredItems do
        if text ~= "" then
            text = text .. ", "
        end
        text = text .. mission.requiredItems[i].amount .. " " .. ItemType(mission.requiredItems[i].itemId):getName()
    end
    text = mission.requiredGold .. " gold, " .. text
    return text
end

local function getOutfitName(outfitLooktype)
   
    local outfitsTable = Game.getOutfits(PLAYERSEX_FEMALE)

    for i = 1, #outfitsTable do
        local outfit = outfitsTable[i]
        if outfit.id == outfitLooktype then
            return outfit.name
        end
    end
   
    outfitsTable = Game.getOutfits(PLAYERSEX_MALE)

    for i = 1, #outfitsTable do
        local outfit = outfitsTable[i]
        if outfit.id == outfitLooktype then
            return outfit.name
        end
    end
   
    return "OUTFIT_UNKNOWN"
end

local function greetCallback(cid)
    local player = Player(cid)
    local storageValue = player:getStorageValue(mission.storage)
    if storageValue == 0 or storageValue == 1 then
        if storageValue == 0 then
            player:setStorageValue(mission.storage, 1)
        end
        npcHandler:setMessage(MESSAGE_GREET, "Have you brought me those items?")
        npcHandler.topic[cid] = 1
    else
        npcHandler:setMessage(MESSAGE_GREET, "Hey. How you doing?")
    end
    return true
end

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

    local player = Player(cid)
    local storageValue = player:getStorageValue(mission.storage)
   
    if (msgcontains(msg, "outfit") or msgcontains(msg, "quest") or msgcontains(msg, "mission")) and npcHandler.topic[cid] == 0 then
       
        if storageValue == -1 then
            npcHandler:say("You're interested in obtaining the " .. getOutfitName(mission.reward.female.outfitLooktype) .. " outfit addon, eh? Would you like to fetch me a few things to make it for ya?", cid)
            npcHandler.topic[cid] = 1
            return true
        end
        if storageValue == 0 then
            npcHandler:say("Well, what are you waiting for? Go get the items and talk to me again.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        if storageValue == 1 then
            npcHandler:say("Have you brought me those items?", cid)
            npcHandler.topic[cid] = 1
            return true
        end
       
        npcHandler:say("I don't have any other outfits to give.", cid)
        npcHandler.topic[cid] = 1
        return true
       
    elseif npcHandler.topic[cid] == 1 then
       
        if storageValue == -1 then
            if not msgcontains(msg, "yes") then
                npcHandler:say("Alright. I won't pressure you.", cid)
                npcHandler.topic[cid] = 0
                return true
            end
   
            npcHandler:say("Alright. Bring me " .. getMissionRequiredItems() .. ".", cid)
            player:setStorageValue(mission.storage, 0)
            npcHandler.topic[cid] = 0
            return true
        end
       
        if storageValue == 1 then
            if not msgcontains(msg, "yes") then
                npcHandler:say("Well, what are you waiting for? Go get the items and talk to me again.", cid)
                npcHandler.topic[cid] = 0
                return true
            end
           
            local hasAllRequiredItems = true
            for i = 1, #mission.requiredItems do
                if player:getItemCount(mission.requiredItems[i].itemId) < mission.requiredItems[i].amount then
                    hasAllRequiredItems = false
                    break
                end
            end
            if player:getMoney() < mission.requiredGold then
                hasAllRequiredItems = false
            end
           
            if not hasAllRequiredItems then
                npcHandler:say("You don't seem to have them with you. Bring me " .. getMissionRequiredItems() .. ".", cid)
                player:setStorageValue(mission.storage, 0)
                npcHandler.topic[cid] = 0
                return true           
            end
           
            for i = 1, #mission.requiredItems do
                player:removeItem(mission.requiredItems[i].itemId, mission.requiredItems[i].amount)
            end
           
            player:addOutfitAddon(mission.reward.female.outfitLooktype, mission.reward.female.addon)
            player:addOutfitAddon(mission.reward.male.outfitLooktype, mission.reward.male.addon)
            player:setStorageValue(mission.storage, 2)
            npcHandler.topic[cid] = 0
            return true
        end

    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:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Alright.

Try this.

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

local mission = {
    storage = 45001,
    reward = {
        female = {
            outfitLooktype = 136, -- data/XML/outfits.xml
            addon = 3 -- addon 1, addon 2, or addon 3 (both 1 & 2)
        },
        male = {
            outfitLooktype = 128, -- as currently scripted, it will reward the player
            addon = 3 -- for both the female and male outfit addons.
        }
    },
    requiredGold = 10000,
    requiredItems =
    {
        {itemId = 1111, amount = 1},
        {itemId = 2222, amount = 20}
    }
}

local function getMissionRequiredItems()
    local text = ""
    for i = 1, #mission.requiredItems do
        if text ~= "" then
            text = text .. ", "
        end
        text = text .. mission.requiredItems[i].amount .. " " .. ItemType(mission.requiredItems[i].itemId):getName()
    end
    text = mission.requiredGold .. " gold, " .. text
    return text
end

local function getOutfitName(outfitLooktype)
  
    local outfitsTable = Game.getOutfits(PLAYERSEX_FEMALE)

    for i = 1, #outfitsTable do
        local outfit = outfitsTable[i]
        if outfit.id == outfitLooktype then
            return outfit.name
        end
    end
  
    outfitsTable = Game.getOutfits(PLAYERSEX_MALE)

    for i = 1, #outfitsTable do
        local outfit = outfitsTable[i]
        if outfit.id == outfitLooktype then
            return outfit.name
        end
    end
  
    return "OUTFIT_UNKNOWN"
end

local function greetCallback(cid)
    local player = Player(cid)
    local storageValue = player:getStorageValue(mission.storage)
    if storageValue == 0 or storageValue == 1 then
        if storageValue == 0 then
            player:setStorageValue(mission.storage, 1)
        end
        npcHandler:setMessage(MESSAGE_GREET, "Have you brought me those items?")
        npcHandler.topic[cid] = 1
    else
        npcHandler:setMessage(MESSAGE_GREET, "Hey. How you doing?")
    end
    return true
end

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

    local player = Player(cid)
    local storageValue = player:getStorageValue(mission.storage)
  
    if (msgcontains(msg, "outfit") or msgcontains(msg, "quest") or msgcontains(msg, "mission")) and npcHandler.topic[cid] == 0 then
      
        if storageValue == -1 then
            npcHandler:say("You're interested in obtaining the " .. getOutfitName(mission.reward.female.outfitLooktype) .. " outfit addon, eh? Would you like to fetch me a few things to make it for ya?", cid)
            npcHandler.topic[cid] = 1
            return true
        end
        if storageValue == 0 then
            npcHandler:say("Well, what are you waiting for? Go get the items and talk to me again.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        if storageValue == 1 then
            npcHandler:say("Have you brought me those items?", cid)
            npcHandler.topic[cid] = 1
            return true
        end
      
        npcHandler:say("I don't have any other outfits to give.", cid)
        npcHandler.topic[cid] = 1
        return true
      
    elseif npcHandler.topic[cid] == 1 then
      
        if storageValue == -1 then
            if not msgcontains(msg, "yes") then
                npcHandler:say("Alright. I won't pressure you.", cid)
                npcHandler.topic[cid] = 0
                return true
            end
  
            npcHandler:say("Alright. Bring me " .. getMissionRequiredItems() .. ".", cid)
            player:setStorageValue(mission.storage, 0)
            npcHandler.topic[cid] = 0
            return true
        end
      
        if storageValue == 1 then
            if not msgcontains(msg, "yes") then
                npcHandler:say("Well, what are you waiting for? Go get the items and talk to me again.", cid)
                npcHandler.topic[cid] = 0
                return true
            end
          
            local hasAllRequiredItems = true
            for i = 1, #mission.requiredItems do
                if player:getItemCount(mission.requiredItems[i].itemId) < mission.requiredItems[i].amount then
                    hasAllRequiredItems = false
                    break
                end
            end
            if player:getMoney() < mission.requiredGold then
                hasAllRequiredItems = false
            end
          
            if not hasAllRequiredItems then
                npcHandler:say("You don't seem to have them with you. Bring me " .. getMissionRequiredItems() .. ".", cid)
                player:setStorageValue(mission.storage, 0)
                npcHandler.topic[cid] = 0
                return true          
            end
          
            for i = 1, #mission.requiredItems do
                player:removeItem(mission.requiredItems[i].itemId, mission.requiredItems[i].amount)
            end
          
            player:addOutfitAddon(mission.reward.female.outfitLooktype, mission.reward.female.addon)
            player:addOutfitAddon(mission.reward.male.outfitLooktype, mission.reward.male.addon)
            player:setStorageValue(mission.storage, 2)
            npcHandler.topic[cid] = 0
            return true
        end

    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:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Good thank you so much
 
Back
Top