Author Topic: Script Assistance  (Read 699 times)

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« on: September 27, 2011, 08:14:51 am »


               Well I'll start off by saying that I hate to make multiple topics in any forum, but I am having a lot of trouble with a script I've been trying to put together. Now I suck at scripting, so I've mostly been drifting around the interwebs in search of multiple scripts to compile together into what I want. Normally I'm able to do this successfully, but it seems I've actually come to the end of the line of my own adequacy.

I am trying to create a placeable (in this case a shaft of light) where once approached (10-20 feet or so), said placeable spawns an encounter I've premade and the placeable disappears/is destroyed. In addition, I am trying to make it so this placeable/encounter will respawn every four minutes or so. Is this at all possible?

PS. More of a want than a need, but it can't hurt to ask: is it possible for a script to destroy a placeable (preferably with an animation) triggered by the emptying of a container/chest? Then this placeable and this chest respawns every twenty minutes or so?

I know I'm asking for a lot, but I would immensley appreciate it and even add credits to the finished module if desired. These two scripts (more importantly the first) are essential to the gameplay element of the module. Pretty much every encounter will be made through the placeable-destruction script, if such script is possible.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script Assistance
« Reply #1 on: September 27, 2011, 09:02:36 am »


                  You should be able to do what you're hoping for quite easily.  Set the encounter you've painted down to respawn every 4 minutes, and then make a script for the encounter triggers OnEnter something like this:


void DelayedCreateObject (string sResRef, location lTarget);
void main()
{
 object oPC = GetEnteringObject();
 // stops NPCs from triggering the encounter.
 if (!GetIsPC (oPC)) return;
 
// Will only run the rest of the script to spawn the encounter if the
 // lightshaft is present.
 object oTarget = GetObjectByTag("LIGHT_SHAFT_TAG_HERE");
  if (!GetIsObjectValid (oTarget)) return;

 // Grab the resref and location before destroying
 string sResRef = GetResRef (oTarget);
 location lTarget = GetLocation (oTarget);
 DestroyObject (oTarget);

 DelayCommand (240.0, DelayedCreateObject (sResRef, lTarget) );
}

void DelayedCreateObject (string sResRef, location lTarget)
{
 // You can't delay creation normally, so you make a seperate function
 //  to create the object and delay that instead.
 CreateObject (OBJECT_TYPE_PLACEABLE, sResRef, lTarget, FALSE, "LIGHT_SHAFT_TAG_HERE");
}


  Just make sure that the lightshaft has a unique tag, or else it might check/destroy the wrong one.  I just wrote that quickly, and test compiled it rather than testing.  If it doesn't work quite right, or you have questions, don't hesitate to ask.

Edit:  Fixed the lines I'd messed up.
               
               

               


                     Modifié par Failed.Bard, 27 septembre 2011 - 11:33 .
                     
                  


            

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« Reply #2 on: September 27, 2011, 11:07:53 am »


               I really really appreciate all the help, man. I have come across what seems to be just a small error, that I could have probably solved myself if it weren't for my scripting incompetence.

I placed the placeable tagged "spawn1" in the center of the encounter trigger, which is set to 240 seconds to respawn. The trigger has the OnEnter script you posted for me, but it didn't compile. It gave me the message "ERROR: DECLARATION DOES NOT MATCH PARAMETERS" for line 17. In both places where you specified to insert the light shaft tag, I entered "spawn1". Maybe you know what this means?
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script Assistance
« Reply #3 on: September 27, 2011, 12:17:24 pm »


                 Oops, my mistake there.  I changed a line in my post without confirming it in the toolset.  Really sorry about that, I added extra variables to the wrong command.  Fixed the lines in the original posting of the script.
               
               

               


                     Modifié par Failed.Bard, 27 septembre 2011 - 11:31 .
                     
                  


            

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« Reply #4 on: September 27, 2011, 12:51:48 pm »


               No need to be sorry at all, you're saving me from tons of frustration messing with scripts that I know next to nothing about. As of right now, the script works almost perfectly. The only bug I'm having now is that the shaft of light isn't respawning, but the encounter trigger is.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script Assistance
