Author Topic: [solved] Getting item and its script into OC  (Read 1003 times)

Legacy_zamiwas

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
[solved] Getting item and its script into OC
« on: January 02, 2012, 06:06:23 pm »


               Hoping someone can help me with this,

I made a new item, and a script for its On-hit-cast-spell (unique power),   and they work in a test module.

Now Im trying to get the item into the HotU OC single player to play with. So I put the .UTI and .nss  (?)  into the override folder.  and While I can get the item,  the script does not seem to be coming wth it : (

I tried both importing a saved char,  and dm_spawnitem,   but the script for its On-Hit just isnt there. 
Hopefully theres a simple solution for my newbie understanding. Thanks
               
               

               


                     Modifié par zamiwas, 04 janvier 2012 - 03:33 .
                     
                  


            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #1 on: January 02, 2012, 06:12:17 pm »


               .nss is the uncompiled text. The .ncs is the compiled script that the engine uses.
Make sure that you have the .ncs as well.
               
               

               
            

Legacy_zamiwas

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #2 on: January 02, 2012, 06:44:58 pm »


               I do have the .ncs as well,  But its still not working   : /
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #3 on: January 02, 2012, 07:58:11 pm »


               

zamiwas wrote...

I do have the .ncs as well,  But its still not working   : /


HotU likely uses a module prefix (like "X2_") which would need to be the first character's of the script name (e.g. X2_SCRIPT_TAG would be needed where instead of SCRIPT_TAG).

EDIT: Looking through the HotU OnActivateItem script, it appears the above is not the case.  So long as the tag of the item matches the item, (and is not a special case like the relic of the reaper or Tynan's top)  your script should fire.
               
               

               


                     Modifié par WhiZard, 02 janvier 2012 - 08:42 .
                     
                  


            

Legacy_zamiwas

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #4 on: January 02, 2012, 08:34:19 pm »


               Ok I tested a new working item and script  (x2_dummy.uti  and x2_dummy.ncs)  but it still doesnt work in HotU.  Arrg
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #5 on: January 02, 2012, 08:45:47 pm »


               You would need to check and see what the prefix is. X2_ was just an example.
It might be set in ModLoad. You can also have a script that grabs the prefix from the variable set on the mod and either dump it to a log file or send it to the character so that you know what it is.

I'm at work now, so I can't check myself.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #6 on: January 02, 2012, 08:46:12 pm »


               

zamiwas wrote...

Ok I tested a new working item and script  (x2_dummy.uti  and x2_dummy.ncs)  but it still doesnt work in HotU.  Arrg


I just found that HotU doesn't use the prefix, though the HotU version does include the prefix possibility.  One last suggestion is to check capitalization; does the tag use capital letters?
               
               

               
            

Legacy_zamiwas

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #7 on: January 02, 2012, 08:56:31 pm »


               Nope, everythings lowercase.  And it does work in a mod,  just not the oc.

I'll troubleshoot if its something wrong in the script
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #8 on: January 02, 2012, 09:02:21 pm »


               

zamiwas wrote...

Nope, everythings lowercase.  And it does work in a mod,  just not the oc.

I'll troubleshoot if its something wrong in the script


I found the problem.  I should have relooked and seen that you were using On-Hit unique power, the only custom script one that does not go through the activate item event.  HoTU replaces the normal custom script firing with its own set of events.

Go into "x2_s3_onhitcast"

Scroll to the bottom "else" command which looks like this:

else
   {
        // Error: Spell was not cast by an item
   }

Insert into this else command

ExecuteScript(GetTag(oItem), oSpellOrigin);
               
               

               


                     Modifié par WhiZard, 02 janvier 2012 - 09:03 .
                     
                  


            

Legacy_zamiwas

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #9 on: January 02, 2012, 09:39:27 pm »


               I tried editing the "x2_s3_onhitcast",   in the toolset,  and threw it in the override folder.
Even tried erasing everything and just putting your code,  but it still doesnt seem to be working
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #10 on: January 02, 2012, 09:49:55 pm »


               

zamiwas wrote...

I tried editing the "x2_s3_onhitcast",   in the toolset,  and threw it in the override folder.
Even tried erasing everything and just putting your code,  but it still doesnt seem to be working


The HotU's module script takes precedence over the override.  If you are limited to overrides, then you might want to change the spells.2da entry that calls "x2_s3_onhitcast", to have it call a different and not yet defined script,  then copy what is in "x2_s3_onhitcast" into that script and put the generic script caller into the else argument.

If you are not limited to overrides, copy the HotU modules from the "nwm" folder into the "modules" folder.  Rename the copied modules to be *.mod instead of *.nwm.  Then you can edit the *.mod entries and the game will show up under "Other Modules".
               
               

               


                     Modifié par WhiZard, 02 janvier 2012 - 09:54 .
                     
                  


            

Legacy_zamiwas

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #11 on: January 02, 2012, 10:32:05 pm »


               Edit:   
Ok I think I edited the spells.2da, and the new onhitcast script correctly.   But that isn't working.

So I tried doing the HotU as a Module,  edited the "x2_s3_onhitcast"  script as you described,  but its not working that way either.

Im probably missing something obvious,  meddling in unknown territory.   : /
               
               

               


                     Modifié par zamiwas, 03 janvier 2012 - 01:08 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #12 on: January 03, 2012, 01:13:39 am »


               First the scripts in the module do not override the override folder.  The override folder overrides the scripts in the module. EDIT:  I am wrong on that one.  Good thing I don't use the override folder much.  
The code inserted into x2_s3_onhitcast will probably be the best way to go as Whizard has sugested.  The only problen there is that he picked the wrong place in the script to place the code.   He also missed setting the userdefined event number if your script is checking for it.

Make the code look like this then compile it and place the  x2_s3_onhitcast.ncs into your override folder.

//::///////////////////////////////////////////////
//:: User Defined OnHitCastSpell code
//:: x2_s3_onhitcast
//:: Copyright © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
    This file can hold your module specific
    OnHitCastSpell definitions
    How to use:
    - Add the Item Property OnHitCastSpell: UniquePower (OnHit)
    - Add code to this spellscript (see below)
   WARNING!
   This item property can be a major performance hog when used
   extensively in a multi player module. Especially in higher
   levels, with each player having multiple attacks, having numerous
   of OnHitCastSpell items in your module this can be a problem.
   It is always a good idea to keep any code in this script as
   optimized as possible.

*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-22
//:://////////////////////////////////////////////
#include "x2_inc_switches"
//:: UPDATE August 5/03 - Add Goblin marker Arrows for Level 2 of Undermountain
void main()
{
   object oItem;        // The item casting triggering this spellscript
   object oSpellTarget; // On a weapon: The one being hit. On an armor: The one hitting the armor
   object oSpellOrigin; // On a weapon: The one wielding the weapon. On an armor: The one wearing an armor
   // fill the variables
   oSpellOrigin = OBJECT_SELF;
   oSpellTarget = GetSpellTargetObject();
   oItem        =  GetSpellCastItem();
   if (GetIsObjectValid(oItem))
   {
       // Add your desired behaviour here
       // Example: (make target burst in flames)
       // if (GetTag(oItem) == "my_cool_weapon")
       // {
       //    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_IMP_FLAME_M), oSpellTarget);
       // }
          //If a PC is hit by a goblin marker arrow - the Goblin chiefs switches will cause effects
          //on that pc (or associate)
        if (GetTag(oItem) == "q2cmarker")
        {
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_COM_HIT_ACID), oSpellTarget);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_COM_CHUNK_GREEN_MEDIUM), oSpellTarget);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_DUR_GLOW_GREEN), oSpellTarget, 30.0);
            if (GetLocalInt(oSpellTarget, "X2_Q2CGoblinMark") == 0)
            {
                SetLocalInt(oSpellTarget, "X2_Q2CGoblinMark", 1);
                FloatingTextStrRefOnCreature(84143 , oSpellTarget);
                object oArea = GetArea(oSpellTarget);
                AssignCommand(oArea, DelayCommand(30.0, SetLocalInt(oSpellTarget, "X2_Q2CGoblinMark", 0)));
            }
            return;
        }
        // * 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_ONHITCAST);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }
      }
   }
   else
   {
        // Error: Spell was not cast by an item
   }


Also keep in mind, before you try and start adding other Tag based Scripts to the OC, The modules are not set op for tag based scripting.   I also only checked one of the modules in the HoTU  if the other modules use different versions of the x2_s3_onhitcast script, you may introduce bugs into the game.   
               
               

               


                     Modifié par Lightfoot8, 03 janvier 2012 - 02:41 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #13 on: January 03, 2012, 01:44:28 am »


               

Lightfoot8 wrote...

First the scripts in the module do not override the override folder.  The override folder overrides the scripts in the module.


Umm...

The order from what I've been told many times is...

Module Scripts> Hak pak > override > core scripts

The HotU module inserted its own x2_s3_onhitcast to override the core x2_s3_onhitcast
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
[solved] Getting item and its script into OC
« Reply #14 on: January 03, 2012, 02:14:33 am »


               Well,  The test I just ran says you are right and I am wrong.    Back to running more tests.  Most likely I am wrong on that one though.