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 »

THOM wrote:I've erased all additions I made to the party-object - no result.
You may think you've removed all the other party definitions, but I can almost guarantee that you haven't. If you had, then that hook would be called.
Are you importing assets/scripts/objects/generic.lua after defining the party? Because it will overwrite the party definition. Importing GrimTK? Overwrites the PartyComponent, so it will remove all your hooks. Using Skuggasveinn's winter tileset without fixing it first? It overwrites the entire party definition (for no reason!) too.
Have you done a grep for "party" in your entire dungeon folder, or shadowed defineObject() to print a special message when it encounters a definition named "party"? If not, then you shouldn't assume that you aren't redefining the party object somewhere else.

Just FYI, the hook function posted doesn't really accomplish the intended result - it gets the damage totally wrong, gets the damage type wrong if the champion is wearing an item with the "fire_gauntlets" trait, attacks HealthComponents that the party shouldn't be able to attack because they're blocked by a door, doesn't check the elevation of the HealthComponent so it can do a bunch of damage to monsters if the party's elevation doesn't match the HealthComponent's, and PartyComponent.onAttack doesn't get called for unarmed attacks at all so it won't detect those. It also probably "hits" the wrong square sometimes even when the elevations match.
There are many other possible problems with this approach as well; you should really temporarily remove the physical immunity instead of trying to use damageTile.
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
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:Have you done a grep for "party" in your entire dungeon folder, or shadowed defineObject() to print a special message when it encounters a definition named "party"?
Wouldn't searching for 'Party' be better?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Isaac wrote:
minmay wrote:Have you done a grep for "party" in your entire dungeon folder, or shadowed defineObject() to print a special message when it encounters a definition named "party"?
Wouldn't searching for 'Party' be better?
A defineObject() call that overwrites the entire party object is likely. As I mentioned, one exists in generic.lua (since it is the original party definition) and there's another one in The Winter Tileset. Anything that overwrites the PartyComponent will be part of a "party" definition so it will still be caught, though you could do a case-insensitive grep if you really need to see it twice.
Of course this still won't catch something silly like defineObject{name="p".."a".."r".."t".."y" [...]} but I doubt THOM has done anything like that.
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
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

minmay wrote: Of course this still won't catch something silly like defineObject{name="p".."a".."r".."t".."y" [...]} but I doubt THOM has done anything like that.
I'm very relieved that you believe in me.... :mrgreen:

Actually it was GrimTK that blocked my onAttack hook. I've moved the script into the GrimTK party-object and now it works. :idea: Thank you Eburt for the code.

Concerning the doubts you mentioned, minmay: most of these circumstances can not become true in my case. I've also added a query and now the code only gets executed in case one specific object is attacked by the party. I hope that breaks the remaining possibilities.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
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 »

I try to import files with a prefix path variable this way:

Code: Select all

path = "mod_assets/spells_pack/"
import path.."items/shaman_staff.lua" -- earth +20%
But it does not work. Using this prefix anywhere in the code works, but not with import. What am I doing wrong? Is it impossible?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Unfortunately the import keyword only works with string literals, so you can't do that.

edit: I'm dumb
Last edited by minmay on Fri Sep 16, 2016 2:45 am, edited 1 time in total.
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
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Just encase the the entire string in parenthesis, like this:

Code: Select all

path = "mod_assets/spells_pack/"
import (path.."items/shaman_staff.lua") -- earth +20%
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 »

hey there,

I've got trouble with a custom spiketrap: I wanted a spiketrap to automatically activate itself, so I didn't had to use any trigger to activate the trap. I've added a floor_trigger component in the object definition, the trap activate itself when the party goes on but when when the party leave the trap the preview crashes and the editor gives me a warning message:
Image

the object definition
SpoilerShow

Code: Select all

defineObject{
	name = "floor_spike_trap_auto",
	baseObject = "base_floor_decoration",
	components = {
		{
			class = "Model",
			model = "assets/models/env/tomb_floor_spiketrap.fbx",
		},
		{
			class = "FloorTrigger",
			onActivate = function(self)
				self.go.animation:play("activate")
				self.go.tiledamager:enable()
			end,
		},
		{
			class = "Animation",
			animations = {
				activate = "assets/animations/env/tomb_floor_spiketrap_hit.fbx",
			},
		},
		{
			class = "TileDamager",
			attackPower = 50,
 			damageType = "physical",	-- TODO: change to "pure"
 			screenEffect = "damage_screen",
 			cameraShake = true,
			sound = "spike_trap",
			floorTrap = true,
			enabled = false,
			onHitObstacle = function(self, obstacle)
				if obstacle.go.name == "beach_thicket_01" then return false end
			end,
			onHitMonster = function(self, monster)
				if monster.go.name == "air_elemental" then return false end
			end,
		},
		{
			class = "Controller",
			onActivate = function(self)
				self.go.animation:play("activate")
				self.go.tiledamager:enable()
			end,
		},
	},
	editorIcon = 284,
}
any idea please?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
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 »

I did not test it, but it seems you are missing a definition for onDeactivate and a default one is messing with your animations.
Post Reply