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!
minmay
Posts: 2780
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

if Dungeon.getMaxLevels() == 0 then
to tell whether you're in the character creation screen.
7Soul wrote: Thu Dec 27, 2018 6:10 amAnd worth pointing out this should be put after standard assets and before mod assets
Only if you don't want your hook to be added to the standard assets' items...
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
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Ask a simple question, get a simple answer

Post by 7Soul »

minmay wrote: Thu Dec 27, 2018 6:42 am
7Soul wrote: Thu Dec 27, 2018 6:10 amAnd worth pointing out this should be put after standard assets and before mod assets
Only if you don't want your hook to be added to the standard assets' items...
When I did that it gave me an error "attempting to index 'c' (a boolean value)" or something like that
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Oh, I see. There are a couple of mistakes in the standard assets where non-table values were inadvertently put in component tables. I didn't realize that when I wrote the code.
So here's an augmented version that detects and reports this problem:

Code: Select all

local orig_defineObject = defineObject
local onEquipItemHook = function(self, champion, slot)
	print("asdfasdf")
end
defineObject = function(def)
	if def.components then
		for k,c in pairs(def.components) do
			if type(c) ~= "table" then
				print(string.format("non-table value (%s = %s) encountered in component table for %s",
					tostring(k),tostring(c),tostring(def.name)))
			elseif c.class == "EquipmentItem" then
				c.onEquipItem = onEquipItemHook
			end
		end
	end
	orig_defineObject(def)
end
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
Lorial
Posts: 91
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial »

Hello there.

I require a helping hand concerning some problems I ran into after the release of my mod and I assume this would be easy to fix. It is important to be able to change it ingame using the console since a re-release would render all save games corrupt - not an option anymore at this point.

1) Alchemy:
I forgot to make a custom potion stackable (missing item list entry "stackable = true") which, of course, crashes the game upon creation. Is there a command line I can use ingame to fix that problem? Just to get an idea what I was thinking of:
"custom_potion".go.setStackable()

2) Teleporter Target Destination:
Due to map changes made after a certain teleporter, the party is now teleported to the wrong spot. I already listed a "safe haven" as a workaround when the party is stuck, but in this case the destination is essential to proceed.
Is there a way to change the destination ingame? My idea was to approach the "teleporter" submenu like the "controller" one, but no command seems to work. I can enable or disable the teleporter using teleporter_1.controller:disable(), (or deactivate) but how to change the teleport settings with console commands?
Something along these lines "teleporter_1.teleporter:setTarget (1,2,3,4,5)", but it tells me setTarget is invalid, what else.


3) While I am at it, is there a quick way to kill a specific monster with a console command? "monster_123".monster:destroy() or something.
4) And can I change the baseDamageStat (so the stat scaling of an item) ingame as well? I accidently made dex the scaling stat, but strength is what it should be.

Thank you in advance.
SluisE
Posts: 8
Joined: Fri Nov 30, 2018 4:56 pm

Re: Ask a simple question, get a simple answer

Post by SluisE »

About problem 2: the correct method is setTeleportTarget(level, x, y, elevation).

You can find this and much more information at the modding-page of this site, under 'scripting reference'. It has a lot of useful information 8-)
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Lorial wrote: Sat Dec 29, 2018 12:53 pm I require a helping hand concerning some problems I ran into after the release of my mod and I assume this would be easy to fix. It is important to be able to change it ingame using the console since a re-release would render all save games corrupt - not an option anymore at this point.
1) This will make every "custom_potion" stackable, as long as it's in the game world (not in a champion inventory, not in a container)

Code: Select all

for i = 1, Dungeon.getMaxLevels() do 
    for e in Dungeon.getMap(i):allEntities() do 
        if e.name == "custom_potion" then 
            e.item:setStackable(true) 
            e.item:setStackSize(1) 
        end 
    end 
end 
2)

Code: Select all

teleporter_1.teleporter:setTeleportTarget(starting_location_1.level, starting_location_1.x, starting_location_1.y, starting_location_1.elevation) 
3)

Code: Select all

monster_123.monster:die() 
4)
Can you post the item definition?
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Lorial wrote: Sat Dec 29, 2018 12:53 pm Hello there.

I require a helping hand concerning some problems I ran into after the release of my mod and I assume this would be easy to fix. It is important to be able to change it ingame using the console since a re-release would render all save games corrupt - not an option anymore at this point.

Thank you in advance.
I don't see why releasing an updated version is a problem? Every mod out there has bugs and everyone releases updates for it.
Did you even upload it at https://www.nexusmods.com/legendofgrimrock2 ? Please do, so that everyone (non steam users) can enjoy your mod.

Happy new year and best wishes! :)
User avatar
Lorial
Posts: 91
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial »

SluisE wrote: Mon Dec 31, 2018 3:11 pm About problem 2: the correct method is setTeleportTarget(level, x, y, elevation).

You can find this and much more information at the modding-page of this site, under 'scripting reference'. It has a lot of useful information 8-)
I have been trying to wrap my head around the scripting reference forever, but I hardly ever glued things together properly. To this day I have no clue how to fuel my lantern with oil flasks even though setFuel or something is in there and recharging is a thing in the game...
Zo Kath Ra wrote: Mon Dec 31, 2018 4:09 pm
1) This will make every "custom_potion" stackable, as long as it's in the game world (not in a champion inventory, not in a container)
Via console this does not seem to work, they simply refuse to stack. Unfortunately, the crash occurs when making them, so only editing the potions.lua seems to have any effect.

The monster:die() and teleporter ones work like a charm, thank you so much, guys. Now all the fixes are one paragraph of copy&paste for players of the mod. An easy fix for 40+ hours of fun, seems like a fair deal. :P
Pompidom wrote: Mon Dec 31, 2018 7:27 pm I don't see why releasing an updated version is a problem? Every mod out there has bugs and everyone releases updates for it.
Did you even upload it at https://www.nexusmods.com/legendofgrimrock2 ? Please do, so that everyone (non steam users) can enjoy your mod.

Happy new year and best wishes! :)
Last time I updated the mod, I instantly got reports of software issues by players trying to load their previous save game. Perhaps this is a steam thing, but I did not want to ruin their fun any further. Steam overwrites old versions of subscribed mods by default, so I could not even upload a newer version and leave it to players whether they wanted to update and start over or not. I could of course upload another workshop entry, but now the main fix is a simple copy&paste.
I had not even considered releasing it on Nexusmods to be honest, will look into it tomorrow. :P

Happy new year to you too, guys.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Lorial wrote: Tue Jan 01, 2019 12:37 am I have been trying to wrap my head around the scripting reference forever, but I hardly ever glued things together properly. To this day I have no clue how to fuel my lantern with oil flasks even though setFuel or something is in there and recharging is a thing in the game...
Start with this (if you haven't already): https://github.com/JKos/log2doc/wiki
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

Hello and happy new year to you guys!

I need help with this script please:
I want to open a door whith the party casting a special spell, but I can't figure how to do that correctly.

This is what I tried, based on a script on another thread, but that don't do anything. Linked to a timer, the timer trigger the script each 0.001 sec.

Code: Select all

function darknessSpell()
      onCastSpell = function(party,champion,spellName)
         if spellName == "darkness" then
			hudPrint("Found!")
			darkness_door.door:open()
            return false
         end       
      end
end
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply