• 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.6+] Converting NPC's (Jiddos system) into new NPC System (Evil Heros system)

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,281
Solutions
29
Reaction score
824
Location
Germany
For anyone who wants to use the new NPC system (lua based NPC's) proposed as a pr at current master branch (included in the upcoming 1.6 release)
I'll help you re write NPC's or create from scratch based on a detailed outline into the new NPC system.

There is 2 ways on how to request:

1) You post a file and I'll just 1:1 transfer it into the new system. (xml and lua file)
2) You write a very detailed version of the npc and what he should be capable of

You have to be prepared for them to be public domain, I'm not posting them in private and they will serve for other people as examples to understand how everything works.

For those who are interested into implementing this npc system into older tfs versions, here is the summarize of all commits which need to be applied:

Post automatically merged:

Let's start off with something very simple, just a Merchant in different versions
I'll try my best to make some good commentary with showing some visual branching on where we are at which stage.
Lua:
-- creates the new npc type with the name "Merchant"
local npcType = Game.createNpcType("Merchant")
-- sets the speech bubble of the npc to a trade bubble
npcType:speechBubble(SPEECHBUBBLE_TRADE)
-- sets the outfit of the npc
npcType:outfit({lookType = 128, lookHead = 114, lookBody = 114, lookLegs = 114, lookFeet = 114})
-- sets the radius on how far the npc can move away from his spawn position
npcType:spawnRadius(2)
-- sets the interval on when the npc should walk in ms
npcType:walkInterval(2000)
-- sets the movement speed on how fast the npc moves
npcType:walkSpeed(100)
-- this does all the magic in the background, initializing the npc system (onAppear/onDisappear/onSay/onTradeRequest, etc.)
npcType:defaultBehavior()
-- creates a new instance of the NpcsHandler class with the npcType
-- this holds all the tree & branch data for the npc
local handler = NpcsHandler(npcType)
-- creating the greeting keywords for the npc, handler.greetWords defaults to a table which can be found in constants.lua or can be overwritten by calling handler:setGreetWords({"word1", "word2", "word3"})
local greet = handler:keyword(handler.greetWords)
-- sets the response of the npc when the player greets him
greet:setGreetResponse("Hello |PLAYERNAME|! I have some fine {weapons} and {shields} for sale.")
--[[
    our current tree structure of the npc looks likes this
    greet
        |- nothing
       
    as we have no keywords after greeting yet
]]
-- creating the keyword "weapons" for the npc
-- this adds now a keyword onto the greet keyword
local weapons = greet:keyword("weapons")
-- sets the response of the npc when the player asks for weapons
weapons:respond("You want to see my fine weapons I offer?.")
--[[
    our current tree structure of the npc looks likes this
    greet
        |- weapons

        we placed the keyword "weapons" onto greet
]]
-- creating the keyword "yes" which will now show us the shop with teh weapons
local accept = weapons:keyword("yes")
-- sets the response of the npc when the player says "yes"
accept:respond("Here are my weapons.")
-- this will show the shop with the id 1 now, I'll show at the end of the example on how to make a shop
accept:shop(1)
--[[
    our current tree structure of the npc looks likes this
    greet
        |- weapons
            |- yes
                |- show shop with id 1

        we placed the keyword "yes" onto weapons
]]
-- creating the keyword "no" which will now lead us back to the greet keyword tree (resetting the talk state)
local decline = weapons:keyword("no")
-- sets the response of the npc when the player says "no"
decline:respond("Ok then, not.")
-- if you wanted the npc now to directly ungreet the player you could call decline:farewell() here which would be like saying "bye" to the npc
--[[
    our current tree structure of the npc looks likes this
    greet
        |- weapons
            |- yes
            |    |- show shop with id 1
            |- no
                |- reset talk state

        we placed the keyword "no" onto weapons
]]
-- creating the keyword "shields" for the npc
local shields = greet:keyword("shields")
-- sets the response of the npc when the player asks for shields
shields:respond("You want to see my fine shields I offer?.")
--[[
    our current tree structure of the npc looks likes this
    greet
        |- weapons
        |   |- yes
        |   |   |- show shop with id 1
        |   |- no
        |      |- reset talk state to greet
        |- shields

        we placed the keyword "shields" onto greet
]]
-- creating the keyword "yes" which will now show us the shop with the shields
local accept = shields:keyword("yes")
-- sets the response of the npc when the player says "yes"
accept:respond("Here are my shields.")
-- this will show the shop with the id 2 now, I'll show at the end of the example on how to make a shop
accept:shop(2)
--[[
    our current tree structure of the npc looks likes this
    greet
        |- weapons
        |   |- yes
        |   |   |- show shop with id 1 (weapons)
        |   |- no
        |       |- reset talk state to greet
        |- shields
            |- yes
                |- show shop with id 2 (shields)

        we placed the keyword "yes" onto shields
]]
-- creating the keyword "no" which will now lead us back to the greet keyword tree (resetting the talk state)
local decline = shields:keyword("no")
-- sets the response of the npc when the player says "no"
decline:respond("Ok then, not.")
-- if you wanted the npc now to directly ungreet the player you could call decline:farewell() here which would be like saying "bye" to the npc
--[[
    our current tree structure of the npc looks likes this
    greet
        |- weapons
        |   |- yes
        |   |   |- show shop with id 1
        |   |- no
        |      |- reset talk state to greet
        |- shields
            |- yes
            |   |- show shop with id 2
            |- no
                |- reset talk state to greet

        we placed the keyword "no" onto shields
]]
-- creating the shop with the id 1 for the npc (shields)
local shop1 = NpcShop(npcType, 1)
-- example of adding a single item to the shop (id/name, buyPrice, sellPrice, subType)
shop1:addItem("sword", 100, 25)
-- example of adding multiple items to the shop (id/name, buyPrice, sellPrice, subType)
local exWeapons = {
    ["axe"] = {buy = 150, sell = 50},
    ["club"] = {buy = 50, sell = 10},
    ["dagger"] = {buy = 75, sell = 20},
    ["mace"] = {buy = 200, sell = 75},
    ["spear"] = {buy = 100, sell = 30},
    ["staff"] = {buy = 250, sell = 100},
    ["sword"] = {buy = 100, sell = 25}
}
shop1:addItems(exWeapons)
-- example of adding discount to the shop for a specific type of %
-- this will reduce the buy price of all items by 10% if the player has the storagevalue 9999 set to 1 or higher
shop1:addDiscount(9999, 10)
-- creating the shop with the id 2 for the npc (shields)
local shop2 = NpcShop(npcType, 2)
-- example of adding a single item to the shop (id/name, buyPrice, sellPrice, subType)
shop2:addItem("shield", 100, 25)
-- example of adding multiple items to the shop (id/name, buyPrice, sellPrice, subType)
local exShields = {
    ["shield"] = {buy = 100, sell = 25},
    ["wooden shield"] = {buy = 50, sell = 10},
    ["brass shield"] = {buy = 150, sell = 50},
    ["plate shield"] = {buy = 200, sell = 75},
    ["steel shield"] = {buy = 250, sell = 100}
}
shop2:addItems(exShields)
-- example of adding discount to the shop for a % depending on storagevalue 9998 value
-- this will reduce the buy price of all items by x% if the player has the storagevalue 9998 set between a number of 1 and 100
shop2:addDiscount(9998)
 
Last edited:
Back
Top