Ask a simple question, get a simple answer

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!
ColdDeadStone
Posts: 24
Joined: Sat Nov 26, 2016 12:12 pm

Re: Ask a simple question, get a simple answer

Post by ColdDeadStone »

My attempts to spawn a script in the running game and fill it with functions() have more or less failed. Rather more than less... I thought of a possibility similar to ORRR3.

>> ORRR3 - v1-1 - sourcepack-132-1-0-1588505955\ORRR3 - v1-1 - source\mod_assets\patcher.lua

Code: Select all

-- This file is for handling updating old savegames to new versions of the mod.
local CURRENT_VERSION = 3 -- Version 1.1

-- To dynamically create a script entity that actually runs its code,
-- ScriptComponent:loadFile() must be called in the onInit hook of a component
-- that appears before the ScriptComponent.

defineObject{
	name = "script_entity_patched",
	placement = "floor",
	components = {
		{
			class = "Null",
			name = "hackyLoader",
			onInit = function(self)
				self.go.script:loadFile(GameMode.patchScriptFile)
				GameMode.patchScriptFile = nil
			end,
		},
		{
			class = "Script",
		},
		{
			class = "ScriptController",
			name = "controller",
		},
	},
}
But there is obviously no easy way. I am not afraid that I forgot a door or a key or something like that but a typo in a script for example. Anyway, every "quest" and every "puzzle" what I have built, was always thoroughly tested by me, I'll just keep my fingers crossed... :?
Sorry for my poor english... hope you understand what i try to say! :)
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

If I remember right that patching system in ORRR3 worked because there was a mechanic implemented before we patched it the first time. It couldn't have be done without that implementation. So if you try to patch an already existing game it won't work that way.

What I am wondering: If I got you right you are trying to patch your own mod. - Why? Don't you have the sourcecode anymore?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
ColdDeadStone
Posts: 24
Joined: Sat Nov 26, 2016 12:12 pm

Re: Ask a simple question, get a simple answer

Post by ColdDeadStone »

I want to be prepared, I've been working on the "Dungeon" since 2014 and now it's almost ready. In case something goes wrong I wanted to know in advance what I can do to eliminate problems.

I just did some tests and noticed that patching is not possible when loading a savegame. The game informs you that the dungeon now has a different version, but unfortunately the new (or changed) scripts are not included, as if you were still playing the old version.

I've been working on it for so many years now and have accumulated over 107 GB of data and backups of the dungeon, I'd hate to see it crash when you finally get around to playing it....

Therefore, I wanted to ask in advance if there are any possibilities that could help me. The MOD is not played yet.
Sorry for my poor english... hope you understand what i try to say! :)
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Ah - now I got you!

Yes, if you think, providing an update is not enough and you also want to patch the savegames of players, then the patching mechanic of ORRR3 is what you want.

You kann alter, move or delete gameobjects with it, or overwrite scripts.

BUT: This mechanic is quite complex. The file you have pasted parts from above has a lot of comments in it. This should help you to find out how it works. Sadly the parts of the tool are spread over the whole ORRR3 project, so a bit searchwork will be needed. In example the definition of the main-object is in the sources of minmay's rooms IIRR.

And you have to be careful: You can only patch objects, of whom you are absolutely sure, that they are in the savegame in the absolutely same condition as your patch-script thinks they are. If in example a monster is already killed and you want to raise its halth, you will get a crash. The same for food that is already eaten or - and that's most important - scripts that store data (which do a lot scripts that are more complex). If you overwrite them by an updated one its data get lost and that could break funktions and gamebehavious. So you must be careful here.

Sadly I'm not the best man to assist with this. The patching system of ORRR3 was done by minmay, who is maybe willing to answer questions if you have some. Or you may ask Zo Kath Ra who has done a lot on the patching script for the latest ORRR3 release.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: Ask a simple question, get a simple answer

Post by ratman »

I have been experimenting with scaling objects, and have decided to try and make a script to make all of my objects called "forest_oak_trunk_large" be scaled so that I don't have to manually do every one. However, when I put my script in, I don't even get an error or anything, the game just freezes up. Can anyone tell me what's wrong with this script?

Code: Select all

	data		= {amount,maxamount}
