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_npcevent handler. The player and NPC entity IDs are read from the current group's event parameters.
()talkTo(missionText: s, groupToNotify: c)
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.
CGiveItemRequestMsg with an empty item list is sent to EGS (this is a workaround since there's no dedicated "talk" message type)// 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);
Source: ryzom/server/src/ai_service/nf_grp_npc.cpp (talkTo_sc_)