Okay, before I say anything. I would like to note that I haven't actually implemented Lua/Textbox communication, but it's
my second highest priority at the moment. Hopefully I may even get around to this tonight.
Here is the plan. I plan to have the conversations loaded from text files (generated by some sort of utility (that I'll make Peter make)). The reason for this is because it would be a pain in the ass (imho) to write entire conversations with nothing but Lua. Especially when there might be completely normal NPCs that don't need any sort of special Lua logic or AI. You can do their entire conversation in the editor.
A complex NPC might have this text file:
Code: Select all
@progress1
Wow, you aren't very far at all in this game.
I recommend that you quit failing at life.
Or at least go grind for an hour.
@progress2
I see that you suck slightly less.
You got a little better at the game,
but you still have a long way to go.
@progress3
Oh wow! You are totally kicking
this game's ass! I tell you what, homeboy.
Since you have 10 potions, I have a surprise for you.
:Accept:@accept
:Decline:@decline
@accept:TakeHP
For your hard work and effort put into this
game, I would like to reward you by
taking your HP, dumbass.
@decline
Oh, suit yourself, prick.
[blank]
[blank]
@hit:LuaMethodName
OUCH, THAT HURT, ASSHOLE!!
[blank]
[blank]
Now we have a more complicated NPC scenario. Each NPC can have a Talk() method that gets invoked by the engine when you try to speak to the NPC. It might look something like this:
Code: Select all
function Talk()
if player.progress == 1 then PopTextBox("progress1")
else if player.progress == 2 then PopTextBox("progress2")
else if player.progress == 3 and inven:getAmount("potion") == 10 then PopTextBox("progress3") end
end
Now, when you try to talk to the NPC, you can go to a certain label depending on whatever scenario you want. If they have so much money, if their health is this low, if whoever is in their party, etc. You are passing the label to the textbox, which goes to that label.
You have this:
Code: Select all
@accept:TakeHP
For your hard work and effort put into this
game, I would like to reward you by
taking your HP, dumbass.
for when you want the engine to call Lua based on some sort of textbox input or something. When the textbox displays the "accept" label, it also calls TakeHP(), which hurts the player.
Then you also have special labels that don't get seen under regular conditions. For example:
Code: Select all
@hit
OUCH, THAT HURT, ASSHOLE!!
[blank]
[blank]
This isn't displayed unless a special event calls that label. I would have something like this in the NPC's Lua file:
Code: Select all
if PLAYER_SMACKS_NPC_WITH_ITEM then
PopTextBox("hit") --bitch the player out
---Enqueue some sort of logic for the NPC to throw the item back
--Or respond to the player's stimulus.
Now we have conversations for the NPC responding to an item being thrown at them. If they are hit by one, the textbox displays at the "hit" label (which is the NPC bitching at the player), then some sort of logic for the NPC's response to the stimulus is performed.
MarauderIIC is currently working on our NPC action queue, so that isn't quite implemented yet either, but the logic is still the same.
I prefer this method for the textbox because it's powerful as the textbox can call certain Lua methods based on the label, and a conversation can be started anywhere in the NPC's script by any stimulus (talking, being hit by something, being in its general vicinity, etc).
But again, I haven't implemented the actual Lua/Textbox interaction yet. I had sat down and planned the scenario out, and I'm pretty sure it would work nicely. If you see anything stupid or have a better idea, let me know.