talk_to - ryzom/ryzomcore GitHub Wiki


title: Talk To description: Add a contextual menu entry for a player to talk to an NPC published: true date: 2026-03-14T00:00:00.000Z tags: editor: markdown dateCreated: 2023-03-16T22:30:34.974Z

talkTo

The talkTo native AI script function adds an entry to the NPC's right-click contextual menu allowing a player to interact with the NPC. When the player clicks the menu entry, user events are triggered on the specified callback group, allowing the AI script to respond (e.g. give a reward, start a dialog, etc.).

This function can only be called from a player_target_npc event handler. The player and NPC entity IDs are read from the current group's event parameters. {.is-warning}

Syntax

()talkTo(missionText: s, groupToNotify: c)

Arguments

  • missionText (string): The text that will appear in the NPC's contextual menu entry.
  • groupToNotify (context): The NPC group that will receive user events when the player interacts. Obtain with context().

Callback User Events

The following user events are triggered on groupToNotify:

Event When
user_event_1 Triggered when the menu is presented to the player
user_event_3 Triggered after the player clicks the menu entry and talks to the NPC

The event parameters (accessible via getEventParam) contain the player and NPC entity IDs at indices 0 and 1. These are needed by functions like giveReward that operate on the interacting player.

How It Works

  1. The NPC turns to face the player
  2. A CGiveItemRequestMsg with an empty item list is sent to EGS (this is a workaround since there's no dedicated "talk" message type)
  3. EGS presents the contextual menu to the player
  4. When the player clicks the entry, EGS triggers the user events back on the callback group

Example

// In a player_target_npc event handler:
($playerEid)getCurrentPlayerEid();
(@myGroup)context();
()talkTo("Talk to this NPC", @myGroup);

Then handle the response in user_event_3:

// In a user_event_3 handler on the same group:
// The player has clicked the menu entry
(@myGroup)context();
()giveReward("Reward!", "Rare!", "Full!", "No points!", @myGroup);

See also

Source: ryzom/server/src/ai_service/nf_grp_npc.cpp (talkTo_sc_)

⚠️ **GitHub.com Fallback** ⚠️