Page 1 of 1
Triggering a script by using an item?
PostPosted: Fri Mar 03, 2017 8:13 pm
by tegstewart
Is there any way to tie a script to an item being used in the DB?
For instance, if somebody used their bind stone, could it fire a script that gives a list of places to teleport to and casts a spell to move them there?
That's not what I was going to use for, but now that I've come up with an easy example I kinda want to do that as well.
Thanks!
Re: Triggering a script by using an item?
PostPosted: Fri Mar 03, 2017 9:54 pm
by ontheDOL
there definitely is a way

Storm d2 has many items that trigger scripts
i'm also interested in possibly seeing an example script to work from, but havent got around to looking.
Neon pvp scripts in user files might have something of use for you, though the code might be outdated.
sorry i cant help more
Re: Triggering a script by using an item?
PostPosted: Sat Mar 04, 2017 12:21 am
by tegstewart
Hmm. Now I'm curious. I can think of all kinds of useful stuff I could stick in a custom base skill tree available to everybody. It would be a lot more elegant than hauling around a bunch of items.
Re: Triggering a script by using an item?
PostPosted: Sat Mar 04, 2017 1:47 am
by PlanarChaosRvrtwo
its not that nice but you could work around the script and create generetic inventory item or such that have an spell like spiritmaster pet bit modified and is loading teleport npctemplate or something.
Re: Triggering a script by using an item?
PostPosted: Sat Mar 04, 2017 7:25 am
by Leodagan
Whenever a player try to activate any inventory Item we have an event fired :
In GamePlayer.cs (UseSlot() around line 8900)
- Code: Select all
// notify event handlers about used slot
Notify(GamePlayerEvent.UseSlot, this, new UseSlotEventArgs(slot, type));
If you listen to these events, and add a specific script in gameserverscript, you can then filter events to your own flavor (Get Player inventory item from used slot, then check if inventory item is the Name or Id_Nb you want to target, then do anything you want !)
Be careful this event could be silenced if the item has any "real use event" (when it triggers a spell or a switch the method exits before notify...)
Re: Triggering a script by using an item?
PostPosted: Sat Mar 04, 2017 11:31 am
by Dinberg
Be careful this event could be silenced if the item has any "real use event" (when it triggers a spell or a switch the method exits before notify...)
This behaviour sounds unintended and possibly a bug. Can you think of any scenarios where a player would /use an item where we don't want the notify to be called?
Re: Triggering a script by using an item?
PostPosted: Sat Mar 04, 2017 12:17 pm
by Leodagan
Yeah probably when it's already handled by "hardcoded" methods, Weapon Switch, Quiver Use, Mount Call...
It may have been a choice to not fire the slot use event if the gameserver handle this specific case himself and don't want other method to interfere...
Typically this kind of events should have multiple "state event", the UseSlot() Method is huge and there is no distinction to fire "inventory switch event" or "item spell fired event", there should also be some specific "Before Use Slot Event" to allow some scripts to act
before the game server code and maybe even stop him completely...
It's not only this behavior that sounds unintended it's more GamePlayer class being completely bloated, further customization should rely on subclassing GamePlayer class and overriding this kind of Method, or implementing InventoryItem Subclass that trigger custom script when virtual method are called (OnEquip() etc...) matching the actual UseSlot() behavior

Re: Triggering a script by using an item?
PostPosted: Sat Mar 04, 2017 5:14 pm
by tegstewart
its not that nice but you could work around the script and create generetic inventory item or such that have an spell like spiritmaster pet bit modified and is loading teleport npctemplate or something.
That actually works perfectly for the teleport, since almost everybody would have a custom pet anyway. That pet is going to also be your teleporter. Very slick.
It doesn't help with having a huge list of summonable pets, though. I think I'll do a separate thread for that specific problem.
Thanks!
Re: Triggering a script by using an item?
PostPosted: Sat Mar 04, 2017 8:58 pm
by PlanarChaosRvrtwo
Would be nice if you could give us an list of custom content you want add and we see then how and who can help you with what
(i leaded the server realm of darkness over an year and added lot of custom stuff without the ability to script biggest work is allways to use the db proper couse the db allready can do very crazy things if you know what to combine with what to make it work)
Re: Triggering a script by using an item?
PostPosted: Sun Mar 05, 2017 4:32 pm
by tegstewart
We talked about this in chat, but for everybody else...
I run a local server I use to do PVE on my own. I'm adding content to make that more enjoyable. In this case, I settled on adding a base line spell every class gets called Utility. It gives things like the top tier skald run speed chant at level 1, the personal bind stone spell with the recast delay removed, and also gives extremely powerful custom pets.
The idea is to make as many classes as possible viable for end game soloing, and to make gameplay more interesting by having situationally useful and flavourful pets so you aren't using the same pet all the time. I'm trying to do this in a way that still makes champion levels useful so there is end-game advancement. For instance, the healer pet applies baseline str/con/dex buffs, but also uses the cleric spec shield buff so the champion shield buff stacks with it, and the champion str/con and dex/qui buffs are still valuable.
Re: Triggering a script by using an item?
PostPosted: Sun Apr 09, 2017 8:09 pm
by ontheDOL
incase anyone else is interested in items triggering scripts , I found these threads helpful
http://www.dolserver.net/viewtopic.php? ... pe#p142810
http://www.dolserver.net/viewtopic.php? ... pe#p149061
http://www.dolserver.net/viewtopic.php? ... pe#p118958
all the links have some example script extracts of how to make a "classtype" for a templated item