function growplants()
	
	data.amount		= 0 --current plant
	data.maxamount	= 1 --put your highest plantnumber here
	local plant = findEntity("forest_oak_trunk_large_"..data.amount)
	

		
		local m = forest_oak_trunk_large_1:getWorldRotation()
		local scale = 0.5
		m.x = m.x * scale
		m.y = m.y * scale
		m.z = m.z * scale
		m.w = m.w * scale
		forest_oak_trunk_large_1:setWorldRotation(m)

		
		
			
					data.amount = data.amount + 1

				
			if data.amount > data.maxamount  then
				self.go:destroy()
			else
				delayedCall(self.go.id,0.04,'growplants') 
			end
end

delayedCall(self.go.id,0.02,'growplants')
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

ratman wrote: Mon Mar 21, 2022 10:51 pmCan anyone tell me what's wrong with this script?
Stack overflow.

_________________
Try this out:

Code: Select all

data		= {}
	data.amount		= 0 --current plant
	data.maxamount	= 5 --put your highest plantnumber here

function growplants()

	local plant = findEntity("forest_oak_trunk_large_"..data.amount)
	
	if plant ~= nil then
		local m = plant:getWorldRotation()
		local scale = 0.5
		m.x = m.x * scale
		m.y = m.y * scale
		m.z = m.z * scale
		m.w = m.w * scale
		plant:setWorldRotation(m)
	end	

		data.amount = data.amount + 1
			
		if data.amount > data.maxamount  then
			self.go:destroyDelayed()
		else
			 growplants() 
		end
end

if data.amount == 0 then growplants() end
You could do this another way, by calling growplants from within the object's own onInit hook function, via the object definition. Then they would each call growplants() when they spawn.... or you could simply put the scaling code in the onInit hook itself.
2498billb
Posts: 40
Joined: Thu Dec 30, 2021 6:06 pm

Re: Ask a simple question, get a simple answer

Post by 2498billb »

Hi can anyone help me with party needing a scroll on them before it can be cast, but scrolls also can be placed in
any container, i have some code to enable this but when placed in container it will not work.
Here is my code which i got from forum a long time ago:

Code: Select all

defineObject{
   name = "party",
   baseObject = "party",
   components = {
      {
         class = "Party", 
         onCastSpell =
            function(party,champion,spellName) 
                  local itemName = "scroll_"..spellName        
                  for i = 1, 32, 1 do
                         if champion:getItem(i) ~= nil and champion:getItem(i).go.name == itemName then
                             return true
                        end
                  end
                  hudPrint(champion:getName().." needs to have the spell scroll on him to be able to cast it")
                  return false 
           end
      
		}
	}
} 
How can this be amended to enable scrolls in containers? Help appreciated thx.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Try this:

Code: Select all

baseObject = "party",
	components = {
			{
				class = "Party",
				onCastSpell = function(party,champion,spellName)
								local itemName = "scroll_"..spellName
								local containers = 0
								
								--Inventory Search
								for item = 1, 32 do
									
									if champion:getItem(item) ~= nil then
										
										--Container Search Function
										local function searchContainer(component)																				
													if component ~= nil and component:getClass() == "ContainerItemComponent" then
														for x = 1, component:getCapacity() do
															local item = component:getItem(x)
															if item ~= nil and item.go.name == itemName then
																return true
															end	
														end
													end
													return false	
												end

										--Search Container Component
										for _,component in champion:getItem(item).go:componentIterator() do
											if searchContainer(component) then
												return true	
											end	
										end	
									
										--Search Inventory Slots for [scroll] itemName 
										if champion:getItem(item) ~= nil and champion:getItem(item).go.name == itemName then
											return true
										end 
		
									end
								end
								--Failure [no spell scroll]

								--Sound & Visual Effect
								playSound("spell_fizzle")
								champion:showAttackResult("Fizzle", "SpellFizzle")
								
								--Caster's name
								local formattedName = champion:getName():sub(1,1):upper()..champion:getName():sub(2)

								--Failure Message
								local warningMsg = formattedName.." needs to have the spell scroll on "..iff(champion:getSex()=="female","her", "him").." to be able to cast it."
								hudPrint(warningMsg)
								return false
							end
			}
		}
	}
Last edited by Isaac on Mon Apr 25, 2022 3:19 am, edited 2 times in total.
2498billb
Posts: 40
Joined: Thu Dec 30, 2021 6:06 pm

Re: Ask a simple question, get a simple answer

Post by 2498billb »

Hi Isaac
thankyou for your speedy answer, have tried out your code and it works a treat.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

You can also use

Code: Select all

party:isCarrying(itemName)
to check if they're carrying the scroll, including in containers.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply