Author Topic: Combo-Tag Scripting...  (Read 370 times)

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« on: June 13, 2012, 10:45:53 am »


               Ok, heres a cool scripting trick I have gotten a lot of mileage out of, for lack of a better name I have nicknamed "Combo-Tagging"...

The Basic Idea:

When an OnActivateItem script is called using an inventory items tag to call a script, only the first 16 letter of the tag are used, as there is a 16 letter limit for script names. The remaining characters past the first 16 are ignored, and thus become "combo-tag" sub-data that can then be parsed for use by said script...
               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 12:40 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #1 on: June 13, 2012, 10:48:38 am »


               To make an item that starts a specific conversation:

__talk_with_me__.nss

// _combo_tag_base_
// __talk_with_me__
//first 16 letters = script to execute, beyond (17+) = subtag data
#include "x2_inc_switches"
void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   string sTag = GetTag(GetItemActivated());
   string sSubTag = GetSubString(sTag, 16, GetStringLength(sTag)-16);
   object oPC = GetItemActivator();
   AssignCommand(oPC, ActionStartConversation(oPC, sSubTag,TRUE,FALSE));
}

For example, a dm tool might have the tag "__talk_with_me__DMTOOL"  to start a conversation named "DMTOOL"

Thus a single script is capable of handling multiple instances of use, while being much more persistant than local vars,
and  in addition it helps take the load off of server databases...
               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 12:25 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #2 on: June 13, 2012, 11:03:32 am »


               Another example, an item that lets the user to teleport to a specific waypoint...

"___beam_me_up___.nss"

// _combo_tag_base_
// ___beam_me_up___
//first 16 letters = script to execute, beyond (17+) = subtag data
#include "x2_inc_switches"
void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   object oPC = GetItemActivator();
   //if (GetTag(GetArea(oPC))=="WELCOME"||GetLocalInt(GetArea(oPC), "NOTELEPORT"))
   if (GetLocalInt(GetArea(oPC), "NOTELEPORT"))
   {
       SendMessageToPC(oPC,"Teleportation does not function in this area.");
       return;
   }
   string sTag = GetTag(GetItemActivated());
   string sSubTag = GetSubString(sTag, 16, GetStringLength(sTag)-16);
   object oTarget = GetWaypointByTag(sSubTag);
   location lTarget = GetLocation(oTarget);
   int iVFX = 31;
   if (GetAreaFromLocation(lTarget)==OBJECT_INVALID)
   {
       SendMessageToPC(oPC,"Destination Waypoint "+sSubTag+" not found.");
       return;
   }
   AssignCommand(oPC, ClearAllActions());
   DelayCommand(1.5, AssignCommand(oPC, ActionJumpToLocation(lTarget)));
   ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(iVFX), oPC);
}


Thus to teleport to a waypoint tagged "wp_start" the objects tag would be "___beam_me_up___wp_start"
               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:09 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #3 on: June 13, 2012, 11:12:53 am »


               "__hi_ho_silver__.nss"

A combo-tag script to summon a ridable mount (combo-tag sub-data = mounts resref)

#include "x2_inc_switches"
#include "x3_inc_horse"

void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   object oUser = GetItemActivator();
   if (HorseGetIsMounted(oUser)) return;
   object oItem = GetItemActivated();
   string sTag = GetTag(oItem);
   string sResRef = GetSubString(sTag,16,GetStringLength(sTag)-16);
   //effect eSummon = EffectSummonCreature(sResRef, VFX_IMP_MIRV, 0.0f);
   //ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSummon, oUser, IntToFloat(GetHitDice(oUser)*10));
   object oHorse = HorseGetHorse(oUser);
   if (oHorse == OBJECT_INVALID) oHorse = GetLocalObject(oUser,"STEED");

   /*
   string sUser = GetName(oUser)+"'s ";
   if (oHorse==OBJECT_INVALID)
   {
       oHorse = GetFirstObjectInArea();
       while (oHorse != OBJECT_INVALID)
       {
           if (FindSubString(GetName(oHorse),sUser)>-1) break;
           oHorse = GetNextObjectInArea();
       }
   }
   */
   DestroyObject(oHorse);

   oHorse = HorseCreateHorse(sResRef,GetLocation(GetItemActivator()),oUser);
   //CreateObject(OBJECT_TYPE_CREATURE,sResRef,GetLocation(GetItemActivator()));
   SetLocalObject(oUser,"STEED", oHorse);
}


               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:14 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #4 on: June 13, 2012, 11:15:46 am »


               "__i_choose_you__.nss"

A script to call a summon until next player rest.

#include "x2_inc_switches"

void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   object oUser = GetItemActivator();
   object oItem = GetItemActivated();
   string sTag = GetTag(oItem);
   string sResRef = GetSubString(sTag,16,GetStringLength(sTag)-16);
   effect eSummon = EffectSummonCreature(sResRef, VFX_IMP_MIRV, 0.0f);
   ApplyEffectToObject(DURATION_TYPE_PERMANENT, eSummon, oUser, IntToFloat(GetHitDice(oUser)*10));
}


               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:16 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #5 on: June 13, 2012, 11:23:36 am »


               "___ohh_shiney___.nss"

