Author Topic: Help: How to merge scripts  (Read 481 times)

Legacy_Wall3T

  • Hero Member
  • *****
  • Posts: 748
  • Karma: +0/-0
Help: How to merge scripts
« on: August 11, 2012, 08:26:24 pm »


               Hi;

i dont venture to this side of the forums very often, but im looking to find out how to merge two particuler scripts together.

im playing around with an old rhun module, and i wanted to merge this farming system to it:

nwvault.ign.com/View.php

what i dont know how to, is merge the existing onactivate scripts (from both the farming and rhun) together (or if thats all together possible)

id like to know: if i can, how do i do it?

I have the scripts below for viewing:

Rhun activate script

#include "taip_r_header"
#include "x2_inc_switches"
#include "sha_subr_methds"
void main()
 {

    object oPC = GetItemActivator();
    string oTag = GetTag(GetArea(oPC));
    if(oTag == "Void" || oTag == "DeathRow")
    {
       SendMessageToPC(oPC, "You cannot use any items while you are trapped in the Void.");
       return;
    }

    ExecuteScript(GetTag(GetItemActivated()), OBJECT_SELF);
    if (GetIsInCombat(oPC)){
    ExecuteScript("recall_stone5", OBJECT_SELF);}
    else if (oTag == "TaerPrisonIsland"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "TaerPrison"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "TaerPrison2"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "TaerPrison3"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "TaerPrisonTunnels"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "TheUnderworld"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "TheUnderworld1"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "TheUnderworld2"){
    ExecuteScript("recall_stone2", OBJECT_SELF);}
    else if (oTag == "AmnathkylsLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "BrybansLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "JubangansLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "LairOfCaraec"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "ScrycansLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "TyreksLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "WyzazonsLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "ZolgilnathsLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "ZyfusborsLair"){
    ExecuteScript("recall_stone3", OBJECT_SELF);}
    else if (oTag == "TanzantorsCastle"){
    ExecuteScript("recall_stone4", OBJECT_SELF);}
    else if (oTag == "TheHighSeasZ"){
    ExecuteScript("recall_stone6", OBJECT_SELF);}
    else
    {
        ExecuteScript("recall_stone1", OBJECT_SELF);
    }
    object oItem = GetItemActivated();
    ExecuteScript (GetTag(oItem), GetModule());
    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)
        {
           return;
        }

     }
}


Farming Activate Script

//:://////////////////////////////////////////////
//:: Name: farm_mod_activ
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    OnItemActivate script for the module.

    This script will handle the necessary actions
        for seed/item activation.
*/
//:://////////////////////////////////////////////
//:: Created By: Adam Walenga
//:: Created On: August 30th, 2004
//:://////////////////////////////////////////////

void main()
{
    object oPlayer = GetItemActivator();
    object oItem = GetItemActivated();
    string sResRef = GetResRef (oItem);

    //Store information captured here to use with ExecuteScript scripts.
    SetLocalObject (oPlayer, "Item_Used", oItem);
    SetLocalObject (oPlayer, "Item_Target", GetItemActivatedTarget());

    if (GetStringLeft (sResRef, 5) == "seed_")
        ExecuteScript ("farm_plant", oPlayer);
    else
        ExecuteScript (sResRef, oPlayer);
}

               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Help: How to merge scripts
« Reply #1 on: August 11, 2012, 09:05:09 pm »


               Easy way: make another script that calls each of them using ExecuteScript().

Better way:
#include "taip_r_header"
#include "x2_inc_switches"
#include "sha_subr_methds"
void main()
{
    object oPC = GetItemActivator();
    string sAreaTag = GetTag(GetArea(oPC));

    if(sAreaTag == "Void" || sAreaTag == "DeathRow")
    {
        SendMessageToPC(oPC, "You cannot use any items while you are trapped in the Void.");
        return;
    }

    object oItem   = GetItemActivated();
    string sResRef = GetResRef (oItem);

    //Store information captured here to use with ExecuteScript scripts.
    SetLocalObject(oPC, "Item_Used", oItem);
    SetLocalObject(oPC, "Item_Target", GetItemActivatedTarget());
    if (GetStringLeft (sResRef, 5) == "seed_")
    {
        ExecuteScript ("farm_plant", oPC);
        return;
    }
    else if (sResRef == "waterbucket" || sResRef == "shovel")
    {
        ExecuteScript(sResRef, oPC);
        return;
     }

    string sScript;

    ExecuteScript(GetTag(GetItemActivated()), OBJECT_SELF);
    if (GetIsInCombat(oPC))
     
    sScript = "recall_stone5";
    else if (sAreaTag == "TaerPrisonIsland"  ||
             sAreaTag == "TaerPrison"        ||
             sAreaTag == "TaerPrison2"       ||
             sAreaTag == "TaerPrison3"       ||
             sAreaTag == "TaerPrisonTunnels" ||
             sAreaTag == "TheUnderworld"     ||
             sAreaTag == "TheUnderworld1"    ||
             sAreaTag == "TheUnderworld2")
        sScript == "recall_stone2";
    else if (sAreaTag == "AmnathkylsLair"  ||
             sAreaTag == "BrybansLair"     ||
                          sAreaTag == "JubangansLair"   ||
                          sAreaTag == "LairOfCaraec"    ||
                          sAreaTag == "ScrycansLair"    ||
                          sAreaTag == "TyreksLair"      ||
                          sAreaTag == "WyzazonsLair"    ||
                          sAreaTag == "ZolgilnathsLair" ||
                          sAreaTag == "ZyfusborsLair")
        sScript = "recall_stone3";
    else if (sAreaTag == "TanzantorsCastle")
        sScript = "recall_stone4";
    else if (sAreaTag == "TheHighSeasZ")
        sScript = "recall_stone6";
    else
        sScript = "recall_stone1";

    ExecuteScript(sScript, OBJECT_SELF);

    ExecuteScript (GetTag(oItem), GetModule());
    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)
            return;
    }
}

