Jump to content
  • 0

[HELP] Implementing NPC Relations


Question

Posted

Hello everybody, nice to see all the useless help posts and some fimilar names.

 

Something that I've been working on is creating your own 'Instance' of the world independent of what other players do. To create a bit more of a dynamic role playing situation for players I've been wanting to implement relationships between NPC's. I'm currently using standard interlude L2j from the nightlies folder (r1434) incase you're wondering, though I'm wondering more about the concept of it rather than the practice.

 

The idea to paint an example of what I mean:

 

There is Tom and there is Joe. Tom is a trader. Tom receives his supplies from Joe and resells them. Joe is a traveling NPC which travels from location A to B. Joe dies, either by the hands of the player or a hostile NPC. Because Tom no longer has a supplier he cannot sell supplies anymore to the player.

 

Obviously it won't be so specific every time and it was just to illustrate what I mean but I want to implement something generic enough that I can define an entry point interface ( like checkRelation or something ) and from there script it myself in specific classes. However I'm running into trouble with a good implementation with the current system of npc's and spawning.

 

1) My original idea was to have the NPC's have a Map with the NPC id as the key and the value being some kind of relation interface (classes implement this with a doCheck as stated above, or something when the player interacts with the NPC). However NPC's can have multiple spawns, which means this is unreliable (or it can be managed if I'm the one managing the custom npcs)

 

2) The second idea is to use the spawn id's of npcs, however this wouldn't be known at compile time. To manage this I'd have to completely overwrite the current spawn system to make something to keep track of it then, which would then have to spawn things inside of a relation 'group'.

 

Anybody maybe have some kind of idea about how to go about this?

 

 

 

6 answers to this question

Recommended Posts

  • 0
Posted

It's interesting, but I'm not even sure you can rely on npc objectId after server shutdown. As CtrlIntention, you can make a Enum with all possible actions, and code any action.

 

About individual behavior (such as your Tom/Joe), I clearly doubt you can do something global. Each A type enters in a "case" you have to code. It could be patrolling an area, you have to give an area manually, or based on actual region.

 

How will you manage to say Tom and Joe are related, for exemple ? I see mostly a "clan" system. How will you manage to make them walk ? I see a pathnode system.

 

You could also do as L2J currently make, aka coding any single behavior. It is very long.

 

Anyway, even on The Sims, you haven't such relation, and it's a game based only about relations between NPCs.

 

You should better take a look on AI systems from others games.

  • 0
Posted

i got a bit lost:

"Instances": check how postIl did it, but it must be just controling knownList or smth like that

 

Relations between Npc's you can create a manager that save the info (Joe alive?) onCreate() turn it true, onDie() false [no idea if Npcs have onCreate(), they must, because some make an animation or a skill, i dont know] that manager may be static so you can access it easy.

 

AIs, there are some usefull information about this, i have read long time ago something about birds/fish simulations that are based on 3 keys:

- they follow a leader

- they have a formation

- they do random moves inside that formation

or something like that

 

Edit: http://www.red3d.com/cwr/boids/

  • 0
Posted

If u would like to make relation between single npcs(each npc spawn have got different relations) and u want those relations to be saved after restart. Npc = spawn, if spawns would be indexed it would be very easy, except that there is no option i think :/

Now, when something happends = relation is changed, it would have to be saved somewhere, best option is new Sql table with spawn relations. When relation has been removed(for example when 1 npc died) it can be just removed from database very fast.

 

Now about relations, u will need to create enum of them. I dont know what relations u want to do but i think that u will need to make each class for each relation so it will be easiest way. Seems like something not really hard to do :)

  • 0
Posted

Well I'm going to start with something simple to begin with. I have an enumation object with 2 statuses. Either the NPC's are going to like each other or they're going to hate each other (two poles to start simple). Let's just say they're both merchants. If you deal with Merchant A, Merchant B is going to hate you, and vice versa: If you deal with B, A is going to hate you. For now deal 2 is going to the player additional as I will have to add things in the L2PcInstance for that. Deal 1 my focus now is how the two NPC's see each other and how to bind them uniquely.

 

