Creating Questgivers

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
supercell1970
Posts: 4
Joined: Mon Mar 11, 2024 11:44 pm

Creating Questgivers

Post by supercell1970 »

How create questgiver in a conversational script? I want the player to be able to accept a quest but when they return to talk to the NPC, they will ask if they have what they want yet.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Creating Questgivers

Post by Isaac »

It's certainly possible to make them, but it's not an included [turn key] feature of the game.

You will have to write a custom script for this; as simple or complex as you wish, depending upon how involved you want the interactivity to be.

You would need a table of quest stages to hold the player's progress, and for your NPC dialog scripts to reference; to direct their dialog prompts and responses.

There are conversational scripts in public mods; I can link to one when I return home later tonight. One Room Round Robin 2 & 3 are good mods to examine. The town blacksmith (Ratling) in ORRR3 has dialog quests to learn from; it has the very framework of what you describe. The Smith describes, and later will accept ore for crafting a weapon.

The ORRR2&3 mods both use a custom framework for their dialog interaction; you can use it it your own mods.
Last edited by Isaac on Tue Mar 12, 2024 12:06 am, edited 1 time in total.
supercell1970
Posts: 4
Joined: Mon Mar 11, 2024 11:44 pm

Re: Creating Questgivers

Post by supercell1970 »

Okay. Thanks. All is appreciated.
supercell1970
Posts: 4
Joined: Mon Mar 11, 2024 11:44 pm

Re: Creating Questgivers

Post by supercell1970 »

Here is something I found on Grimrock.net. Is there a way to set a variable in this? I am having hell trying to get it to work properly.

Code: Select all

function gtkDidLoad()
	GTK.Core.GUI:addImage({ name="book-of-monsters", path="mod_assets/ext/grimtk/samples/book-of-monsters.tga", size={545, 400} });
end

questAccepted = false;

function biteParty()
	local champion = party.party:getChampion(1);
	champion:damage(10, "physical");
	playSound("consume_food");
	champion:playDamageSound();
end

function enableBook()
	local e = findEntity("book_of_monsters");

	if ( e ) then
		e.item:enable();
		e.item:setUiName("Book of Monsters!");
		isDone = true;
	end
end

function showDemoDialogue(sender)
	if ( questAccepted == true ) then
		return;
	end

	local dialogue = {
		lockParty = true,
		pages = {
			{
				id = "first",
				mainImage = "book-of-monsters",
				speakerMessage = "A small book lies still on an altar behind the bars...",
				playSound = "polymorph_bear",
				responses = {
					{ text = "<Poke It>", nextPage = "poke", onSelect = self.go.id..".script.biteParty" },
					{ text = "<Stare At It>", nextPage = "stare" },
					{ text = "<Walk Away>" },					
				} 
			},
			{
				id = "poke",
				mainImage = "book-of-monsters",
				mainMessage = "*Gnash* *Gnash* *Gnash*",
				responses = {
					{ text = "Okay...", nextPage = "first" },
				}
			},
			{
				id = "stare",
				mainImage = "book-of-monsters",
				mainMessage = "WHAD YA WANT?",
                                questAccepted = true,
				responses = {
					{ text = "To read you!", nextPage = "okay" },
					{ text = "<Walk Away>" }
				}
			},	
			{
				id = "okay",
				mainImage = "book-of-monsters",
				mainMessage = "OKAY THEN!",
				responses = {
					{ text = "<Done>", onSelect = self.go.id..".script.enableBook" },
				}
			}
		}
	}

	GTKGui.Dialogue.startDialogue(dialogue);
end

function hideDemoDialogue()
	GTKGui.Dialogue.hideDialogue();
end
edited by Zo Kath Ra
(now the code is wrapped in code tags)
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Creating Questgivers

Post by Isaac »

There are those here and on Discord who will gladly instruct on the finer points of scripting (or even create them for you). 8-)

(I don't have the Discord link offhand, but I will post it later if none post it before me.)

Edit: https://discord.gg/ArgAgNN
supercell1970
Posts: 4
Joined: Mon Mar 11, 2024 11:44 pm

Re: Creating Questgivers

Post by supercell1970 »

When I change a variable in a script, how do I keep it the same throughout the dungeon level? In other words, is it a global variable?
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Creating Questgivers

Post by Isaac »

supercell1970 wrote: Wed Mar 13, 2024 2:00 am When I change a variable in a script, how do I keep it the same throughout the dungeon level? In other words, is it a global variable?
No. You must access the variable through the script. Variables that are declared in a script —but outside of a function, are accessible from within that script by those functions, and saved with it in the saved-game. The variables are also accessible from outside of the script, by other scripts.

The simplest way to check a value from within a script is directly by name, like this: (script_name.script_component_name.variable_name)

Code: Select all

magic_itemOwnerName = "Ralph"
from another script you can have print(script_entity_1.script.magic_itemOwnerName), and it will print the value of the variable.

However if you make a function that takes one or more arguments to then set the value of one or more variables in the script, then you can change them from within the script via an outside call; these are often called Getter & Setter functions.

Example: (Paste this into a script on a new map, and preview.)

Code: Select all


magic_itemOwnerName = "Ralph"

function setItemOwnerName(name) 
      magic_itemOwnerName=name
end

function getItemOwnerName() 
      return magic_itemOwnerName
end



--_________________________________________________________________
--Example of result: (Not needed in your own implementation.)
print("magic_itemOwnerName is currently:", getItemOwnerName())
setItemOwnerName("Robert") 
function output()playSound("secret")party:spawn('blob')print("magic_itemOwnerName has been changed to:",getItemOwnerName())end
delayedCall(self.go.id,2,"output")
	
--_________________________________________________________________	
Post Reply