Do I even need scripting? You usually add a scripting engine to a game engine so that you have a simpler work environment for team members which are less skilled at programming. But I am working alone. So why not just create a simple framework to define quests in Java and leave it as that? Could be much less work because I wouldn't have to worry about script bindings and could interact with the server engine directly.
A drawback would be that I would not be able to change quest coding at runtime. I would have to rebuild the server for every single script change (Although Manaserv has the same problem even though it uses Lua as a scripting backend). Also when I ever do hire people to help me with content or I would like to license the server to someone without revealing the sourcecode, I would need to give them a way to do stuff without any hardcoding.
An alternative to implementing a full scripting backend with a real scripting language would be to use some kind of markup language like JSON or XML to describe NPC dialog trees and other frequent use-cases for scripting. That way I could move the trivial stuff to external files and not clutter the servers codebase with hundreds of trivial NPC dialogs.
This is an example how I could do a simple dialog with JSON:
{"dialog": [
{ message: "Hello" },
{ message: "How can I help you?" },
{ choice: [
{ option: "Where is the castle?",
dialog: [
{ message: "Just down the road, you can't miss it." }
],
next: "back"
},
{ only_when_equal { "quest_slay_dragon", false },
option: "I need a job",
dialog: [
{ message: "I got a quest for you." }
{ message: "slay the dragon in the mountains." }
{ choice: [
{ option: "No, that's too dangerous!" ,
next: "back"
},
{ option: "Sure, let's go!",
dialog: [
{ setvar: { "quest_slay_dragon", true } },
{ message: "good luck, then" }
],
next: "quit"
}
]
}
],
next: "back"
},
{ only_when_equal { "quest_slay_dragon", true },
option: "I need a job",
dialog: [
{ message: "I already told you to slay the dragon!" }
],
next: "back"
}
{ option: "Nothing, goodbye",
next: "continue"
},
]},
{ message: "It was a pleasure to meet you." },
{ only_when_equal: { "quest_slay_dragon", true },
message: "And good luck with the dragon!" }
]}
Explanation:
dialog: Process the following elements as dialog.
dialog->setvar: Set the variable as key to the value
choice: present the elements of this array to the user as dialog options:
choice->option: dialog option text the user can select
choice->dialog: (optional) process the following dialog when the user clicks this option
choice->next: what to do after processing the dialog. "back": go back to choice. "continue": continue after the choice. "quit": leave the dialog.
*->only_when_equal: ignore this element, when the variable is unequal to the value
No comments:
Post a Comment