Author Topic: Scripting Wizards Please Help  (Read 326 times)

Legacy_Electryc

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Scripting Wizards Please Help
« on: February 25, 2011, 03:25:27 pm »


                This script will not fire, any advice would be welcome.  Thanks!! 




effect eEffect;
object oTarget;

void main()
{
object oPC;

if ((GetObjectType(GetItemActivatedTarget())!=OBJECT_TYPE_CREATURE)
){

SendMessageToPC(GetItemActivator(), "You must target a creature for this power to work.");
return;}

oTarget = GetItemActivatedTarget();

if (WillSave(oPC, 13))
   {
   SendMessageToPC(oPC, "[SUCCESS MESSAGE]");

   oTarget = GetItemActivatedTarget();

   eEffect = EffectAttackDecrease(2);

   eEffect = SupernaturalEffect(eEffect);

   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 60.0f);

   eEffect = EffectSavingThrowDecrease(SAVING_THROW_ALL, 2, SAVING_THROW_TYPE_ALL);

   eEffect = SupernaturalEffect(eEffect);

   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 60.0f);

   eEffect = EffectSkillDecrease(SKILL_ALL_SKILLS, 2);

   eEffect = SupernaturalEffect(eEffect);

   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 60.0f);

   oTarget = oPC;

   eEffect = EffectAttackIncrease(1);

   eEffect = SupernaturalEffect(eEffect);

   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 60.0f);

   eEffect = EffectSavingThrowIncrease(SAVING_THROW_ALL, 1, SAVING_THROW_TYPE_ALL);

   eEffect = SupernaturalEffect(eEffect);

   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 60.0f);

   eEffect = EffectSkillIncrease(SKILL_ALL_SKILLS, 1);

   eEffect = SupernaturalEffect(eEffect);

   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 60.0f);

   }
else
   {
   SendMessageToPC(oPC, "[FAILURE MESSAGE]");

   }

}
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #1 on: February 25, 2011, 04:06:40 pm »


               I take it this is an activated item of some sort? Do you have Tag Based Scripting turned on? If so, did you name the script appropriately?
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #2 on: February 25, 2011, 04:18:10 pm »


               eg -

Tag of the Item =  wonder_wand

Script filename should be  wonder_wand



Also make sure you build/compile your module too, to refresh the scripts.
               
               

               
            

Legacy_Electryc

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #3 on: February 25, 2011, 05:04:11 pm »


               Thanks for the quick response, Ill give it a shot and report if that was the problem.
               
               

               
            

Legacy_Electryc

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #4 on: February 25, 2011, 05:22:13 pm »


               who knows doublechecked the tags they were correct, rebuilt mod.  Still it's failing to work.  The script itself may be the problem.

               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #5 on: February 25, 2011, 05:29:12 pm »


               I see where you say object oPC;  but I don't see where you declare exactly what "oPC" is to reference, right now it is nothing. It should probably be something like object oPC = GetItemActivator();

For simple testing to see if the script fires at all, add these lines to your script:

object oPC = GetFirstPC();
FloatingTextStringOnCreature("SCRIPT FIRED.", oPC);


Right after the lines:

void main()
{
object oPC;

That should at least let you know if the script is firing off or not. If the message floats above your PC's head, then script fired off. If it doesn't float there, script did not fire.
               
               

               


                     Modifié par _Knightmare_, 25 février 2011 - 05:37 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #6 on: February 25, 2011, 10:43:13 pm »


               Your largest problem is with oPC

object oPC;
This is as far as you go in defining oPC, therefore in the entire script oPC == OBJECT_INVALID

To make matters worse half way through the script you do this:
oTarget = oPC;
From this point on both oPC and oTarget are invalid objects.

The other problem I see without looking to deep is your will save.
if (WillSave(oPC, 13))
Of minor interest here is, why is the PC making the save. But then again since oPC is OBJECT_INVALID I guess I can not draw to much about who you want to make the save. The second problem with the will save, is that since this looks like a module event script, OBJECT_SELF will be the module. So you have  oPC(OBJECT_INVALID) making a save of DC13 versus OBJECT_SELF (the module) doing somthing to it.
               
               

               


                     Modifié par Lightfoot8, 25 février 2011 - 10:47 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #7 on: February 26, 2011, 12:25:42 am »


               Good points.  I think what you're trying to do is make an item which targets an enemy and does negative things to them and postive things to you, the item activator.  Something along these lines:

#include "x2_inc_switches"
void main()
{
 int nEvent =GetUserDefinedItemEventNumber();
     if (!nEvent == X2_ITEM_EVENT_ACTIVATE)
     return;
    object oPC = GetItemActivator();
    //target of the positive effects
    object oItem = GetItemActivated();
  
   //I always add the above as a matter of style, though it can often be useful
    //at some later point.  That is if you wanted to destroy the item on some % chance
    //or set an int on the item, for instance.

    object oTarget = GetItemActivatedTarget();
   //target of the ill effects.
if ((GetObjectType(GetItemActivatedTarget())!=OBJECT_TYPE_CREATURE)
)
{
 SendMessageToPC(oPC, "You must target a creature for this power to work.");
return;
}
 
if (WillSave(oPC, 13, SAVING_THROW_WILL))
   {
   SendMessageToPC(oPC, "[SUCCESS MESSAGE]");
  effect eEffect = EffectAttackDecrease(2);
  ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oTarget, 60.0f);
   effect eEffect1 = EffectSavingThrowDecrease(SAVING_THROW_ALL, 2, SAVING_THROW_TYPE_ALL);
   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect1, oTarget, 60.0f);
   effect eEffect2 = EffectSkillDecrease(SKILL_ALL_SKILLS, 2);
   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect2, oTarget, 60.0f);
   //now all the negative effects applied to the target creature, now apply positive effects
   //to the item activator, the Player Character.
   effect eEffect3 = EffectAttackIncrease(1);
   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect3, oPC, 60.0f);
   effect eEffect4 = EffectSavingThrowIncrease(SAVING_THROW_ALL, 1, SAVING_THROW_TYPE_ALL);
   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect4, oPC, 60.0f);
   effect eEffect5 = EffectSkillIncrease(SKILL_ALL_SKILLS, 1);
   ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect5, oPC, 60.0f);
   }
