Skip to content

Hall of Traps

I'm trying very hard to create a script that will: when a wand is used it disarms each trap slowly, one by one. There are 10 traps in the hallway...
I've tried to do this but I'm afraid my scripting hasn't caught up with my ambitions. :)
Any help would be greatly appreciated.

Comments

  • ZephiriusZephirius Member Posts: 419
    I've really gotten nowhere...

    void main()
    {

    object oTrapSeen = GetTrapDetectable();
  • ForSeriousForSerious Member Posts: 466
    edited January 2021
    Make a script called "trap_wand":
    void main()
    {
        // You can set this to get any trap, but calling it this way only gets traps that the user can see.
        object oTrap = GetNearestTrapToObject();
        // This is our escape case. When the user sees no more traps oTrap will return as OBJECT_INVALID.
        if(GetIsObjectValid(oTrap))
        {
    	// This tries to copy the visual display of the knock spell.
            effect eVis = EffectVisualEffect(VFX_IMP_KNOCK);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTrap);
    	// This disables the trap and fires the OnDisabled event of the trap.
            SetTrapDisabled(oTrap);
    	// This waits 2 seconds then calls the script again on the player that originally called it.
            DelayCommand(2.0, ExecuteScript("trap_wand"));
        }
    }
    

    I have not compiled this or tested it at all, but it should be a good start, I think.

    Let me know if you need help getting the wand to call the script using your module OnItemActivated script.
    (Added comments to the code)
    Post edited by ForSerious on
  • ZephiriusZephirius Member Posts: 419
    Thank you ForSerious. Gonna give it a try. I'll let you know.
  • ZephiriusZephirius Member Posts: 419
    Yeah, OnItemActivated eludes me???
  • ForSeriousForSerious Member Posts: 466
    So, make sure your wand has the property Cast Spell: Unique Power (You can do the Self Only one fore this. It's not going to matter)
    Under the edit tab, go to module properties. Under the events tab, edit the second script down (OnActivateItem). Ignore all warnings.
    The script should already have
    object oItem = GetItemActivated();
    
    Somewhere under that, add:
    // This grabs who used the item.
    object oPC = GetItemActivator();
        // This is a fail-safe check
        if(GetIsObjectValid(oItem))
        {
    	// Find the tag of the item that was activated.
            string sTag = GetTag(oItem);
    	// If it is the trap wand, run the script on the player who activated it.
    	// You will need to replace YourWandTag with the actual tag of the trap wand.
    	if(sTag == "YourWandTag")
    	{
            	ExecuteScript("trap_wand", oPC);
    	}
        }
    

    There may be a if(GetIsObjectValid(oItem)) check in the script already, you can copy what you need.
  • ZephiriusZephirius Member Posts: 419
    When I use the wand, there is no unique power option from the radial menu. Not sure. The very first script trap_wand, is it supposed to be attached to an event handler? Or is the script just sitting there waiting to be called?
  • ZephiriusZephirius Member Posts: 419
    OK. Great job ForSerious! Both scripts are up and running, and running well I might add...
    Thank you for your time and your scripting lesson. :wink:
  • ForSeriousForSerious Member Posts: 466
    You're welcome.
Sign In or Register to comment.