« Reply #5 on: September 27, 2011, 02:59:51 pm »


               Alright, I figured out why the creation part wasn't working.  I'd thought encounters just "turned off", so to speak, but it looks as though they're deleted then recreated later when they're "active" again.  Since the encounter isn't there any longer, the delayed part can't run.
 It should work, as is, if you place a seperate generic trigger down in the same place and put the script in the on enter of that instead.

 I'd also noticed it doesn't seem to want to destroy a static placeable, so you might need to make sure you're using a light that's set that way in the palette, and not just adjusted on the map, or it might not work properly on the second time.
               
               

               
            

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« Reply #6 on: September 27, 2011, 03:30:22 pm »


               I did the generic trigger idea and it works absolutely perfectly. Thank you so much for this. A module ain't a module without the combat and, in this case, the fancy encounter animations. =P
               
               

               
            

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« Reply #7 on: October 03, 2011, 12:33:38 pm »


               Now I've been trying to get this one script to work for forever, now, and quite frankly I think I'm going crazy. I am trying to have an item with "use unique power" that practically mounts you up instantly (that means no horse sattlebag storage or anything). To do this I used the proper resref (blackhorse) and used the OnActivateItem script of the module to try summoning this creature and then mounting it all in one motion, one after the other.

Once mounted I wanted it to be exactly the same as any other mounted horse, only once you dismount, the horse is immediately dismissed. If possible I was trying to get the visual of the player using the item, suddenly appearing mounted on the horse, and then appearing the same as when they started upon dismounting.

I've accomplished summoning the horse and that's it. I can mount it, but only manually, whereas I wanted the script to automatically mount me on the horse. So far I've gone so nuts that I pretty much erased all my progress out of confusion and aggitation.

Note: You could compare this whole thing to World of Warcraft's mount system, if you will.

Once I have the script down, I planned on making individual horse summons/mounts scripts, within the same script, tied to the tag of the item with the "use unique power" ability. I think I can figure that out, as long as I manage to finish script itself. Can anyone help me?
               
               

               


                     Modifié par Junnest, 03 octobre 2011 - 11:36 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script Assistance
« Reply #8 on: October 03, 2011, 04:44:41 pm »


                   You mount the horse by casting the mount horse spell on it, if I remember right.  I had similar issues when I made the "Summon Mount" spell for my little mod.  I can post the code I used for the creation and mounting when I get home again tomorrow if nobody else has helped you with it before then.

    As for unsummoning it as soon as the horse is dismounted, I'm not sure how to do that part.  That was the aspect of my spell I never got working properly, since once the horse is mounted the original variables and duration you might have put onto it when you created it are lost.

    If it's possible to make it off of a unique resref horse, I suppose you could put something into its on HB script, but that will only work if it creates the same resref version horse when you dismount, and not the standard version of it.  I'll do a bit of testing on that tomorrow as well.

    It might be best to handle it in the dismount spell.  That way you can do your checks as soon as the PC dismounts to see if the horse should be "unsummoned".  I'll test out how much work it is to change that as well.  It might be a fair bit, since I think the code that handles that is in an include.
               
               

               


                     Modifié par Failed.Bard, 03 octobre 2011 - 03:45 .
                     
                  


            

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« Reply #9 on: October 04, 2011, 06:53:12 am »


               I attempted using an erf I downloaded off of nwvault as an alternate mounting option, and while it wasn't what I wanted, it made it so that once you mounted an item would appear in your inventory that could be used to dismount. Maybe that could work, considering how you say the variables are lost from the mounted creature? The item could maybe have a tag that is listed in the OnActivateItem script where the script can call for onuse-dismount/dismiss?

I would appreciate it sooo much if you could help me get this thing to work. I've been hung up on it for what I thought would be hours, what has turned into days. Out of all the scripting elements I have to implement before progressing with this module, this is the last (next to the death system, which I already have figured out).
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script Assistance
« Reply #10 on: October 04, 2011, 12:56:18 pm »


               There's actually no reason why the same item can't be used to both summon/mount, and dismount/unsummon.  I'll be back home in three hours or so now, so I'll see about turning my summon mount spell into an item that does both then.

 The only tricky thing will be checking for the horse if they dismounted using the standard horse radial and then removed it from the party, but I should be able to find the naming convention used for tagging the horses to take care of that.
               
               

               
            

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« Reply #11 on: October 04, 2011, 06:05:40 pm »


               Yeah, I was thinking about that at the point when I was so desperate - I was just going to leave a sign at the start of the module or a note in the journal that says to use the dismount item instead of radial menu option (a kinda pathetic way out). But that would be amazing if the script could call for the same dismount/dismiss/unsummon by both the radial menu and unique item use. I'm also assuming that with this script I can set the resref/tag of other mount models included in CEP 2.4, which would expand a lot of the ideas I was originally forced to disregard due to this scripting issue (but I won't get my hopes up yet just in case the script and the models aren't compatible for some reason or other).

I appreciate all the effort you're putting into this, I really do. Can't stress that enough.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script Assistance
« Reply #12 on: October 04, 2011, 07:06:34 pm »


                 Okay, this should work with any single resref mount.  I don't have cep 2.4 installed, so it was tested with a horse, but it should work for the alternate mounts in other packages as well.

First, the item script:

#include "x2_inc_switches"
void main()
{
 if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
 object   oTarget = GetItemActivator();
 location lTarget = GetLocation (oTarget);
 if (!GetLocalInt (oTarget, "MOUNTED"))
    {
     SetLocalInt (oTarget, "MOUNTED", TRUE);
     object oSteed = CreateObject (OBJECT_TYPE_CREATURE, "put_resref_here", lTarget);
     // Assigns the mount to oTarget.  The delay is just to ensure the Steed is created fully first.
     DelayCommand (0.3, AssignCommand (oTarget, ActionCastSpellAtObject (SPELL_HORSE_ASSIGN_MOUNT, oSteed,  METAMAGIC_NONE, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE)) );
     DelayCommand (0.4, AssignCommand (oTarget, ActionCastSpellAtObject (SPELL_HORSE_ASSIGN_MOUNT, oTarget, METAMAGIC_NONE, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE)) );
     DelayCommand (0.5, AssignCommand (oTarget, ActionCastSpellAtObject (SPELL_HORSE_MOUNT,        oSteed,  METAMAGIC_NONE, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE)) );
    }
 else
    {
     DeleteLocalInt (oTarget, "MOUNTED");
     AssignCommand (oTarget, ActionCastSpellAtObject (SPELL_HORSE_DISMOUNT, oTarget,  METAMAGIC_NONE, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
    }
}


  Then put this into the heartbeat event of the custom mount:

void main()
{
 if (GetLocalInt (OBJECT_SELF, "UNMOUNTED"))
    {
     DeleteLocalInt (GetMaster (OBJECT_SELF), "MOUNTED");
     DestroyObject (OBJECT_SELF);
    }
 else
    {
     SetLocalInt (OBJECT_SELF, "UNMOUNTED", TRUE);
    }
}

It's nothing fancy, just destroys the mount on the second HB after the player dismounts.  You could add a VFX to the "summoning" and "unsummoning" if you wanted, I just put the basic support in place.
               
               

               


                     Modifié par Failed.Bard, 04 octobre 2011 - 06:07 .
                     
                  


            

Legacy_Junnest

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
Script Assistance
« Reply #13 on: October 04, 2011, 07:52:39 pm »


               Everything compiled successfully. I placed the appropriate resref and even tried a second one when the first didn't work for the OnActivateItem module event, placing that other script in the heartbeat event for either creatures, but when I use the item ingame nothing happens. I assumed the actual item that I was using had to have a certain tag or resref, assuming it was "MOUNTED" I gave that a try. Everything looks just fine script-wise, I think maybe I am missing a component.

Update: I decided to create a new module without CEP, put the scripts in the module and creature events with the appropriate resref, but had the same result. Just for the sake of it, I also gave the item the resref and tag of "MOUNTED", but I doubt that's even necessary.
               
               

               


                     Modifié par Junnest, 04 octobre 2011 - 06:53 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script Assistance
« Reply #14 on: October 04, 2011, 08:31:30 pm »


               Ah, I take it you're not entirely sure how to use tag based scripting then.  You'll want the items tag to be the same as the script name.  In that particular case, the tag name isn't case sensative, though it generally is.

 If you tag the item "SUMMON_MOUNT", and save the script as "summon_mount", then that should be all you need to do with it to make it work, assuming that tag based scripting is turned on.

 You can check that in the on module load event, there'll be a switch o use tag based scripting that might be commented out.  Make sure that line is just like this (no // in front):
SetModuleSwitch (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS, TRUE);