VERSION .01ALPHA RELEASED SEE http://otland.net/f83/enhanced-npc-system-0-01alpha-released-143943/#post1384937
~~~~~~~~~~~~~~ o ~~~~~~~~~~~~~~ End of Edit
Hello, I'm about to release a complete library for NPC coding, I started this library because the current facilities that are included by default in TFS/Otserv did not fulfill our team needs for simplicity and ease of extension.
An example (The Oracle.lua):
(50% Less code (comments stripped) than the oracle.lua in npcs/scripts folder)
The system is based on events, like the Jiddo's system, but much less coupled, with this system will be possible (and not extremely difficult) to create npcs that follow walk routes, speak with several players in private at the same time they speak in public, maintaining individual/shared states and in general more deeply conversations/interactions. A very notorious change is that some of the things that are configurable in Jiddo's npc system, are per server, that means that, for example, you cant change say NPCHANDLER_TALKDELAY or KEYWORD_BEHAVIOR for two given npcs. Wait a bit to see this library, there's a lot of new things.
The conversation system (Talk) is very simple, is based on a stack of topics (as opposed to Jidds's system, which is based on a tree of topics), I found that with the stack approach is easier to create normal npcs and serves for most of the complexes npcs you will ever create. Either way, the system that handles the conversation is completely detached from the npc, so is 100% customizable.
I'm 99% done with the base (1.1k lines in 5 files so far), I just need to add "default" templates for npcs (shop, travel, storage id handling) and make documentation a bit more consistent.
Any suggestions or criticism are welcome.
P.S: Of course, it will be realeased to the public (Soon)
Edit:
A very early version of an editor im working on
~~~~~~~~~~~~~~ o ~~~~~~~~~~~~~~ End of Edit
Hello, I'm about to release a complete library for NPC coding, I started this library because the current facilities that are included by default in TFS/Otserv did not fulfill our team needs for simplicity and ease of extension.
An example (The Oracle.lua):
Lua:
local Oracle = AI.SocialNpc:New()
-- Lots of configuration options skipped for simplicity (hope)
-- This is just a specific table to store some data, we might use a local table aswell
-- The Npc class reserves all properties/methods in the object that start with a Upercase letter
-- you can add your own fields as long as they start with lowercase
Oracle.config = {
minLevel = 8,
cities = {
['Rhyves'] = { town = 1, pos={x=242, y=429, z=12} },
['Varak'] = { town = 2, pos={x=159, y=387, z=6} },
['Jorvik'] = { town = 3, pos={x=469, y=172, z=7} }
},
vocations = {
[1] = 'So, you wish to be a powerful magician? Are you sure about that?',
[2] = 'Are you sure that a druid is what you wish to become?',
[3] = 'A ranged marksman. Are you sure?',
[4] = 'A mighty warrior. Is that your final decision?'
},
vocIdMap = {}
}
-- Do this one time
Oracle.config.citiesList = AI.CreateOptionList(Oracle.config.cities) -- outputs: "{Rhyves}, {Varak} or {Jorvik}"
Oracle.config.vocationsList = AI.CreateOptionList(Oracle.config.vocations, function(vocid) -- outputs: "{Sorcrer}, {Knight}, {Paladin} or {Druid}"
local vocName = getVocationInfo(vocid).name
Oracle.config.vocIdMap[vocName] = vocid -- Some mapping for later use
return vocName
end)
-- This is called when user replies positive to our question (see line 85)
Oracle.dudeIsPrepared = function(talk)
-- This outputs the message is passed, extracts the keywords (all words enclosed in {}) and
-- later, if the players answers with any of these keywords, the response function
-- (see below) is called
talk:Ask('What city do you wish to live in? ' .. Oracle.config.citiesList .. '?')
-- Response to all valid cities
-- city = the city the player answered (with no case modification, so if player said
-- "ThAiS" city will be "Thais"(the orignal keyword on the talk:Ask parsed parameters list)
talk:Response(function(talk, city)
talk:Ask(city .. ', eh? So what vocation do you wish to become? ' .. Oracle.config.vocationsList .. '?')
-- Resonse functions are only called when the player replies with a valid answer
-- Theres a equivalent talk:BadResponse() function for when the player says a nonsense
talk:Response(function(talk, vocation)
talk:AskAgreement(Oracle.config.vocations[Oracle.config.vocIdMap[vocation]] .. ' This decision is irreversible!',
function() -- yes
-- Start of default oracle code
if(getPlayerVocation(talk.player) > 0) then
talk:Say('Sorry, You already have a vocation!')
else
local cityPos = Oracle.config.cities[city].pos
doPlayerSetVocation(talk.player, Oracle.config.vocIdMap[vocation])
doPlayerSetTown(talk.player, Oracle.config.cities[city].town)
local tmp = getCreaturePosition(talk.player)
doTeleportThing(talk.player, cityPos)
doSendMagicEffect(tmp, CONST_ME_POFF)
doSendMagicEffect(cityPos, CONST_ME_TELEPORT)
end
-- End of default oracle code
return talk:SilentEnd() -- Player is gone or we already said "You already have a voc.."
end,
function() -- no
talk:Say('Then what vocation do you want to become?')
talk:GoUp(1) -- Go up to vocation selection
end)
end)
end)
end
-- All replies can be either a function or a string
Oracle.GreetReply = function(talk) -- a Talk object represent a conversation with a player
if(getPlayerLevel(talk.player) < Oracle.config.minLevel) then
talk:Say('COME BACK WHEN YOU GROW UP, CHILD!')
talk:SilentEnd() -- Unfocus this player without saying anything
else
-- This output the question and waits for a positive or negative answer,
-- calling the appropriate passed function once the player replies
talk:AskAgreement('Hello |PLAYERNAME|. Are you prepared to face your destiny?',
Oracle.dudeIsPrepared, -- yes
nil) -- no, since its nil(you can leave it empty) if players dont agree, the talk ends)
end
end
-- String reply
Oracle.FarewellReply = 'Then come back when you are ready.'
-- This registers the default OnCreatureSay, OnCreatureDissapear, etc
-- to this enviroment
Oracle:Register()
The system is based on events, like the Jiddo's system, but much less coupled, with this system will be possible (and not extremely difficult) to create npcs that follow walk routes, speak with several players in private at the same time they speak in public, maintaining individual/shared states and in general more deeply conversations/interactions. A very notorious change is that some of the things that are configurable in Jiddo's npc system, are per server, that means that, for example, you cant change say NPCHANDLER_TALKDELAY or KEYWORD_BEHAVIOR for two given npcs. Wait a bit to see this library, there's a lot of new things.
The conversation system (Talk) is very simple, is based on a stack of topics (as opposed to Jidds's system, which is based on a tree of topics), I found that with the stack approach is easier to create normal npcs and serves for most of the complexes npcs you will ever create. Either way, the system that handles the conversation is completely detached from the npc, so is 100% customizable.
I'm 99% done with the base (1.1k lines in 5 files so far), I just need to add "default" templates for npcs (shop, travel, storage id handling) and make documentation a bit more consistent.
Any suggestions or criticism are welcome.
P.S: Of course, it will be realeased to the public (Soon)
Edit:
A very early version of an editor im working on
Last edited: