Author Topic: Combing Script functions?  (Read 956 times)

Legacy_Foregone_Conclusion

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Combing Script functions?
« on: January 07, 2012, 09:06:27 am »


               Okay so I am having trouble implementing some scripts to a module that I wanted to use.  The following here :

http://nwvault.ign.c....Detail&id=3841
and
http://nwvault.ign.c....Detail&id=3846
As well as
http://nwvault.ign.c....Detail&id=3842

 Now all of these call for having their own module On_Activate scripts in place. I haven't tried putting them in because I wanted to keep the defualt scripts in place that are set because other things I have in the current module call on the default scripts. (default meaning X2_mod_on_act) etc etc.

 What I did for one of these script sets was append the ON_Equip/OnUnequip with the scripts the author provided, and it seems to work just fine. But I can't do that with the above for the On_Activate/On_Acquire.  How can I combine/join these script functions together? 

 (Be gentle I am a newb at this.) 
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Combing Script functions?
« Reply #1 on: January 07, 2012, 10:11:36 am »


               Im currently away from home, and I have no priviledges to install stuff on this computer. (no toolset, files in .erf) Could you post the scripts?

edit

Nevermind, apparently im not even allowed to be here. gtg '<img'>
I propably wont be able to help you. (Due to lack of access to a computer D:)
               
               

               


                     Modifié par Xardex, 07 janvier 2012 - 10:14 .
                     
                  


            

Legacy_Foregone_Conclusion

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Combing Script functions?
« Reply #2 on: January 07, 2012, 06:32:09 pm »


               Okay here is one of the scripts that I mean

//::///////////////////////////////////////////////
//:: Example XP2 OnActivate Script Script
//:: x2_mod_def_act
//:: © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Put into: OnItemActivate Event

*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-16
//:://////////////////////////////////////////////

#include "x2_inc_switches"
void main()
{
     object oItem = GetItemActivated();

     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss
     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
        ExecuteScript(GetTag(GetItemActivated()),
        OBJECT_SELF);

        }
        {
           return;
        }

     }

}

The underlined section  is what I was trying to add. Seems to be the function the Tag Based Script wants to call on. Technically its just about the same thing as what is already there, but the Tag script does not utilize it. So whats the proper way to add the extra lines in? 
               
               

               


                     Modifié par Foregone_Conclusion, 07 janvier 2012 - 06:33 .
                     
                  


            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Combing Script functions?
« Reply #3 on: January 07, 2012, 06:40:39 pm »


               Most of the time, these scripts will have lines that are similar to
ExecuteScript("ac_"+GetTag  (GetModuleItemAcquired()), OBJECT_SELF);
Just add that line to your onactivate event script somewhere inside of the void main() brackets, but above the
// * Generic Item Script Execution Code
line.

As to your code above:
move the highlighted line a couple lines higher. it should be closer to:

       int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
       ExecuteScript(GetTag(GetItemActivated()),
       OBJECT_SELF);
       if (nRet == X2_EXECUTE_SCRIPT_END)
       {

The line that says "if (nRet == X2_EXECUTE_SCRIPT_END)" means that anything in the brackets under it will only fire if another tag based script has fired and that script returned a specific variable marking it as complete.

Normally, your tag based scripts will have a prefix that you can choose. Say we use "itm_". So, if we have a item tagged "myitem", the name of the script that fires will be named itm_myitem.
That's what this line does:
int nRet = ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF); 
Your new line always calls a script with only the tag and no prefix.
This can be an issue if you have tag based scripts enabled and do not use a prefix. The script can be called twice.
If you notice that the items are being called twice, delete that new line.
               
               

               


                     Modifié par wyldhunt1, 07 janvier 2012 - 06:46 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Combing Script functions?
« Reply #4 on: January 07, 2012, 06:46:08 pm »


               X2_EXECUTE_SCRIPT_CONTINUE is the default return (of zero).
X2_EXECUTE_SCRIPT_END must be set in the executed script.
               
               

               
            

Legacy_Foregone_Conclusion

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Combing Script functions?
« Reply #5 on: January 07, 2012, 09:05:56 pm »


               Okay... well I tried that, (thanks). However it seems the on activate isn't calling on the script at all, or only partially.  On equip items don't seem to be having any trouble executing. For example, the cloak of invisibility works as its put on. And there are some Movement Speed enchancing boots that seem to work.

But the ForceRest potion and the town portal scripts are not calling their scripts via their tags.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Combing Script functions?
« Reply #6 on: January 07, 2012, 09:17:59 pm »


               The Script you posted above is the standard bioware script for the module's OnItemActivate Event.

Is it the one you where currently using?

If not please post your original OnItemActivate Event script here ot at pastebin.com with a link back here.
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Combing Script functions?
« Reply #7 on: January 07, 2012, 09:39:03 pm »


               Also, make sure that you have tag based scripting enabled in your modload event.
MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS
I don't have access to NWN right now, but there should be an option to enable it. I think it's enabled by default, but it may not be if you're using old code.
Take a look in your OnModLoad event and see if you can find it.
               
               

               
            

Legacy_Foregone_Conclusion

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Combing Script functions?
« Reply #8 on: January 07, 2012, 09:43:21 pm »


               This is what is in the script (which is the defualt NWN on_load script)

 SetModuleSwitch (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS, TRUE);

  if (GetModuleSwitchValue (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)

And yes the script above is the standard bioware script. Not using anything different. I am running some custom haks but I can't think of anything that would interfere with the scripting system.
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Combing Script functions?
« Reply #9 on: January 07, 2012, 11:09:46 pm »


               Then, something is wrong somewhere. </Obvious>
It's probably something simple.
I haven't downloaded the erf that you are using yet, since I'm at work.
Can you post the townportal item tag and the script name?
And, would you mind posting your OnActivate script exactly as it is now, with the changes you've made?
               
               

               
            

Legacy_Foregone_Conclusion

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Combing Script functions?
« Reply #10 on: January 07, 2012, 11:24:09 pm »


               Okay here is the On_Activate (Sans the green text thats usually above it)

void main()
{
     object oItem = GetItemActivated();

     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss
     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
        ExecuteScript(GetTag(GetItemActivated()),
        OBJECT_SELF);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }

     }

Correct?

Town Portal item tag is : scrl_twnpp_strk
The script name is : scrl_twnpp_strk

 There is an older town portal system that I am going to try later, that I think should actually work as intended.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Combing Script functions?
« Reply #11 on: January 07, 2012, 11:33:00 pm »


               @wyldhunt. All three systems he posted do not use the standerd tag based scripting and where written by the same person. Well posted to the valt by the same person, they where writtem by lilac's script generator.

The Krit in comments on the vault even sugested that the author convert them to comform to standard TBS. I have to agree. instead of messing with the module events, it would be better to just edit the scripts to conform to the standard TBS.

Looking at the transport system, I am not even sure it worked for the get go yet. But I have just barly glanced over them.

EDIT:  Ok It would work the way he has it wtitten.   But he has him modifying three module events for a system that uses only one of them.
   Instead of simply placing the  filter int the script to not run the other events. 
   Problem two. It requires him to write a script for each waypoint/scroll combination using the ones given as a templet.  
   Problem three:   If used on a PW where all the players have the habit of grouping up ito a single party to chat. It will take everyone who is in the party to the waypoint reguardless of where they are.

@ForeGone:   All of that can be fixed.  But i would sugest finding a better teleport system. 
I have not looked at the other two systems yet,  But from what I have read so far thay also should be cleaned up a bit. At least as far as brining them back into TBS standard. 

Here is the script of the transport system if you wanted to still see it Whyled.   http://pastebin.com/bVgfXka2 
               
               

               


                     Modifié par Lightfoot8, 07 janvier 2012 - 11:48 .
                     
                  


            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Combing Script functions?
« Reply #12 on: January 08, 2012, 12:09:05 am »


               Erk!
Bad code. Bad!

@Foregone Conclusion
Yes. You seem to have your OnActivate set up to trigger the code the way they intended.

For starters, the reason it's failing is because of this:

location lTarget;
oTarget = GetWaypointByTag("stp_link_strk");
if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;


lTarget is never given a location, so it never has an area. The script exits before it ever starts.

I also advise you to find a new system.
               
               

               


                     Modifié par wyldhunt1, 08 janvier 2012 - 12:10 .
                     
                  


            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Combing Script functions?
« Reply #13 on: January 08, 2012, 03:45:23 am »


               Okay...
This isn't tested. In fact I'm still at work, so I haven't even tried to compile it. I just typed it out in Notepad, based on the code that Lightfoot posted...
It may need some tweaks.
http://pastebin.com/Ws3ADdUj

It is set up to use tag based scripting.
There is a tutorial to help you understand how tag based scripting works here:
http://www.nwnlexico...dscripting.html

Notes:
The target location is a waypoint with a unique tag.
The tag of the waypoint needs to be set on the item as a string variable named JUMPTO.
This is a potential flaw if you intend to sell unlimited quantities of these items in a store.
Items get all of their variables wiped when they are set to unlimited in a store.
I've fixed that in Adelan (Our PW) by deleting any storebought items acquired and then re-creating them in the players inventory. If you want that fix, let me know.
The advantage of this is that you can make multiple copies of the item and give them all the same tag, but change their name and JUMPTO variable. The one script will handle as many items and jump locations as you want.
It is set up so that it jumps all party members in the characters current area. They all get the special effects from the old script. This can cause a lag spike if there are a lot of party members in the area. If you want it to only trigger the special effects on the character using the item, I can change that for you. I can also stagger the timing a little bit on when each member jumps by a fraction of a second so that all of the effects don't lag quite as bad. I just didn't have time right now.
I can also change it to only jump party members within a set distance of the character (Say, party members within 20 feet). Again, I just didn't have time (Or good enough memory of Aurora script to do it all from memory).
               
               

               


                     Modifié par wyldhunt1, 08 janvier 2012 - 04:28 .
                     
                  


            

Legacy_Foregone_Conclusion

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Combing Script functions?
« Reply #14 on: January 09, 2012, 12:49:43 am »


               Okay so I found this on activate script  from another Townportal on the Vault.

void main()
{
// variable init
object oItem = GetItemActivated(); // gets which item activated
object oPC = GetItemActivator(); // gets item activator
string sItemTag = GetTag(oItem); // gets tag of activated item
if (sItemTag == "townportal") { // checks if it's the town portal scroll that was used
location lLoc = GetItemActivatedTargetLocation(); // sets the location the scroll was casted at
// Effects start
effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD, FALSE);
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVis, lLoc, 6.0);
// Effects stop
CreateObject(OBJECT_TYPE_PLACEABLE,sItemTag,lLoc,TRUE); // creates the actual portal
SetLocalLocation(oPC, "Portal", GetItemActivatedTargetLocation()); // stores the location variable in the PC itself
}
}

Looks to be well written and I do know it works, as I've used it before. Though last time I had some sort of trouble with it conflicting with other tag fired scripts...

@Wldly hunt. Yours is the raw post data correct?  That actually compiled when I used it in the script editor. However I can't seem to get the on_activate to work still. I think maybe the tag-based scripts themselves may need some touch ups?