Tutorial: NPC's

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Akatana
Posts: 42
Joined: Tue Apr 10, 2012 11:07 pm

Tutorial: NPC's

Post by Akatana »

So I will write a short tutorial on how to create NPC's :)

First of all you need to create a new monster.
I will show you an example on how it should look like:

Code: Select all

cloneObject{
   name = "npcGoromorg",
   baseObject = "goromorg", 
   evasion = 100000,
   onAttack = function(self, dir)
   	return false
   end,
   onMove = function(self, dir)
   	return false
   end,
}
Just copy it into your mod_assets/scripts/monster.lua
Then just place the NPC anywhere into your dungeon.

The next things are optional!

I used this NPC to create an merchant so I created 2 alcoves and a button.
One is for the offer and the other one is for the item which you will get.

Then I wrote a short lua script and connected the checkAlcoveForItems() function with the button (most of it was already done by other persons)

Code: Select all


-- Optional I justed wanted a little bit of dialogue :)
traded = false
function Merchant1()
	if traded == false then
		hudPrint("Hello traveler!")
		hudPrint("I'm a merchant and I would really like to trade with you.")
		hudPrint("If you give me your torch I will give you nice loot!")
	else
		hudPrint("At the moment I have nothing to offer")
	end
end


function checkAlcoveForItems()

   -- Offer
   local itemName = "torch_everburning"
 
   -- offer alcove
   local alcoveID = alcove_offer

   -- checks if the offer alcove has an item 
   if alcoveID:getItemCount() == 0 then
		hudPrint("First you have to place an item into the alcove!")
   end
	
   -- checks if the offer is equal to the item you want
   for i in alcoveID:containedItems() do
      if i.name == itemName then
                 hudPrint("The trade was successful!")
		 
                 -- spawns the item which you will get
                 alcove_win:addItem(spawn("boots_valor"))
                 
                 -- spawns a secret door in front of the offer alcove so that you cant get the offer back
		 spawn("dungeon_secret_door", party.level, 14, 14, 0)
		 traded = true
      else
                 hudPrint("The trade was not successful!")
      end
   end
end
Of course you have to change the items and the alcave ID's

DONE! :D

Here is a little map I made to show you how it works:
https://rapidshare.com/files/865757490/Npcs.rar
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Tutorial: NPC's

Post by Komag »

Wow, this is very cool! It opens up so much potential for interesting interactions, nice. I've added it to the Useful Scripts Repository:
viewtopic.php?f=14&t=3099&p=31949#p31949
Finished Dungeons - complete mods to play
Post Reply