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 »

GameObject isn't a Component. GameObject is the container that contains Components. All Components have a "go" field that points to their parent GameObject, but the GameObject does not have a field that points to itself; your hook assumes it does, which it doesn't, so it crashes.
Use

Code: Select all

villageMummy1Lantern:destroy()
Also there should still be an error message, you just aren't seeing it because you aren't running the game from the command line so stdout goes nowhere.
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 »

brzrkr wrote:2. Why does it say that "gameobject" or "go" doesn't exist?
Because it doesn't. All of the gameobject methods are accessible as object:method()

Code: Select all

 Try this in the hook:

function smotherLantern(monsta)
	print(monsta.go.id, unpack{monsta.go:getPosition()})
	for monster in monsta.go.map:entitiesAt(monsta.go.x, monsta.go.y) do
	
		if monster.monster and not monster.go then  -- notice that the condition FAILS if there is a value for monster.go
		
			print(monster.id, unpack{monster:getPosition()})   -- notice that this is not monster.go.id
		end
	end

end
The .go field is used when accessing the script object; which is generally the first argument passed to your function. In function(self), self.go.id gives the id of the script. [monsta is the script, and needs to be monsta.go.id]
And the wall lantern has that same exact ID.
No two objects [existing concurrently] on the map should have the exact same id. That will crash it.
[Except in the dangerous case where of one of them is in a container on the map].
How am I supposed to destroy the lantern or disable one of its components when the monster dies, if this is not the correct way?
If its id is 'Lantern' then the way is: Lantern:destroy()
3. About the commented part, since the dying monster's ID is villageMummy, I was wondering if I could take his id, append "Lantern" to it in a string (thus creating the lantern's ID), and then use the string variable as if it were the lantern ID itself, to destroy the lantern directly. If not, how can I turn that string into the actual lantern entity?
.
You could set it up this way by manually naming the objects. When you have a concatenated string and need to use it as an ID, use the function findEntity() in place of the id, and pass to it the string.
Examples:

findEntity("my_object_1"):destroy()

local obj = "my_object_"..x --where x == 1
findEntity(obj):destroy()

Know that findEntity will return nil, if it cannot find the object ~that can crash your script if unexpected. So if there is a chance of it returning nil, you can first check that it's not nil.
Example:
if findEntity("my_object_1") then findEntity("my_object_1"):destroy() end
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

How can a condition manipulate a champions cool down?
It's definitely possible because there's a condition that does that already. (Haste)
I've added this to the conditions definition but it did nothing:

Code: Select all

	onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if level > 0 then return 90 end
	end,
My asset pack [v1.10]
Features a bit of everything! :D
brzrkr
Posts: 11
Joined: Wed Aug 10, 2016 4:05 pm

Re: Ask a simple question, get a simple answer

Post by brzrkr »

Riight. I expected it to be something so stupid that I overlooked it. I'm even more stupid than it.

Thank you for the tips also.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

zimberzimber wrote:How can a condition manipulate a champions cool down?
It's definitely possible because there's a condition that does that already. (Haste)
I've added this to the conditions definition but it did nothing:

Code: Select all

	onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if level > 0 then return 90 end
	end,
The builtin conditions don't really work like custom conditions. Anyway, there's no onComputeCooldown hook for conditions, only skills and traits. You'll need to add a trait to all champions that checks for the presence of your custom condition.
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
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

minmay wrote:The builtin conditions don't really work like custom conditions. Anyway, there's no onComputeCooldown hook for conditions, only skills and traits. You'll need to add a trait to all champions that checks for the presence of your custom condition.
Into the hidden mother-of-all-not-simply-added-stats trait it goes :D
My asset pack [v1.10]
Features a bit of everything! :D
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 »

AndakRainor wrote:How do I get the height of a monster ?
The elevation? [-7 to 6?]
monster.elevation
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

MonsterComponent:getCapsuleHeight()
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
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

I tried MonsterComponent:getCapsuleHeight(), and used the value in world coordinates. It appears to be very low, near the ground. I am trying to set a good starting position for a particle effect moving from the "center" of a monster to the party (for the drain life spell).

Currently I am using monster:getCapsuleHeight() + monster:getCapsuleRadius()/2, it feels ok, I tested if in the arena of orrr3, but it was still a little too low for the mosquitos!
Post Reply