How to register a Lua function with custom dropdown entries?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Pam
Posts: 3
Joined: Sun Feb 11, 2024 8:04 pm

How to register a Lua function with custom dropdown entries?

Post by Pam »

Hi Tony!

Thank you for your amazing work!

I'm trying to create a spawning NPC system for a game, the game has a different scenes with a lot of npc that needs to be spawned on scene change.

I think this is the best solution (i hope):

- NPC Manager for each scene with a list of the npc that needs to spawn on scene load, the list contains (Scene name, Character Name, Dialogue Name, Position (vector 3). (for the change of scene, each time a scene is loaded it reads saved data from a persistent list/file)

Then i want to add two custom commands:

LoadNPC with this structure: Scene/Character/Dialogue/Position

and

RemoveNPC with this structure: Scene/Character (only one character for each type can exist in the list present in the manager)

I want (if possible) to add dropdown autopopulated field when the writer/designer wants to add a character to a scene like the attachment
https://www.pixelcrushers.com/phpbb/dow ... ew&id=4625


I hope it's clear :ugeek:
Thank you again!
Attachments
pixel.png
pixel.png (14.19 KiB) Viewed 196 times
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to register a Lua function with custom dropdown entries?

Post by Tony Li »

Hi,

Do you want the designer to add this character when (1) the scene starts, or (2) in a conversation's dialogue entry > Script field or Dialogue System Trigger > Actions > Run Lua Code?

If (1), you don't need to register a Lua function. You can do this in your own script.

So I'm assuming you mean (2). Unfortunately, the Lua "..." dropdown wizards don't support custom dropdowns. You could instead use a scene event or a custom sequencer command.

If you use a custom sequencer command, you can add custom menu items for all of your characters. See Customizing the Dialogue Editor, specifically SequenceEditorTools.customSequenceMenuSetup or, if your characters are prefabs or ScriptableObject assets in a Resources folder, SequenceEditorTools.tryDragAndDrop.
Pam
Posts: 3
Joined: Sun Feb 11, 2024 8:04 pm

Re: How to register a Lua function with custom dropdown entries?

Post by Pam »

Thank you Tony!

I want the desginer to add the character inside a conversation in the dialogue window on a node.

I tried with the custom sequencer command but (for what i can see) it's not perfect!

I spawn the prefabs of the npcs so i don't think a scene event is the best way

i'm trying with the custom sequencer command while customizing the dialogue editor but i only managed to get the drag and drop working for the character.

If possible i would like the designer to select the character from a list (to avoid checking the names or with a drag and drop), the scene (optionally from a list, is there a way to achieve this to avoid that the user needs to remeber all the scene names?) and the position (set manually)

The structure of the command is: LoadNPC("NPCName", "SceneName","Conversation to start", "Vector 3 position")

with the sequence drag and drop i was able to solve the first problem (NPCName), if there is a way to set also the SceneName or more importantly to set (without the need of the designer to remember the name of the conversation) the conversation that the Spawned npc will have on it's dialogue trigger it would be perfect!


To better understand this is my structure:
Scenes:
- bathroom
- museum
- outside

for each scene there is a script that has a list with a data for each npc that needs to be spawned (NPC name (to get the prefab), Npc conversation to set in his dialogue trigger, npc position)

public class NPCData
{
public string characterName; //same as the scriptableObject with prefab reference
public string dialogueName; //get by the NPC and set on his dialogue trigger (on use) on the spawn of the npc
public Vector3 position; //position to spawn
}

Then there is a persistence data that has the "saved" information for each list for each scene (to mantain the data of the npcs between scenes and play sessions)

Then there is the custom command that needs to add the npc data to the persistent data (the data then will be fetched by the script in the scenes on start)
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to register a Lua function with custom dropdown entries?

Post by Tony Li »

Hi,

For persistence, you may be able to use the save system's Spawned Object Manager.

If you're spawning an NPC that has a Dialogue System Trigger, and you have an NPCData object, you can set its Dialogue System Trigger's conversation like this:

Code: Select all

// Assume npcData is a reference to the NPCData object and spawnedNPC is a reference to the NPC.
var dialogueSystemTrigger = spawnedNPC.GetComponent<DialogueSystemTrigger>();
dialogueSystemTrigger.conversation = npcData.dialogueName;
Side note: You can turn dialogueName into a dropdown menu using the [ConversationPopup] attribute:

Code: Select all

public class NPCData
{
    public string characterName; //same as the scriptableObject with prefab reference
    [ConversationPopup(true)] public string dialogueName; //get by the NPC and set on his dialogue trigger (on use) on the spawn of the npc
    public Vector3 position; //position to spawn
}
I may be misunderstanding where the NPCData object comes from, but hopefully the info above is useful anyway. Now that I re-read your reply, it looks like NPCData may be constructed from this command:

LoadNPC("NPCName", "SceneName","Conversation to start", "Vector 3 position")

If the NPC info is already in the scene, maybe you can use a single reference to that info. Let's say you have an NPC named Adam. Would Adam always appear in the same position in the same scene (e.g., middle of the museum scene) and play the same conversation? In this case, the designer is just triggering an event that causes Adam to appear in this "hard-coded" configuration. If so, it's easier to set up.

On the other hand, if the designer can make Adam appear at any place in any scene and play any conversation, it's still possible, but I don't have any good suggestions yet on how to handle it all "point-and-click" rather than having to type some of that info. Are the designers using the Dialogue Editor window to create content, or are they using an external editor such as Arcweave or articy:draft?
Pam
Posts: 3
Joined: Sun Feb 11, 2024 8:04 pm

Re: How to register a Lua function with custom dropdown entries?

Post by Pam »

Hi Tony thank you for your answer!

Yeah the NPCData is constructed from the command and it's not unique for every character (there can be 1 NPCData for each scene for each character)

Then i have the NPCScriptableObject to store the prefab, the names and other things (it's used to spawn the npc).

When the command is called (example: LoadNPC(Adam, MainScene, DefaultConversation, (0,0,0)) i add a generated NPCData to a manager (singleton) that store all the scenes npc data. when a scene is loaded i search for the entries in the list with same scenename of the new loaded scene and i spawn the given npcs. (of course the position of the spawned npc is given in the command)

I'll look to the documentation of the save system's Spawned Object Manager and for the ConversationPopup!

Maybe if i can't figure it out i will make a custom editor that helps the designer to generate the command (maybe with a vector 3 raycast position picker to allow easy way to set the spawning position)

Thank you!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to register a Lua function with custom dropdown entries?

Post by Tony Li »

Hi,

A custom editor sounds like a good idea. The requirements are a little beyond what the basic editing of the sequence and script fields were designed for.
Post Reply