Useful scripts repository

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

Re: Useful scripts repository

Post by Darsithis »

Created an interesting "round-robin" scheme between 3 altars a la Eye of the Beholder. To reproduce:
  • Create 3 altars. Make two of them inaccessible
  • Name your primary one, the one someone is going to place an item onto, "sacrificeAltar"
  • Name the other two "rewardAltar1" and "rewardAltar2"
  • Add the script below to a script entity
  • Connect said script to activate of sacrificeAltar
  • Add at least ONE item to each of the other two reward altars. Without items, this will fail!
  • When someone places an item on the sacrifice altar, it will cause items to move between the 3
As long as you have items to add to the sacrificeAltar, it will continue to move them between all of the altars over and over. You can add as many altars as you wish and you can limit by items just by checking item names before moving things. This could make it more "sacrificial" by preventing people from using common things like rocks.

The reason I destroy and respawn the sacrificeAltar (and reconnect it to the script) is that the activate event connector will cause a stack overflow otherwise when placing an item.

Code: Select all

function Sacrifice()

	
	for alcoveItem in sacrificeAltar:containedItems() do
		local itemName = alcoveItem.name
		alcoveItem:destroy()
		rewardAltar1:addItem(spawn(itemName))
		break;
	end
	

	for alcoveItem in rewardAltar1:containedItems() do
		local itemName = alcoveItem.name
		alcoveItem:destroy()
		rewardAltar2:addItem(spawn(itemName))
		break;
	end	
	
	sacrificeAltar:destroy()
	spawn("deep_temple_altar", party.level, 3, 23, 1, "sacrificeAltar");
	
	for alcoveItem in rewardAltar2:containedItems() do
		local itemName = alcoveItem.name
		alcoveItem:destroy()
		sacrificeAltar:addItem(spawn(itemName))
		break;
	end	
	
	sacrificeAltar:addConnector("activate", "sacrificeAltarScript", "Sacrifice")
end
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Natural dialog with pauses.

Post by Isaac »

This is a quick script made for delivering a series of up to nine statements via hudPrint(). To use it, place it in a script object, and connect a trigger, or call the longSpeech() function.

To customize it, simply change the quoted text in the 'statement' table, and [optionally] adjust the values in the 'pause' table, to best suit your text ~that is if the automatic delay is not ideal.
If it's not, simply replace the entry with your own number as the delay.

Code: Select all

	
--[[ This script supports up to nine statement entries, with pauses between them. 
	Add or remove the statement entries as needed.

	This script does not ~technically~ support multi-line statements, but it is possible
	to format a string with extra spaces and escape code \n, to fit in a second line of text.
	The extra empty spaces would be needed to center the text manually, and you might want
	to use a number to override the delay, as the spaces would count to lengthen the pause.  
	
	The statement table must have nine entries (statements). They can be empty; empty quotes are
	ignored, and should ~only~ exist as the last entries; to fill up the remainder of the nine slots. 
	
	IMPORTANT: Only call this script once (obviously), you should only call it via script, or with a one-time use pressure plate.	
	If you do call it more than once with script, make sure that it has had time to stop; or else the statements can overlap.

--]]
	

statement = {
			"This is the first statement.",
			"And this is the second. (After a brief pause)",
			"[clears throat]",
			"and this is the final statement.",
			"[an awkward silence ensues]",
			"Where has the rum gone?",
			"               Double line of text, \n it kind of works, but it\'s not perfect.",
			"",
			"",
		} -- There must always be nine statements. Pad the end of your dialog with  "",
                         
