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
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

zimberzimber wrote:

Code: Select all

onInit = function(self)
				spawn("script_entity", 1, 0, 0, 0, 0, "id_for_this_object_for_future_reference").script:loadFile("mod_assets/external_scripts/my_external_script.lua")
				self.go:destroy()
			end
The object spawn code could include a check for the ID it's about to use; to avoid potential ID collisions with other objects. The ID string itself could also be made rather complex, to further reduce the chance of a another script with that same ID existing in a mod that has included it. While both of these might be overly cautious, the spawn function can currently crash the game [for duplicate entity] if there is already an object on the map with the same name.
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 »

Isaac wrote:The object spawn code could include a check for the ID it's about to use; to avoid potential ID collisions with other objects. The ID string itself could also be made rather complex, to further reduce the chance of a another script with that same ID existing in a mod that has included it. While both of these might be overly cautious, the spawn function can currently crash the game [for duplicate entity] if there is already a script on the map with the same name.
Right, forgot to include it...
Worst of all, forgot to include it in my asset pack :oops:
My asset pack [v1.10]
Features a bit of everything! :D
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

Hello, another quick question.

Consumable items when in hands are used via attack action which triggers the onAttackHook.

So as long as I can identify the item, I can work with it and see if the character is eating or using a potion.

But when the item is consumed in the inventory it does not trigger the onAttackHook and I am not seeing it trigger any hook.

Is there any hook that it triggers?
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 »

PedroMoniz wrote:Hello, another quick question.

Consumable items when in hands are used via attack action which triggers the onAttackHook.

So as long as I can identify the item, I can work with it and see if the character is eating or using a potion.

But when the item is consumed in the inventory it does not trigger the onAttackHook and I am not seeing it trigger any hook.

Is there any hook that it triggers?
The UsableItem component has an onUseItem hook that receives (self, champion).
This hook is also called when the item is consumed from the hero panel.
Bonus: If you return false, the item will not be consumed
Here's an example:

Code: Select all

class = "UsableItem",
onUseItem = function(self, champion)
	playSound("consume_potion")
	hudPrint("The flask is full of water again!")
	return false
end,
My asset pack [v1.10]
Features a bit of everything! :D
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

Thank you,

did not see there are a usable item component.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

PedroMoniz wrote:Thank you,
did not see there are a usable item component.
There is also a second [more up to date] scripting reference for Grimrock 2.
https://github.com/JKos/log2doc/wiki
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

When a monster dies, it explodes in a shower of sparks.
I want a forest_old_oak to explode like this.
Other than making a monster that looks just like a forest_old_oak, is there a way to do this?
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Code: Select all

do
  local p = forest_old_oak_1:spawn("particle_system")
  p.particle:setParticleSystem("death")
  p.particle:setEmitterMesh(forest_old_oak_1.model:getModel())
  local l = p:createComponent("Light")
  l:setRange(4)
  l:setColor(vec(0.6078431372549,0.4,0.27058823529412))
  l:setOffset(vec(0,1.5,0))
  l:setBrightness(40)
  l:setFadeOut(1)
  forest_old_oak_1:destroy()
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
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Yes, but it has to have the sound effects too! :twisted:

Updated.
Last edited by Isaac on Tue Jan 31, 2017 4:58 am, edited 1 time in total.
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Ask a simple question, get a simple answer

Post by Grimfan »

I have a rough idea of how sequencing is used to open up pits or activate spikes in a specific order with timers or counters, but what about player activated objects like buttons? Can the same sort of code be used to press buttons in a specific order or is it a little more convoluted than that? I know I could achieve the same results with levers or pressure_plates with potentially less hassle but I don't want to overuse either in my mod.
Post Reply