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!
User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 » Sat Aug 31, 2019 1:47 pm

Lorial wrote:
Sat Aug 31, 2019 12:42 pm
If I equip the last item of a custom armor set, it seems to spam the message/sound every frame.
Is there a way to get the message/sound only once? Would adding/removing a trait for that be the better choice?

Code: Select all

		{
			class = "EquipmentItem",
			protection = 2,
			evasion = 3,
			onRecomputeStats = function(self, champion)
				if champion:isArmorSetEquipped("tattered") then
--				hudPrint(champion:getName().." is now wearing the full Tattered Set.")
					champion:addStatModifier("protection", 2)
					champion:addStatModifier("evasion", 4)
				end
			end,
The fx are spamming because everything's onRecomputeStat hook is called every frame (60fps)
At a glance, Id say run your code from onEquipItem and onUnequipItem hooks
Those hooks are called whenever you un/equip, not every frame
One thing I noticed, though, the spelling must be that of the trait id, not the name displayed in the traits window (Meditation - meditation). Gets a bit ugly when it hudPrints "X loses the improved_dual_wield trait". When changing to a capital "M", it doesn't work anymore, the trait won't get removed.
Thanks for the reminder!! :D

User avatar
Isaac
Posts: 2995
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac » Sat Aug 31, 2019 6:31 pm

Lua is case sensitive. You must make the changes to the id string for hudPrint.

Example:

Code: Select all

traitId = "meditation"

function capitalize(idString)
	return string.upper(idString:sub(1,1))..idString:sub(-(#idString-1))
end

hudPrint(capitalize(traitId))

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 » Sun Sep 01, 2019 5:15 am

Isaac wrote:
Sat Aug 31, 2019 6:31 pm
Lua is case sensitive. You must make the changes to the id string for hudPrint.

Example:

Code: Select all

traitId = "meditation"

function capitalize(idString)
	return string.upper(idString:sub(1,1))..idString:sub(-(#idString-1))
end

hudPrint(capitalize(traitId))
Ah, thanks Isaac ;)

User avatar
Lorial
Posts: 79
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial » Sun Sep 01, 2019 7:54 pm

Somehow i cannot get this armor set thing to work properly. With onRecomputeStats it at least granted me the bonus when all parts were in their respective slot. Now nothing seems to have an effect anymore. What am I missing here?!

SpoilerShow

Code: Select all

		{
			class = "Item",
			uiName = "Plate Cuirass",
			armorSet = "plate",
			armorSetPieces = 5,
			gfxIndex = 91,
			weight = 16.0,
			traits = { "heavy_armor", "chest_armor" },
		},
		{
			class = "EquipmentItem",
			protection = 12,
			onEquipItem = function(self, champion, slot)
				if slot == 4 and
				champion:isArmorSetEquipped("plate") then
				hudPrint(champion:getName().." is now wearing the full Plate set.")
					champion:addStatModifier("protection", 5)
					champion:addStatModifier("evasion", 3)
					champion:addStatModifier("max_load", 15)
				end
			end,
		},

User avatar
Willigamer
Posts: 12
Joined: Sat Jan 07, 2017 6:06 pm
Contact:

Re: Ask a simple question, get a simple answer

Post by Willigamer » Tue Sep 03, 2019 11:42 am

Lorial wrote:
Sun Sep 01, 2019 7:54 pm
Somehow i cannot get this armor set thing to work properly. With onRecomputeStats it at least granted me the bonus when all parts were in their respective slot. Now nothing seems to have an effect anymore. What am I missing here?!

SpoilerShow

Code: Select all

		{
			class = "Item",
			uiName = "Plate Cuirass",
			armorSet = "plate",
			armorSetPieces = 5,
			gfxIndex = 91,
			weight = 16.0,
			traits = { "heavy_armor", "chest_armor" },
		},
		{
			class = "EquipmentItem",
			protection = 12,
			onEquipItem = function(self, champion, slot)
				if slot == 4 and
				champion:isArmorSetEquipped("plate") then
				hudPrint(champion:getName().." is now wearing the full Plate set.")
					champion:addStatModifier("protection", 5)
					champion:addStatModifier("evasion", 3)
					champion:addStatModifier("max_load", 15)
				end
			end,
		},
Well... just because you can’t use the hook "onEquipItem" in a "EquipmentItem" class. If you want to use the "onEquipItem" hook, it must be placed in the "item" class. The only memory hook that can be passed in "EquipmentItem" is "onRecomputeStats" ;)
Last edited by Willigamer on Tue Sep 03, 2019 3:30 pm, edited 1 time in total.
"Always become the one you are, be the master and the sculptor of yourself"
My LoG2 Mods :
  • Legend of Island : Coming Soon
  • Sanctuary Antique : One day maybe...

Pompidom
Posts: 486
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom » Tue Sep 03, 2019 12:27 pm

Code: Select all

function opengates(surface, item)
	for _,i in surface:contents() do
		if i.go.name == item then 
			i.go:destroy()		
			return true 
		end
	end
end

function waterta(alcove)
	if opengates(hunger_ledge_alcove_28.surface, "note") then
		counter_34.counter:decrement()	
    end
end
This surface will now accept any note,
How do i change it so it only accepts "note_2"

User avatar
Isaac
Posts: 2995
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac » Tue Sep 03, 2019 1:18 pm

Pompidom wrote:
Tue Sep 03, 2019 12:27 pm
How do i change it so it only accepts "note_2"
It has to be done with an in-definition hook if it is to conditionally refuse the inserted item.
Regular user scripts cannot cancel events.

Code: Select all

defineObject{
	name = "dungeon_alcove_note",
	baseObject = "dungeon_alcove",
	components = {
		{
			class = "Surface",
			offset = vec(0, 0.85, 0.2),
			size = vec(1.3, 0.65),
			onAcceptItem = function(self, item) return item.go.id == "note_2" end,
		},
	},
}

--Alternate version

defineObject{
	name = "dungeon_alcove_note_with_msg",
	baseObject = "dungeon_alcove",
	components = {
		{
			class = "Surface",
			offset = vec(0, 0.85, 0.2),
			size = vec(1.3, 0.65),
			onAcceptItem = function(self, item) 
								if (item.go.id == "note_2") then return true
								 else hudPrint("Wrong Item") self.go:spawn("teleportation_effect") --or any failure state behavior 	
									  return false	
								end	
							end	
		},
	},
}
*Updated script for typo...

**Edit:
If you would like to have control over the event in a script_entity, the way to do it is to return that script_entity function's boolean return value from the surface hook. That way your condition(s) can be in a script_entity on the map, and still cancel the event. This option affords access to external script variables and other functions that could be used in the conditional logic.
eg.

Code: Select all

onAcceptItem = function(self, item) return script_entity_1.script.checkItemId(item) end
--where  checkItemId() returns true or false

Pompidom
Posts: 486
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom » Tue Sep 03, 2019 5:00 pm

Yes, just any simple script that checks for the exact itemID instead of the general's object name.

But you've just given me an idea how to deal with something entirely different as well.

User avatar
Lorial
Posts: 79
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial » Wed Sep 04, 2019 6:19 am

Willigamer wrote:
Tue Sep 03, 2019 11:42 am
Well... just because you can’t use the hook "onEquipItem" in a "EquipmentItem" class. If you want to use the "onEquipItem" hook, it must be placed in the "item" class. The only memory hook that can be passed in "EquipmentItem" is "onRecomputeStats" ;)
Wow, I do need vacation urgently. Thanks a bunch, Willigamer.

Pompidom
Posts: 486
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom » Wed Sep 04, 2019 9:03 pm

Exits and entrances. Are there any out there with a custom destination target?
Or is there any other way to get the "walk slowdown" fade out/fade in transmission.

I want to stack 4 basic_exit_no_model on the same square for a multi portal like the multi portal in arx fatalis. and only 1 exit is activated at the same time depending from which direction you go through in combination with invisible floor_triggers.

https://youtu.be/YulDbORSj6w

The portal needs to be activated by power gems, currently the portals are flickering because they are not activated yet.

I was also toying with the idea to create a portal like stargate, where you have a rune button panel to dial in the coordinates. And then like the upside down map video I posted it will activate the models to show a reflection of the location you will go to through the portal.

Post Reply