pauses = {0,
				#statement[1]/5,
				#statement[2]/5,
				#statement[3]/5,
				#statement[4]/5,
				#statement[5]/5,  -- replacing this line with   35,   would add a 35 second delay after the fifth statement. 
				#statement[6]/5,
				#statement[7]/5,
				#statement[8]/5
				}  
				--[[	Pause #1 should always be zero. The other '#statement[?]/5' values can be replaced with your own number 
					of seconds to wait. One reason that you might wish to do this, is to include an extended pause.
					
					For this you must still type something as a statement entry ~be it only a blank space " ", or even some
					descriptive note like "[an awkward silence ensues]". it cannot be empty quotes.
				--]]


	function _statementPrint(caller) _screenClear() hudPrint(tostring(statement[tonumber(string.sub(caller.id,-1))])) caller:destroy() end

	function _delayEval(x)
			local temp = pauses[1]
			if x ~= nil then
			 	 for y = 1, x do
					if statement[y] == "" then break 
					else
						temp = temp + pauses[y]
					end
				 end
			end
		return temp
	end
							
	function longSpeech()
		for x= 1, #pauses do

				local delay = _delayEval(x)
				local name = 'timer_['..getStatistic('play_time').."]_"..x
			if statement[x] == "" then return 
			else
				spawn('timer', party.level, 1,1,1, name )
				:setTimerInterval(delay)
				:addConnector("activate", self.id, "_statementPrint")
				:addConnector("activate", "name", "destroy")
				:activate()
			end

		end
	end
	
	function _screenClear() hudPrint("") hudPrint("") hudPrint("") hudPrint("") hudPrint("") end
						

		
Glew
Posts: 74
Joined: Sat Dec 21, 2013 7:57 pm

Re: Useful scripts repository

Post by Glew »

This is pretty basic stuff, but it may be useful to people who are completely new to scripting (like I was/am).

How to search a floor/room for a specific item

I used this because I had to change a lot of dungeon_wall_texts into temple_wall_texts and wanted to make sure there are no dungeon models left on the level.
What it does: It prints to screen the name, x and y coordinates of the items you are looking for. I'm sure it can be improved upon, but it served its purpose for me.

Code: Select all

function search()
for x=0, 31 do --you can obviously change these if you only want to search a room and not the whole floor
	for y=0, 31 do
	for e in entitiesAt(self.level, x, y) do 
        if e.name =="dungeon_wall_text" then --your item's name here, or it could be any other condition
	hudPrint("Found "..string.lower(e.name).." at x "..tostring(e.x).." y "..tostring(e.y).." .")
	end
	end
	end
	end
end
Stuff with wall texts and scrolls

I've been toying around to see what can be done with text in the game. Turns out you can do lots if you get the hang of it. There are so many puzzle/story possibilities. So here are a few, simple examples on how to mess with text.

Code: Select all

function varPrint() --you can get the value of a non-string variable printed, good for testing and debugging
local fact=true
hudPrint(tostring(fact))
if fact then hudPrint("fact is true") else hudPrint("fact is false") end
end

--how to print attributes of objects, ID and class here
function printID()
hudPrint("the X coord is "..tostring(self.x).." for this item")
end

function printClass()
hudPrint("The class of the "..string.lower(readable_note.name).." IS "..string.lower(readable_note.class))
end

function readNote() --what it says on the package; you will need a scroll type item for this
hudPrint(id_of_your_scroll:getScrollText())
end

function readWall() --same with wall text
hudPrint(id_of_your_wall_text:getWallText())
end

function copyToWall() --you can get text stored on one object/item to an other one
if id_of_your_scroll~=nil then 
--sadly this one crashes if the party picks up the scroll so you better check if the scroll can be found
wall_text:setWallText(id_of_your_scroll:getScrollText()) 
end
end

function grafitti() 
--now this is more interesting, you place a counter and a button,
--and connect the button to the function, but not to the counter 
read_counter:increment()
local x=read_counter:getValue() --the lazy way to get the counter value
hudPrint(tostring(x)) --optional
test_text:setWallText("You have pressed the button "..tostring(x).." times.")
end
I hope if someone else is still modding Grimrock 1 and they are coding-impaired like me, they'll find this useful.
User avatar
Resu
Posts: 141
Joined: Tue Nov 10, 2015 12:09 am

Re: Useful scripts repository

Post by Resu »

i have problems with the Earthquake shake, the sound is played but neither the particle effekt script and the shake are happening..

function scareshake()
party:shakeCamera(0.5,3)
end

just this in a script entity but nothing happens

