
Scripting Reference (work in progress)
Re: Scripting Reference (work in progress)
John, JKoss, can you provide one example of this ? I'm not sure i understand it correctly. Working part of script would be great to test and then reverse-engineer 

Re: Scripting Reference (work in progress)
If you used connectors in your dungeon already (floor trigger closing a door, a lever executing a script, etc) you can open dungeon.lua and there will be a lot of examples of use there. Search/find "addConnector"Blichew wrote:John, JKoss, can you provide one example of this ? I'm not sure i understand it correctly. Working part of script would be great to test and then reverse-engineer
Re: Scripting Reference (work in progress)
I was able to make my own custom event (onTeleport) and got it working, finally. It processes that force field flash effect to simulate the way is barred.Grimfan wrote:I wouldn't be too sure of that NutJob. You won't get a response from me but I bet Prozail or JKos might have a crack at answering your query if they feel inclined.
It's pretty easy if you follow these 18 steps:
1) Remove all th
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Scripting Reference (work in progress)
@Bilchew: Not on my windows PC at the moment, so I cannot test this to ensure it's 100% correct, but you should be able to do something like this within a script component to add a timer to that same game object and hook up the timer's activate method to a method in the script...
Similarly, you can hook into the party component's hooks (all apart from the GUI ones I think) by doing the following...
There are a couple of restrictions with the connectors. There doesn't appear to be a way to remove them once you have added them, so if you do add them - you need to either make sure that you will destroy the thing emitting the messages before you destroy the thing receiving them (otherwise you will get loads of warnings in the console). As JKos stated, it's also not possible to provide any feedback using this method. Which makes sense I guess - as I presume the order of connectors being fired is not strictly-required to always be the same (??) so connectors are more like "observers" as opposed to "delegates" provided in the object definition.
Hope this helps!
Code: Select all
self.go.createComponent("Timer");
self.go.timer:addConnector("onActivate", self.go.id, "timerTick");
self.go.timer:setTimerInterval(0.5);
self.go.timer:start();
function timerTick()
print("TICK!");
end
Code: Select all
party.party:addConnector("onMove", self.go.id, "partyMove");
function partyMove()
print("Party Moved")
end
Hope this helps!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Re: Scripting Reference (work in progress)
So it's possible to spawn onUseItem for one specific (let's say) potion_of_bear that on use can do something different ?JohnWordsworth wrote:
Similarly, you can hook into the party component's hooks (all apart from the GUI ones I think) by doing the following...
There are a couple of restrictions with the connectors. There doesn't appear to be a way to remove them once you have added them, so if you do add them - you need to either make sure that you will destroy the thing emitting the messages before you destroy the thing receiving them (otherwise you will get loads of warnings in the console). As JKos stated, it's also not possible to provide any feedback using this method. Which makes sense I guess - as I presume the order of connectors being fired is not strictly-required to always be the same (??) so connectors are more like "observers" as opposed to "delegates" provided in the object definition.Code: Select all
party.party:addConnector("onMove", self.go.id, "partyMove"); function partyMove() print("Party Moved") end
Hope this helps!
This one would be too good to be true - I cannot add non-existent hook/connector ? Like add onUseItem to rock item which (probably) doesn't have any onUseItem effects defined ?
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Scripting Reference (work in progress)
I haven't tested it with that many hooks yet, but assuming they all work the same (apart from the GUI ones, which I might guess don't work as expected because maybe the connector system isn't really designed to be called every frame), then I think you can add a hook to any item that has a component of a given class (you could even add a component to that object dynamically).
So, you could take the generic "Water Flask" item, and when you create a new instance of it, you could add one "drink potion" hook from a list of functions you have written - to make potions that have random effects say. Equally, I imagine you could spawn a rock, and then add a special effect that kicks in when you throw it by adding a connector to the item's "ItemActionComponent.onAttack(self, champion, slot, chainIndex)" hook. This is all hypothetical, as I've not tried it an I'm still not on the right computer to do so! In both cases, the new effect you have added will only occur on that specific item (not all rocks).
So, you could take the generic "Water Flask" item, and when you create a new instance of it, you could add one "drink potion" hook from a list of functions you have written - to make potions that have random effects say. Equally, I imagine you could spawn a rock, and then add a special effect that kicks in when you throw it by adding a connector to the item's "ItemActionComponent.onAttack(self, champion, slot, chainIndex)" hook. This is all hypothetical, as I've not tried it an I'm still not on the right computer to do so! In both cases, the new effect you have added will only occur on that specific item (not all rocks).
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Re: Scripting Reference (work in progress)
Well, I guess we cannot add new components via script. I've tried:
and
unless you mean overriding createObject (or cloneObject) from script_entity, not (as usual) from within mon_assets
Code: Select all
rock_1:addComponent(usableitem)
Code: Select all
rock_1.usableItem:enable()
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Scripting Reference (work in progress)
Check my first post on this page - where I create a timer component on the current script entity! It's "createComponent", which you must call on the game object. You also have to use a capital letter for the first character in the component name.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Re: Scripting Reference (work in progress)
And how did I not see this
? I was just reading posts to catch up faster, not the code...
Thanks for that !
:EDIT:
I'm still doing something wrong:
Clicking this item in hand triggers throw (which is completly normal) while clicking this in inventory gives this error:



:EDIT:
I'm still doing something wrong:
Code: Select all
rock_1:createComponent("UsableItem")
rock_1.usableitem:addConnector("onUseItem",self.go.id,"useRock()")
function useRock()
hudPrint("rock_1 just got used !!")
end

- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Scripting Reference (work in progress)
No need for the braces in the last parameter passed to the addConnector method. Also, I'm not 100% sure what happens when you right click a "Usable" and a throwable item when it is in your hands... But I'll leave you to experiment with that!
Hope this helps! 
Code: Select all
rock_1.usableitem:addConnector("onUseItem",self.go.id,"useRock")

My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.