Page 186 of 395

Re: Ask a simple question, get a simple answer

Posted: Sun Jan 29, 2017 4:24 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Sun Jan 29, 2017 5:00 pm
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:

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 30, 2017 2:29 pm
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?

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 30, 2017 2:46 pm
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,

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 30, 2017 3:40 pm
by PedroMoniz
Thank you,

did not see there are a usable item component.

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 30, 2017 4:42 pm
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

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 30, 2017 11:21 pm
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?

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 30, 2017 11:56 pm
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

Re: Ask a simple question, get a simple answer

Posted: Tue Jan 31, 2017 4:22 am
by Isaac
Yes, but it has to have the sound effects too! :twisted:

Updated.

Re: Ask a simple question, get a simple answer

Posted: Tue Jan 31, 2017 4:28 am
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.