I'm making the decision right now that all boss NPC's and all interactable NPC's are only going to be allowed 1 spawn. I'm blocking spawning two uniquely identified NPC's from being spawned at the same time. This way the NPC id is going to become a reliable key for looking up relations.

 

I don't want to make a global solution for the implementation but I'd like to have a generic interface with a function

( RelationInterface.CheckRelations(L2Player ) ) with classes that implement the interface based on whom you're talking with.

 

public interface RelationInterface { public Something getRelations(); }

 

Keep in mind I'm focusing on simple relations of NPC's right now, the addition of players will come next (need to take this one step at a time since it's quite ambitious).

 

Adenaman: I'll take a look at the link and give it a read over, thanks for the link.

 

  • 0
Posted

If you deal with B, A is going to hate you.

It means player got a role to play. Your system (even that simple one) can't work without player interaction.

 

For such "simple" exemple, you have to register every player. You have also to create a static link between both L2Npc (another map ?), which you have to feed by yourself (or at least finding a particular variable to make checks on, like ALL Gludio merchants hate ALL Dion merchants - in that case, the region).

 

Basically, for a global table, as simple as possible, I see something like :

npcId EnumAction parameter

The parameter being related to EnumAction. Could be a Location model (patrol), a L2PcInstance (trade), another L2Npc (follow/escort), a monster (hunt).

 

SQL table feeding a ConcurrentHashMap, which can return all stored interactions following npcId. Then the AI will act following priority of action.

 


 

About a PURE relation system, just do like the SIMS. One variable put to 100, at 0 it means hate, 100 love. Following npc template, react according other npc template.

  • 0
Posted

You can copy the Varka/Ketra system, if you add the Tryskell idea

-100 to -20 = love completly Varka

-20 to +20 = neutral

+20 to 100 = love Ketra

 

If you want any interface then it must be something like Comparable (or Comparator dont remmember now) but i dont think that you need it.

 

if it is personal player based (love Dion or love Heine) then just add a int / boolean at L2PcInstance and some help method "boolean isDionFriend()" or "int getDionHeineFriendship()"

 

if it is not, (like Hellbound levels more or less) then you need a manager that store that var, it can be singleton because there will be only one (no 2 Dion-Heine relationship)

 

Btw the link is about behavior simulations, dont think that is relevant

Guest
This topic is now closed to further replies.


  • Posts

    • Wooowww!! Thank you so much bruv!! Really useful!! Thank you for smart solution, work and sharing!!
    • Generate your own. There are tools. 
    • Server Athena x45 C4 is running online since 11 January 2026 without wipe.
    • L2SPIRIT OF LORENA x3 INTERLUDE Discord: Discord SPIRIT OF LORENA < WEBSITE: L2 Spirit of Lorena x3 Interlude WEBSITE: L2-LORENA Network x30 x1200 x5000 PvP GRAND OPENING – 12 JUNE 2026 19:00 UTC+2 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ LONG TERM PROJECT NO WIPE CLASSIC INTERLUDE OLD SCHOOL COMMUNITY REAL PROGRESSION ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ WHY L2SPIRIT OF LORENA? Are you tired of servers that die after a few weeks? L2Spirit of LORENA was created for players who miss the true Interlude feeling: Clan Wars Castle Sieges Epic Bosses Party Farming Real Economy Long Term Progression No shortcuts. No instant endgame. No seasonal wipes. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SERVER INFORMATION 🛡 Chronicle: Interlude Type: Classic Low Rate Server: Long Term International Community ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ RATES EXP/SP x3 Adena x3 Drop x3 Spoil x3 Raid Boss x3 Seal Stones x3 Quest x3 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ DYNAMIC EXP SYSTEM 1-20 = x3.0 20-40 = x2.7 40-52 = x2.4 52-61 = x2.1 61-70 = x1.8 70-76 = x1.5 76-77 = x1.2 77-78 = x1.1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ FEATURES Auto Learn Skills Auto Farm Available 2 Windows Maximum Retail Olympiad Epic Bosses Daily Events Stable Dedicated Server Active Administration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ WHAT MAKES US DIFFERENT? No Wipe Policy Stable Economy Competitive Olympiad Clan Focused Gameplay Retail Feeling Friendly Community ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ THE JOURNEY MATTERS Every level. Every raid. Every item. Every victory. This is the Interlude experience you remember. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SERVER STATUS TOP L2JBRASIL:Top L2JBrasil de Servidores de Lineage2 - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ OPENING DAY 12 June 2026 19:00 UTC+2 Prepare your clan. Prepare for war. The adventure begins. SEE YOU IN SPIRIT OF LORENA!
    • PlayerPort: The Ultimate In-Game Web Engine for Lineage 2 Hello. For those who don't know me, I specialize in Lineage 2 interface and client/server development. PlayerPort is my ongoing project - an attempt to build a truly universal, modular, multi-server in-game web engine. The goal is to stop "pushing" players out of the game to forums, websites, or external messengers. Instead, I want to keep them engaged by providing a seamless, high-quality experience directly within the game client. What is PlayerPort? It is a client-side module that acts as a hybrid UI. It integrates a lightweight web engine directly into the Lineage 2 client, bridging the gap between the native engine (UnrealScript/XML) and a modern web layer (HTML/JS/CSS). The Architecture: JS (Layer 0): Handles structural skeletons, widgets, and basic styling. Flash (Layer 1): Manages graphical wrappers, physics/animations, and transitions. PortNatives (C++ API): A low-level engine for math, logging, Windows interaction, WebSockets, and heavy lifting. This "sandwich" architecture allows for smooth, interactive, and high-performance UI components that don't suffer from the limitations of the legacy webkit. Key Features & Modules PortUI Framework: My own lightweight UI framework based on standard Lineage 2 methodology. No heavy external libraries - just vanilla JS with GPU-accelerated rendering. It allows for complex transitions, particles, parallax, and procedural animations without bloating the system. Advanced Report System: Fully integrated ticket management. Players can submit reports directly from the game, including attachments. It supports simple copy-paste or screenshot capture. PortNatives optimizes images (even 4K/8K) in milliseconds, reducing file size by up to 50x without losing quality, ensuring near-instant loading. Radio Module: A streamlined radio service with a vast selection of stations. Features include a mini-player (PIP), high-quality streams with jitter-fix, and a smart system that pre-checks connection status to avoid timeouts. PortStream (Streaming): Full integration for streaming platforms. You can display custom streamer lists or popular feeds directly in-game. Features include status monitoring, live preview tiles, PiP (Picture-in-Picture) playback, and native volume control (up to 200%). Communication Hub: Inter-server forums and messaging that allow collaborating projects to share news, welcome messages, and support systems without leaving the game. Admin & Analytics: Real-time dashboards tracking server population, player behavior, trade analysis, and anti-RMT/botting tools. The system builds connection chains between characters to assist administrators. Why does this matter? The current ecosystem is fragmented. By centralizing everything - support tickets, social interaction, radio, and streaming - within the client, we improve the "Quality of Life" for players and reduce administrative overhead. Performance: All network activity is handled by an external process, isolating it from the l2.exe core. We utilize "lazy" updates (periodic POSTs) and "active" subscriptions, ensuring minimal impact on game performance. Compatibility: Works on everything from ancient clients (like Grand Crusade p110) to the latest Essence/Live versions. Availability: I am looking for enthusiasts and server projects interested in adopting this. Integrating the system is fast and simple. The core service is free. Future Outlook I am currently focusing on PortCanvas, a proxy layer that will allow developers to replace native UI windows with custom web-based components. This will effectively turn Lineage 2 into a shell for fully custom web applications, accessible to anyone with basic web development skills - no complex compilers or proprietary editors required. If you are interested in implementing this on your project, or if you have questions, feel free to reach out.     Gallery https://imgur.com/a/Dqrl4L9         Contact: https://t.me/TELEGABOY See you in the next update. 🐀
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..