else
   {
   SendMessageToPC(oPC, "[FAILURE MESSAGE]");
   }
}
//I don't think you want the effects to be supernatural since they are temporary
//here is the description:
// Set the subtype of eEffect to Supernatural and return eEffect.
// (Effects default to magical if the subtype is not set)
// Permanent supernatural effects are not removed by resting!!!!!(therefore they are not temporary-ffbj)
//effect SupernaturalEffect(effect eEffect)

You realize of course that if the itme does not have limited uses the PC will be able to use it multiple times on a single creature.  There are ways around that, but just something to keep in mind.
One way would be to reduce the Will Save of the PC activator for a time  on each use so enevtually the item would not work too well.
               
               

               


                     Modifié par ffbj, 26 février 2011 - 12:32 .
                     
                  


            

Legacy_Rusticator

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #8 on: February 26, 2011, 12:37:47 pm »


               Hello all, thanks for the help. It's actually my script - the OP is a player in the campaign.

The script - as ffbj notes - is designed, on the failure of a will save, to apply a set penalty to a creature, and half of that penalty as a bonus to a PC.

I had noticed that I had managed to tangle up oTarget and oPC. It should be the target attempting the Will save, not the activator.

if (WillSave(oTarget, 13, SAVING_THROW_WILL))

I want the Effects to be supernatural to ensure that they cannot be dispelled. Is there a way to set all Effects to supernatural, or need I change every one?

The triggering item is 1/day, so I have no concerns about spamming.

Thanks again.
               
               

               


                     Modifié par Rusticator, 26 février 2011 - 12:48 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting Wizards Please Help
« Reply #9 on: February 26, 2011, 05:52:54 pm »


               I modified ffbj's  modification to your script a little but more for you.   I hope the comments in the script answer you question.



#include "x2_inc_switches"
void main()
{
 int nEvent =GetUserDefinedItemEventNumber();
 if (!nEvent == X2_ITEM_EVENT_ACTIVATE) return;

 //target of the positive effects
 object oPC = GetItemActivator();

 object oItem = GetItemActivated();
 //I always add the above as a matter of style, though it can often be useful
 //at some later point.  That is if you wanted to destroy the item on some % chance
 //or set an int on the item, for instance.

 //target of the ill effects.
 object oTarget = GetItemActivatedTarget();

  if(GetObjectType(GetItemActivatedTarget())!=OBJECT_TYPE_CREATURE)
  {
    SendMessageToPC(oPC, "You must target a creature for this power to work.");
    return;
  }
  if (WillSave(oTarget, 13, SAVING_THROW_WILL))
  {
    SendMessageToPC(oPC, "[SUCCESS MESSAGE]");

    // Create your effects.
    effect eEffect = EffectAttackDecrease(2);
    effect eEffect1 = EffectSavingThrowDecrease(SAVING_THROW_ALL, 2, SAVING_THROW_TYPE_ALL);
    effect eEffect2 = EffectSkillDecrease(SKILL_ALL_SKILLS, 2);

    //Link them together.
    effect eLink = EffectLinkEffects(eEffect,eEffect1);
           eLink = EffectLinkEffects(eLink,eEffect2);

    // Change the effect to the tyoe you want.
    eLink = ExtraordinaryEffect(eLink);

    // Apply the Effects as one effect
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, 60.0f);

    //now all the negative effects applied to the target creature, now apply positive effects
    //to the item activator, the Player Character.
    effect eEffect3 = EffectAttackIncrease(1);
    effect eEffect4 = EffectSavingThrowIncrease(SAVING_THROW_ALL, 1, SAVING_THROW_TYPE_ALL);
    effect eEffect5 = EffectSkillIncrease(SKILL_ALL_SKILLS, 1);

    // Link the effects.
    eLink = EffectLinkEffects(eEffect3,eEffect4);
    eLink = EffectLinkEffects(eLink,eEffect5);

    // Change the effect to the tyoe you want.
    eLink = ExtraordinaryEffect(eLink);

    // Apply the Effects as one effect
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, 60.0f);
  }
  else
  {
   SendMessageToPC(oPC, "[FAILURE MESSAGE]");
  }
}