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
Slade
Posts: 36
Joined: Tue Oct 21, 2014 6:31 pm

Re: Ask a simple question, get a simple answer

Post by Slade » Fri Dec 26, 2014 8:50 pm

minmay wrote:Check the box that says "disableSelf".
Thanks, god damn i feel stupid :lol:

cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Ask a simple question, get a simple answer

Post by cameronC » Sat Dec 27, 2014 6:33 pm

I don't suppose anyone has an answer/work around to get addConnector to work with item hooks yet?
(Related to this thread and some others...)
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Ask a simple question, get a simple answer

Post by NutJob » Sat Dec 27, 2014 9:29 pm

cameronC wrote:I don't suppose anyone has an answer/work around to get addConnector to work with item hooks yet?
(Related to this thread and some others...)
I haven't seen an update yet to the software so I don't think we can yet. It was my primary reason to set LoG2 coding aside and just lurk around the forums.

minmay
Posts: 2689
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Sun Dec 28, 2014 12:06 am

What? Of course there is a workaround, you have scripting access to all the hooks that connectors do. In fact, all of the work has already been done for you, over a month ago.
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.

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Ask a simple question, get a simple answer

Post by NutJob » Sun Dec 28, 2014 12:48 am

minmay wrote:What? Of course there is a workaround, you have scripting access to all the hooks that connectors do. In fact, all of the work has already been done for you, over a month ago.
So you can make this work...

Code: Select all

function myTestSpawn()
   local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation)
   o.item:addConnector("onEquipItem", "lib", "aaa")
   o.item:addConnector("onUnequipItem", "lib", "bbb")
end

function aaa()
   print("A")
end

function bbb()
   print("B")
end

...without an error?

minmay
Posts: 2689
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Sun Dec 28, 2014 1:56 am

NutJob wrote:
minmay wrote:What? Of course there is a workaround, you have scripting access to all the hooks that connectors do. In fact, all of the work has already been done for you, over a month ago.
So you can make this work...

Code: Select all

function myTestSpawn()
   local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation)
   o.item:addConnector("onEquipItem", "lib", "aaa")
   o.item:addConnector("onUnequipItem", "lib", "bbb")
end

function aaa()
   print("A")
end

function bbb()
   print("B")
end

...without an error?
Well, you cannot overwrite the native addConnector method as far as I know, so you can't use that exact code. You would use something like this:

Code: Select all

function myTestSpawn()
   local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation)
   fw.script:set(o.id..'@item.whateverNamespaceYouWant.onEquipItem',aaa)
  fw.script:set(o.id..'@item.whateverNamespaceYouWant.onUnequipItem',bbb)
end

function aaa()
   print("A")
end

function bbb()
   print("B")
end
Also if the hook framework works similarly to how it does in LoG1 (I haven't tested) function ownership will change from this script component to the fw script if the game is saved and reloaded, so you need to account for that (only reference the global environment in the function).
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.

instablemonster
Posts: 2
Joined: Sun Dec 28, 2014 6:48 am

Re: Ask a simple question, get a simple answer

Post by instablemonster » Sun Dec 28, 2014 8:16 am

How do I put a delay in between the activate and deactivate ?

Code: Select all

function teleporterrotation()
	teleporter_13.controller:activate() 
	teleporter_13.controller:deactivate()
end

minmay
Posts: 2689
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Sun Dec 28, 2014 8:37 am

Since the teleporter object has a ControllerComponent named "controller", you can use the global delayedCall function:

Code: Select all

function teleporterrotation()
   teleporter_13.controller:activate()
  delayedCall("teleporter_13",1.5,"deactivate")
end
to deactivate the teleporter after 1.5 seconds.
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.

instablemonster
Posts: 2
Joined: Sun Dec 28, 2014 6:48 am

Re: Ask a simple question, get a simple answer

Post by instablemonster » Sun Dec 28, 2014 9:03 am

minmay wrote:Since the teleporter object has a ControllerComponent named "controller", you can use the global delayedCall function:

Code: Select all

function teleporterrotation()
   teleporter_13.controller:activate()
  delayedCall("teleporter_13",1.5,"deactivate")
end
to deactivate the teleporter after 1.5 seconds.
Thank you !

User avatar
Mentok
Posts: 5
Joined: Sat Dec 27, 2014 6:34 am

Re: Ask a simple question, get a simple answer

Post by Mentok » Sun Dec 28, 2014 10:53 am

Here's a simple question: I was trying to use setAiState to shift a monster from guard to its default ai state, but I really have no idea what i'm doing. Any help would be greatly appreciated. :D

Post Reply