Page 5 of 10

Re: Scripting Reference (work in progress)

Posted: Mon Nov 03, 2014 10:07 pm
by Blichew
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)

Posted: Mon Nov 03, 2014 10:20 pm
by NutJob
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 :)
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"

Re: Scripting Reference (work in progress)

Posted: Mon Nov 03, 2014 10:28 pm
by NutJob
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. ;)
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.

It's pretty easy if you follow these 18 steps:

1) Remove all th

Re: Scripting Reference (work in progress)

Posted: Tue Nov 04, 2014 12:29 am
by JohnWordsworth
@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...

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
Similarly, you can hook into the party component's hooks (all apart from the GUI ones I think) by doing the following...

Code: Select all

party.party:addConnector("onMove", self.go.id, "partyMove");

function partyMove()
  print("Party Moved")
end
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!

Re: Scripting Reference (work in progress)

Posted: Tue Nov 04, 2014 12:53 am
by Blichew
JohnWordsworth wrote:
Similarly, you can hook into the party component's hooks (all apart from the GUI ones I think) by doing the following...

Code: Select all

party.party:addConnector("onMove", self.go.id, "partyMove");

function partyMove()
  print("Party Moved")
end
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!
So it's possible to spawn onUseItem for one specific (let's say) potion_of_bear that on use can do something different ?

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 ?

Re: Scripting Reference (work in progress)

Posted: Tue Nov 04, 2014 12:59 am
by JohnWordsworth
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).

Re: Scripting Reference (work in progress)

Posted: Tue Nov 04, 2014 1:25 am
by Blichew
Well, I guess we cannot add new components via script. I've tried:

Code: Select all

rock_1:addComponent(usableitem)
and

Code: Select all

rock_1.usableItem:enable()
unless you mean overriding createObject (or cloneObject) from script_entity, not (as usual) from within mon_assets

Re: Scripting Reference (work in progress)

Posted: Tue Nov 04, 2014 8:41 am
by JohnWordsworth
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.

Re: Scripting Reference (work in progress)

Posted: Tue Nov 04, 2014 9:20 am
by Blichew
And how did I not see this :oops: ? I was just reading posts to catch up faster, not the code... :) Thanks for that !

: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
Clicking this item in hand triggers throw (which is completly normal) while clicking this in inventory gives this error:
Image

Re: Scripting Reference (work in progress)

Posted: Tue Nov 04, 2014 10:17 am
by JohnWordsworth
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!

Code: Select all

rock_1.usableitem:addConnector("onUseItem",self.go.id,"useRock")
Hope this helps! :)