• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[TFS 1.1] NPC sells same item with diffrent action ID

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,393
Solutions
7
Reaction score
552
Hey otland,

I've been working on a NPC that can sell reciepes for colors crafting system. This is what i've come up with so far.


Code:
    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 shopWindow = {}
    local keys = {
         {id = 2217, buy = 5, name = "BlackSmithing", actionid = 50501},
         {id = 2217, buy = 20, name = "Alchemy", actionid = 50502},
         {id = 2217, buy = 50, name = "Inscription", actionid = 50503},
         {id = 2217, buy = 50, name = "Tailoring", actionid = 50504},
         {id = 2217, buy = 50, name = "Enchanting", actionid = 50505},
         {id = 2217, buy = 50, name = "Taming", actionid = 50506},
         {id = 1967, buy = 50, name = "reciepe", text = "101", actionid = 50501},
    }

    local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
         if doPlayerRemoveMoney(cid, shopWindow[item].Price) then
             local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)                   
             doSetItemText(thing, shopWindow[item].Text)
             doSetItemActionId(thing, shopWindow[item].Actionid)
             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
         else
             selfSay("You don't have enough money.", cid)
         end
         return true
    end


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

         if msgcontains(msg, 'trade') then
             for var, item in pairs(keys) do
                 shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid, Text = item.text}
             end
             openShopWindow(cid, keys, onBuy, onSell)
         end
         return true
    end

    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())

This script does indeed sell the item with the Action ID however, being that the item is the same it just assigns the same action id to all the items.

Example: If i buy the tailoring item the action ID will still be 50501.

Is this even possible?

Regards
beastn
 
This post might be useless... But I don't think there's a way to achieve what you want with the actual npc system. Seems like my crafting system needs some rework on the recipes part :(
 
Dang.. i thought so..Can i make it so this monster will 100% always drop that recipe? that way i'll need to make like 6 bosses per set but it will work lol
 
Did a really dodgey work around for now.. i made a room full of doors with chests behind them... then the npc grants them permission with a storage. lawl does the job for now
 
The thing is, it doesn't matter what change I make to the recipes, the npc system is not able to check item attributes.
NPCs can still sell the recipes/books using the old way (hi, buy x recipe, yes) or changing the system to make every recipe have their unique itemid...
 
What if we changed the system to storage's? so you just learn the reciepes like spells? (No need for the scroll)? i havnt looked at how the recipes are learnt but i'm sure it wouldn't be too hard to make it like that?
 
I think that will be the same, since the items are working with storages too.
Code:
player:setStorageValue(craftingProfessionsConfig.baseRecipeStorage + recipes[found].storage, 1)

What's your idea? Maybe we could improve the system or something.
 
My idea was to just get rid of the action id. So you dont loot scrolls or books are anything you learn the skills from a npc. So you have 1 npc called 'Crafting Master' and he gives you your skills black smithing etc etc where all he will need to do is add the storage value to you. then you have a diffrent NPC for every skill so blacksmithing etc etc where it will just set the storage value for that player. dunno if this makes sense or is even remotly right... I havnt really looked into how your script works yet haha
 
Yeah you can do that easily, but you don't need to get rid of the actual item for that... Just use the code that I gave you in the last post as reference :p
 
Yeah you can do that easily, but you don't need to get rid of the actual item for that... Just use the code that I gave you in the last post as reference :p

yeah yeah i know but i want to get rid of the item i dont think its needed tbh lol only good thing with having the item is that you can loot it.. Was also thinking maybe you could make it grant more items depending on your blacksmithing etc level..
 
Back
Top