It's still not optimal. The Rhun script gets its recall stone scripts fired on everything. However, if you don't want to set about redoing the whole Rhun recall system, this'll probably have to do.
               
               

               


                     Modifié par Squatting Monk, 11 août 2012 - 08:12 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Help: How to merge scripts
« Reply #2 on: August 11, 2012, 09:31:49 pm »


               Why not just rewrite the whole thing and put variables on each area, instead of using the Tag of the Area?
So the variable recallstone1 set to 1,2,3, etc.. fires off the script of the same name. That way you could change it just by changing the variable on the area, instead of going into the script and writing all those tags, also more useful for those who don't have those areas by that name, or when you add areas.

To stop the item from activating on any event just put this at the top of the script:
#include "x2_inc_switches"
void main()
{
 int nEvent =GetUserDefinedItemEventNumber();
     if (!nEvent == X2_ITEM_EVENT_ACTIVATE)
     return;

Then for the areas such as the void you could put a variable on them too like NoRecallStone set to 1 and the line that returns the script would look like this:

  if (GetLocalInt(oArea, "NoRecallStone") == 1)
        {
       SendMessageToPC(oPC, "This item is not useable here.");
       return;
        }
               
               

               


                     Modifié par ffbj, 11 août 2012 - 08:42 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Help: How to merge scripts
« Reply #3 on: August 11, 2012, 09:40:56 pm »


               Yeah, that would be the best way to do it.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Help: How to merge scripts
« Reply #4 on: August 11, 2012, 09:43:28 pm »


               Yeah you said as much, nice to see some old timers, I mean really old timers still around.
Wow! You rewrote the skill system.  Impressive.  Have to come by and check out the world sometime.
Mostly I just work on mine these days.
               
               

               


                     Modifié par ffbj, 11 août 2012 - 08:49 .
                     
                  


            

Legacy_Wall3T

  • Hero Member
  • *****
  • Posts: 748
  • Karma: +0/-0
Help: How to merge scripts
« Reply #5 on: August 12, 2012, 12:34:18 am »


               wow, thanks guys '<img'> i think that ought to do it. im not great on scripting so i wasnt sure how to go about dong it. as for the modding, keep it up! i like to see new ideas
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Help: How to merge scripts
« Reply #6 on: August 12, 2012, 12:44:34 am »


               Kye, if you need any help with Rhun at all please don't hesitate to pm me. Myself, Carcerian and Baaleos are probably the most experienced with Rhun at this stage of the game. And if you downloaded the original Rhun from the vault you will need to fix multiple issue which I addressed and fixed in my updated versions of Rhun found here: http://nwvault.ign.c....Detail&id=6024
               
               

               


                     Modifié par Birdman076, 11 août 2012 - 11:45 .
                     
                  


            

Legacy_Wall3T

  • Hero Member
  • *****
  • Posts: 748
  • Karma: +0/-0
Help: How to merge scripts
« Reply #7 on: August 12, 2012, 12:51:26 am »


               aha;

as a matter of fact, that is the very one i grabbed for using. im surprised to not see your name in the module. i will have to change that.

your rhun j, is perhaps the best rhun module ive seen to date. its very handy when i dont have to keep hearing from my players why all the journal quests are  missing, when they were never there in the first place '<img'>
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Help: How to merge scripts
« Reply #8 on: August 12, 2012, 01:23:55 am »


               Typically I don't put my name on much lol. I'm more of a man behind the curtain kinda guy, make the magic, watch the awe but stay well out of the lime light. I had given thought to releasing some persistent versions of Rhun as it is supposed to be a persistent world but I've gone quite a bit past just adding persistence to my version and it would be a bit of work to remember all the things I had to do to make the quest lines persistent throughout the entire module. I can't remember if I fixed the bandit on south dugan plains which is supposed to drop the quest bag of gold or not in those versions, if not its an easy fix and outlined on Shayan's forums quoted below:

"On the off hand chance you still care after all these years, the thing to change in the South Dugan Plains area is the second to last encounter. Right-click on that to get the context menu and choose properties. On the Creatures tab you can see the Thief that is used. He's the only one that is called "Thief" instead of "Bandit" so he'll be easy to find. On the left panel, click on the custom palette tab and he's in the NPCs -> Half-Elves section. Right-click to choose edit creature from his context menu and click on his inventory. In the inventory contents screen, click on the custom items tab and the bag of gold can be found in the Special -> Custom 2 section about six items down ("Elith's Bag Of Gold"). Just drag that to the contents section and make sure to click on the dropable checkbox (and, if you're like me, you'll also want to check the pickpocketable checkbox because it just makes sense Smile ). Save and you're done!"