Thursday, February 7, 2008

NPCs talking to NPCs

Again, a neat idea from Maple. NPCs can now receives message from other NPCs and from characters (well, GMs and admins at least).

What can this be used for? Well, you can simulate 2 npcs having a conversation, have a npc sending orders to another one (like "Attack that player while I run away") and much more other stuff I can't imagine at the moment.

I guess the best way to illustrate the possibilities is to show 2 sample scripts set to 2 different NPCs:

NPC 1:
sayto('comehere','110'); -- say to NPC id 110 to come to NPC 1

NPC 2:
newmessage=getheard();
if (newmessage.message == 'comehere') then
npcposition = getxy(newmessage.sender);
moveto(npcposition[0], npcposition[1]);
end


So NPC 1 ask NPC 2 to come at his position. NPC 2 check for new messages received and check the nature of the message. If "comehere" is found, it gets the position of the NPC 1 and move to it. The moveto command is not done yet but it's next on the list.

I must say that adding commands available to NPCs is quite fun. It requires little work (must be a sign that my framework is well done, hehe) and the results and possibilities are amazing.

Might not seems like much but with just the commands available right now, there's quite some stuff to do interesting AI and mini-games.

Here's the vb.net definition of those commands that can be called from LUA scripting. I'll leave the exact description for another time.

- Function getrandomdirection() As Integer

- Function move(ByVal direction As Integer, ByVal allowchangezone As Boolean) As Boolean

- Sub say(ByVal message As String)

- Sub sayto(ByVal message As String, ByVal targetNameID As String)

- Function getheard(Optional ByVal messageSender As String = "", Optional ByVal firstOrLast As Integer = 0)

- Function getrandomcharacter(ByVal distance As Integer, Optional ByVal distanceType As enumDistanceType = enumDistanceType.ChessKing) As String

- Function getrandomnpc(ByVal distance As Integer, Optional ByVal distanceType As enumDistanceType = enumDistanceType.ChessKing) As Long

- Function getnewestcharacter() As String

- Function getxy(Optional ByVal targetNameID As String = "") As ArrayList

- Function getdistance(ByVal targetNameID As String, Optional ByVal distanceType As enumDistanceType = enumDistanceType.ChessKing) As Integer

0 Comments: