Page 1 of 1

How to get reference to actor GO from dialogue in custom lua function?

Posted: Tue Jul 23, 2024 2:51 am
by Fitbie
Hey Tony and everybody!
I have my own inventory system, and i wish to check for some items during conversations.
So i implemented and register Custom Lua Functions.
But there is 1 problem: i wish i can get a reference to actor gameobject or any component, so i could

Code: Select all

actorGO.GetComponent<IHaveInventory>()
and get reference to Player's inventory.

In CustomLuaFunctionInfo wizard i can see the only acceptable parameter: actor.
So, my questions is
1) What is actor parameter on C# side? Is it a string?
2) How can i get reference to dialogue actor from my custom lua function to search for required interfaces?
Thanks!

(I know it can be done with singletons and custom actor databases, but is there a shortcut?)

Re: How to get reference to actor GO from dialogue in custom lua function?

Posted: Tue Jul 23, 2024 7:41 am
by Tony Li
Hi,

> 1) What is actor parameter on C# side? Is it a string?

It's an actor ID number.

> 2) How can i get reference to dialogue actor from my custom lua function to search for required interfaces?

If the actor is the current conversation's conversation actor, use DialogueManager.currentActor. If it's the conversation conversant, use DialogueManager.currentConversant.

Re: How to get reference to actor GO from dialogue in custom lua function?

Posted: Tue Jul 23, 2024 6:02 pm
by Fitbie
Hey! Thanks for reply!
I figured out another way, i don't know about pifalls, but it seems like it is working

Code: Select all

 private bool InventoryContainsItem(string actorName, double itemId, double amount) // Condition
    {
        Transform character = PixelCrushers.DialogueSystem.CharacterInfo.GetRegisteredActorTransform(actorName);
        if (!character.TryGetComponent<IHaveInventory>(out var inventoryOwner))
        {
            throw new ArgumentException($"You are trying to use custom dialogue method \"InventoryContainsItem()\", but GameObject, associated with passed actor {actorName} does not have ANY component, implementing IHaveInventory!");
        }
        
        return inventoryOwner.Inventory.ContainsItem((int)itemId, (int)amount);
    }

Re: How to get reference to actor GO from dialogue in custom lua function?

Posted: Tue Jul 23, 2024 8:53 pm
by Tony Li
Hi,

That's perfectly fine. It's exactly what I would have suggested next if you weren't using the conversation actor or conversation conversant.