A script to add a VFX to the items target...

// [_combo_tag_base_]
// [___ohh_shiney___]
//first 16 letters = script to execute, beyond (17+) = subtag data
#include "x2_inc_switches"
void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   object oTarget = GetItemActivator();
   string sTag = GetTag(GetItemActivated());
   string sSubTag = GetSubString(sTag, 16, GetStringLength(sTag)-16);
   int effectNum = StringToInt(sSubTag);
   SendMessageToPC(oTarget,"VFX: "+IntToString(effectNum));
   effect eVFX = SupernaturalEffect(EffectVisualEffect(effectNum));
   ApplyEffectToObject(DURATION_TYPE_PERMANENT, eVFX, oTarget);
}

Esp handy for things like faerie fire, or vfx accessories '<img'>
               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:26 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #6 on: June 13, 2012, 11:28:40 am »


               "_give_you_wings_.nss"

A tool to add or remove a characters wings...

//_give_you_wings_

void main()
{
string sTag = GetTag(GetItemActivated());
string sSubTag = GetSubString(sTag, 16, GetStringLength(sTag)-16);
int iSubTag = 0;
object oUser = GetItemActivator();
int iWings = GetCreatureWingType(oUser);

if (sSubTag == "demonflying")
{
   if (GetGender(oUser) == GENDER_FEMALE)
   {
       iSubTag = 46;
   }
   else
   {
       iSubTag = 45;
   }
}
else
{
   iSubTag = StringToInt(sSubTag);;
}

if (iWings == iSubTag) SetCreatureWingType(CREATURE_WING_TYPE_NONE, oUser);
else SetCreatureWingType(iSubTag, oUser);

}


               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:29 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #7 on: June 13, 2012, 11:30:31 am »


               "_give_you_tails_.nss"

and one for tails...

//_give_you_tails_

void main()
{
string sTag = GetTag(GetItemActivated());
string sSubTag = GetSubString(sTag, 16, GetStringLength(sTag)-16);
int iSubTag = 0;
object oUser = GetItemActivator();
int iTail = GetCreatureTailType(oUser);

iSubTag = StringToInt(sSubTag);;

if (iTail == iSubTag) SetCreatureTailType(CREATURE_TAIL_TYPE_NONE, oUser);
else SetCreatureTailType(iSubTag, oUser);

}


               
               

               
            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #8 on: June 13, 2012, 11:32:24 am »


               "_grow_placables_.nss"

To add or remove a placable object (like furniture, a campfire, etc)

#include "x2_inc_switches"

void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   object oPC = GetItemActivator();
   object oItem = GetItemActivated();
   string sTag = GetTag(oItem);
   string sResRef = GetSubString(sTag,16,GetStringLength(sTag)-16);
   object oTarget = GetItemActivatedTarget();
   location lTarget = GetItemActivatedTargetLocation();

   if (GetResRef(oTarget)==sResRef)
   {
       DestroyObject(oTarget);
   }
   else
   {
       object oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, sResRef, lTarget);
    }
}


               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:34 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #9 on: June 13, 2012, 11:36:12 am »


               "_only_your_hair_.nss"

A script for hair Dye '<img'>

// _combo_tag_base_
// _only_your_hair_

//first 16 letters = script to execute, beyond (17+) = subtag data
#include "x2_inc_switches"
void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   object oPC = GetItemActivator();

   string sTag = GetTag(GetItemActivated());
   string sSubTag = GetSubString(sTag, 16, GetStringLength(sTag)-16);

   int iHair = StringToInt(sSubTag);

   SendMessageToPC(oPC, "Hair Color #"+sSubTag);
   SetColor(oPC, COLOR_CHANNEL_HAIR, iHair);

   ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_HEAD_ODD), oPC);
}


               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:36 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #10 on: June 13, 2012, 11:37:39 am »


               "_play_that_tune_.nss"

An item that plays a specific song

// _combo_tag_base_
// _play_that_tune_
#include "x2_inc_switches"
void main()
{
   if (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE) return;
   object oPC = GetItemActivator();
   string sTag = GetTag(GetItemActivated());
   string sSubTag = GetSubString(sTag, 16, GetStringLength(sTag)-16);
   int iTrack = StringToInt(sSubTag);

   object oArea = GetArea(oPC);
   MusicBackgroundStop(oArea);
   MusicBattleStop(oArea);

   MusicBattleChange(oArea, 0);
   MusicBackgroundChangeDay(oArea, iTrack);
   MusicBackgroundChangeNight(oArea, iTrack);
}


               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:38 .
                     
                  


            

Legacy_Carcerian

  • Hero Member
  • *****
  • Posts: 1655
  • Karma: +0/-0
Combo-Tag Scripting...
« Reply #11 on: June 13, 2012, 11:39:59 am »


               Hopefully are usefull, more to come!

All questions, suggestions and requests welcome '<img'>
               
               

               


                     Modifié par Carcerian, 13 juin 2012 - 10:42 .