whats wrong there?

edit: ok i just removed "function scareshake()" and it worked :O

i have another task: i have problems to define conditions in scripting, something like when a lever is activated --> activate scipt/function

how can i do it for example?
User avatar
Nathaniel
Posts: 111
Joined: Sun Jul 26, 2015 9:09 pm
Location: Ukraine

Re: Useful scripts repository

Post by Nathaniel »

Hi guys!

Please tell me how to do the following things...
1. Suppose I decided to dig in the same cage. After that there is something like a heap or hole on the ground of the earth. Is it possible to remove this hole? Unpleasant after "dig" to go to these piles of earth...

2. I want to change the color of illumination light spells. For example, the intensity and color. How to do it?
Legend of Grimrock 1.3.7
Legend of Grimrock II 2.2.4
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Useful scripts repository

Post by Isaac »

Note: This is a Grimrock2 question.
Nathaniel wrote:Suppose I decided to dig in the same cage. After that there is something like a heap or hole on the ground of the earth. Is it possible to remove this hole? Unpleasant after "dig" to go to these piles of earth...
To remove a specific hole, use the following in the console (stand the party on the hole before use):

Code: Select all

for each in party.map:entitiesAt(party.x,party.y) do if each.name=="dig_hole" then each:destroy() end end
To remove every hole on the map, use this version instead:

Code: Select all

for each in party.map:allEntities() do if each.name=="dig_hole" then each:destroy() end end
https://player.vimeo.com/video/177289581

**Be aware that removing all holes in this way, might remove intentional holes placed by the map designer. Use with caution.
Last edited by Isaac on Sat Aug 13, 2016 11:18 pm, edited 1 time in total.
User avatar
Nathaniel
Posts: 111
Joined: Sun Jul 26, 2015 9:09 pm
Location: Ukraine

Re: Useful scripts repository

Post by Nathaniel »

Isaac wrote:To remove a specific hole, use the following in the console (stand the party on the hole before use):

Code: Select all

for each in party.map:entitiesAt(party.x,party.y) do if each.name=="dig_hole" then each:destroy() end end
Thank you very much! :) I think I'lll have enough the first option...
Legend of Grimrock 1.3.7
Legend of Grimrock II 2.2.4
Howl3r
Posts: 12
Joined: Fri Aug 12, 2016 11:34 pm
Location: Finland

Re: Useful scripts repository

Post by Howl3r »

Komag wrote:Post on-screen text with a character's name:

Code: Select all

local name1 = party:getChampion(1):getName()
hudPrint("You know "..name1..", you are an incredibly effective adventurer!")
COMMENT EDITED:

I'm not sure if this is where to ask a question, but I have a little problem.
I am not using this to display a character's name so for me it is just written like

Code: Select all

function talk()
hudPrint("example")

end
Now the issue is, that I don't know how can I make it display for a given time. If you just give me the variables and stuff I think I can get it done myself. A full given script would be awesome though so I don't need to bother you again with this subject xP

Thank you for your time ^^
Last edited by Howl3r on Sat Aug 13, 2016 7:42 pm, edited 1 time in total.
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Useful scripts repository

Post by THOM »

everything you write in a script-object is executed emediatly at game beginning.
If you don't want this, you have to write it into a function:

Code: Select all

function abcdefg()
hudPrint("example")
end
Now you can connect the trigger with the script-entety and choose from the drop-down-menu on the right the name of the function you meant. In this case "abcdefg".
Last edited by THOM on Sat Aug 13, 2016 7:43 pm, edited 1 time in total.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Howl3r
Posts: 12
Joined: Fri Aug 12, 2016 11:34 pm
Location: Finland

Re: Useful scripts repository

Post by Howl3r »

THOM wrote:everything you write in a script-object is is executed at game beginning
what you want is

Code: Select all

function abdcdefg
hudPrint("example")
end
Now you can connect the trigger with the script-entety and choose from the drop-down-menu on the right the name of the function you meant. In this case "abcdefg".
I edited the comment as I got out of the total retardation level to a slightly retarded level xP
Post Reply