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!
Post Reply
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Ask a simple question, get a simple answer

Post by JKos »

minmay wrote: ...
Well, you cannot overwrite the native addConnector method as far as I know, so you can't use that exact code. You would use something like this:

Code: Select all

function myTestSpawn()
   local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation)
   fw.script:set(o.id..'@item.whateverNamespaceYouWant.onEquipItem',aaa)
  fw.script:set(o.id..'@item.whateverNamespaceYouWant.onUnequipItem',bbb)
end

function aaa()
   print("A")
end

function bbb()
   print("B")
end
Also if the hook framework works similarly to how it does in LoG1 (I haven't tested) function ownership will change from this script component to the fw script if the game is saved and reloaded, so you need to account for that (only reference the global environment in the function).
Yes, that should work, but you should be aware that functions aaa and bbb will be copied when the game is saved, so every item will have their own copies of those functions, I think this is what you meant by "function ownership will change from this script component to the fw script". It's an effect of the serialization method of LoG, references can not be serialized instead the referenced object/fuction will be copied.
If you want to avoid that you should define those hooks like this:

Code: Select all

function myTestSpawn()
   local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation)
   fw.script:set(o.id..'@item.whateverNamespaceYouWant.onEquipItem',function(hook,item,champion,slot) 
      your.script.aaa(item,champion,slot) 
   end)
   fw.script:set(o.id..'@item.whateverNamespaceYouWant.onUnequipItem',function(hook,item,champion,slot) 
      your.script.bbb(item,champion,slot) 
   end)
end
Tip: With cloneObject you can easily register framework hooks to all items.

Code: Select all

modifyObjects{
	filter = {
		hasComponents = {"item"}
	},
	components = {
		fw_addHooks{ 
			class = 'Item',
		}
	}
}
This may be a wrong thread for this discussion, so if you have more questions about the framework, we should continue in the framework thread: viewtopic.php?f=22&t=8345
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Ciccipicci
Posts: 154
Joined: Mon Oct 08, 2012 12:55 am

Re: Ask a simple question, get a simple answer

Post by Ciccipicci »

There's a way to implement a particle effect like the first LoG when a quake is happening?
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

Is there a way to see all the icons and spell icons available (in their numeric codes order) ? I have a lot of custom spells (with the same icons for now) and I would like to choose their icons without testing every code number with the editor ^^
Also, if no icon matches the spell theme, is there a way to add custom icons ?
User avatar
TheLastOrder
Posts: 104
Joined: Wed Oct 17, 2012 1:56 am

Re: Ask a simple question, get a simple answer

Post by TheLastOrder »

What am I doing wrong?

Code: Select all

for i in alcove1:containedItems() do
   weight = weight + i:getWeight()
returns a nil value for containedItems.
If i put alcove1.surface, same thing. :oops:

Thanks in advance!
minmay
Posts: 2770
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

There is no containedItems() method on any object or component in Grimrock 2.
Instead you want the contents() method of SurfaceComponent.

Code: Select all

for i in alcove1.surface:contents() do
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.
User avatar
TheLastOrder
Posts: 104
Joined: Wed Oct 17, 2012 1:56 am

Re: Ask a simple question, get a simple answer

Post by TheLastOrder »

minmay wrote:There is no containedItems() method on any object or component in Grimrock 2.
Instead you want the contents() method of SurfaceComponent.

Code: Select all

for i in alcove1.surface:contents() do
Credited!

:D :D :D
Ixnatifual

Re: Ask a simple question, get a simple answer

Post by Ixnatifual »

How do I setup a default party for a mod? The old method of creating a default_party.dat file from a save and putting it in the mod_assets folder doesn't appear to work for LoG2.
User avatar
TheStoryteller01
Posts: 20
Joined: Wed Dec 31, 2014 3:29 am
Contact:

Re: Ask a simple question, get a simple answer

Post by TheStoryteller01 »

This works fine for the displayed text "Shadow earns 200 XP from the Scholar's Quest"

Code: Select all

hudPrint(party.party:getChampion(1):getName().." earns 200 XP from the Druid's Quest")
Ultimately I would prefer the text to be "DRUID QUEST: Shadow earns 200 XP for discovering a stone circle" but I can't manage to make

Code: Select all

party.party:getChampion(1):getName()..
work inside the " ".

Is this possible at all and if yes, how?
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Ask a simple question, get a simple answer

Post by cameronC »

TheStoryteller01 wrote:This works fine for the displayed text "Shadow earns 200 XP from the Scholar's Quest"

Code: Select all

hudPrint(party.party:getChampion(1):getName().." earns 200 XP from the Druid's Quest")
Ultimately I would prefer the text to be "DRUID QUEST: Shadow earns 200 XP for discovering a stone circle" but I can't manage to make

Code: Select all

party.party:getChampion(1):getName()..
work inside the " ".

Is this possible at all and if yes, how?

Code: Select all

hudPrint("DRUID'S QUEST: "..party.party:getChampion(1):getName().." earns 200 XP for discovering a stone circle.")
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
User avatar
TheStoryteller01
Posts: 20
Joined: Wed Dec 31, 2014 3:29 am
Contact:

Re: Ask a simple question, get a simple answer

Post by TheStoryteller01 »

cameronC wrote:

Code: Select all

hudPrint("DRUID'S QUEST: "..party.party:getChampion(1):getName().." earns 200 XP for discovering a stone circle.")
Tested it and it works perfectly - thanks a lot!
Post Reply

Return to “Mod Creation”