Author Topic: item scripting prob  (Read 611 times)

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« on: May 16, 2012, 10:26:17 pm »


               i am trying to create an effect of a book that when used will start a conversation.  I have had problems trying to get it to work so i search and searched an found that u cant have a conversation on and item so i was trying to have the book create and invisible placeable that will fire the conversation.  I can get the item to create the placeable but cant get the placeable to become invisible or the conversation to fire.  Please help here is the code that im using. Oh and this script is run by a unique power self on the book

#include "x2_inc_switches"
#include "x0_i0_position"
location GetStepOppositeLocation(object oTarget);
  effect invs;
   object book;
void main()
{
    int nEvent = GetUserDefinedItemEventNumber();    //Which event triggered this
    object oPC;                                                           //The player character using the item
    object oItem;                                                        //The item being used
    object oSpellOrigin;                                               //The origin of the spell
    object oSpellTarget;                                              //The target of the spell
    int iSpell;                                                             //The Spell ID number
    //Set the return value for the item event script
    // * X2_EXECUTE_SCRIPT_CONTINUE - continue calling script after executed script is done
    // * X2_EXECUTE_SCRIPT_END - end calling script after executed script is done
    int nResult = X2_EXECUTE_SCRIPT_END;
    switch (nEvent)
    {
        case X2_ITEM_EVENT_ONHITCAST:
            // * This code runs when the item has the 'OnHitCastSpell: Unique power' property
            // * and it hits a target(if it is a weapon) or is being hit (if it is a piece of armor)
            // * Note that this event fires for non PC creatures as well.
            oItem  =  GetSpellCastItem();               // The item triggering this spellscript
            oPC = OBJECT_SELF;                            // The player triggering it
            oSpellOrigin = OBJECT_SELF ;               // Where the spell came from
            oSpellTarget = GetSpellTargetObject();  // What the spell is aimed at
            //Your code goes here
            break;
        case X2_ITEM_EVENT_ACTIVATE:
// * This code runs when the Unique Power property of the item is used or the item
// * is activated. Note that this event fires for PCs only
            oPC   = GetItemActivator();                 // The player who activated the item
            oItem = GetItemActivated();               // The item that was activated
           /// ActionStartConversation(oPC,"mgbook_conv", TRUE, TRUE);
           CreateObject(OBJECT_TYPE_PLACEABLE, "mageguildbookinv", GetStepOppositeLocation(oPC),FALSE,"magebookinv");
                 AssignCommand(GetObjectByTag("magebookinv"),ApplyEffectToObject
           (DURATION_TYPE_PERMANENT,EffectInvisibility(INVISIBILITY_TYPE_IMPROVED),GetObjectByTag("magebookinv")));
                AssignCommand(GetObjectByTag("magebookinv"), ActionStartConversation(oPC, "mgbook_conv", TRUE));
            //Your code goes here
            break;
        case X2_ITEM_EVENT_EQUIP:
            // * This code runs when the item is equipped
            // * Note that this event fires for PCs only
            oPC = GetPCItemLastEquippedBy();        // The player who equipped the item
            oItem = GetPCItemLastEquipped();         // The item that was equipped
            //Your code goes here
            break;
        case X2_ITEM_EVENT_UNEQUIP:
            // * This code runs when the item is unequipped
            // * Note that this event fires for PCs only
            oPC    = GetPCItemLastUnequippedBy();   // The player who unequipped the item
            oItem  = GetPCItemLastUnequipped();      // The item that was unequipped
            //Your code goes here
            break;
        case X2_ITEM_EVENT_ACQUIRE:
            // * This code runs when the item is acquired
            // * Note that this event fires for PCs only
            oPC = GetModuleItemAcquiredBy();        // The player who acquired the item
            oItem  = GetModuleItemAcquired();        // The item that was acquired
            //Your code goes here
            break;
        case X2_ITEM_EVENT_UNACQUIRE:
            // * This code runs when the item is unacquired
            // * Note that this event fires for PCs only
            oPC = GetModuleItemLostBy();            // The player who dropped the item
            oItem  = GetModuleItemLost();            // The item that was dropped
            //Your code goes here
            break;
       case X2_ITEM_EVENT_SPELLCAST_AT:
            //* This code runs when a PC or DM casts a spell from one of the
            //* standard spellbooks on the item
            oPC = OBJECT_SELF;                          // The player who cast the spell
            oItem  = GetSpellTargetObject();        // The item targeted by the spell
            iSpell = GetSpellId();                         // The id of the spell that was cast
                                                                    // See the list of SPELL_* constants
            //Your code goes here
            //Change the following line from X2_EXECUTE_SCRIPT_CONTINUE to
            //X2_EXECUTE_SCRIPT_END if you want to prevent the spell that was
            //cast on the item from taking effect
            nResult = X2_EXECUTE_SCRIPT_CONTINUE;
            break;
    }
    //Pass the return value back to the calling script
    SetExecutedScriptReturnValue(nResult);
}
 location GetStepOppositeLocation(object oTarget)
{
    float fDir = GetFacing(oTarget);
    float fAngleOpposite = GetOppositeDirection(fDir);
    return GenerateNewLocation(oTarget,
                               DISTANCE_TINY,
                               fDir,
                               fAngleOpposite);
}
 
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
item scripting prob
« Reply #1 on: May 16, 2012, 11:06:33 pm »


               Easiest way to do this, make a new blueprint using the "Invisible Object" found under the Misc drop down. Give it the tag you want and the conversation you want. Then your chunk of code should look like this:


case X2_ITEM_EVENT_ACTIVATE:
// * This code runs when the Unique Power property of the item is used or the item
// * is activated. Note that this event fires for PCs only
oPC   = GetItemActivator();                 // The player who activated the item
oItem = GetItemActivated();               // The item that was activated
location lLoc = GetLocation(oPC);
object oBook = CreateObject(OBJECT_TYPE_PLACEABLE, "mageguildbookinv", lLoc, FALSE, "magebookinv");

AssignCommand(oPC, ActionStartConversation(oBook, "", TRUE));
break;

Good luck.
               
               

               


                     Modifié par GhostOfGod, 16 mai 2012 - 10:07 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
item scripting prob
« Reply #2 on: May 16, 2012, 11:28:15 pm »


               I usually just have the PC converse with themselves for items, but it depends entirely what sort of effect you're trying to achieve with the conversation if that's a valid method in this instance.
               
               

               
            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #3 on: May 17, 2012, 12:02:29 am »


               i have tried to have the pc converse with themselves but it woulnt work from the book.  This is the code i had used

AssignCommand(oPC, ActionStartConversation(oPC, "mgbook_conv", TRUE));
               
               

               
            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #4 on: May 17, 2012, 12:03:12 am »


               ill try yours now ghost
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
item scripting prob
« Reply #5 on: May 17, 2012, 12:39:08 am »


               

delmetry wrote...

i have tried to have the pc converse with themselves but it woulnt work from the book. This is the code i had used


AssignCommand(oPC, ActionStartConversation(oPC, "mgbook_conv", TRUE));



AssignCommand(oPC,ClearAllActions());
AssignCommand(oPC, ActionStartConversation(oPC, "mgbook_conv", TRUE));
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
item scripting prob
« Reply #6 on: May 17, 2012, 12:46:32 am »


               hmm,  I just a s simple  obvious thought.

If you used one of the cep equipable books, you could start the conversation onEquip and unequip the book on conversation end.
               
               

               
            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #7 on: May 17, 2012, 12:53:51 am »


               ghost and light...neither will still work...i even tried ghosts in a new mod. with no haks and nothing
               
               

               
            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #8 on: May 17, 2012, 12:56:21 am »


               also ghost i had to declare location iLoc and object oBook or else i was getting errors..just fyi
               
               

               
            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #9 on: May 17, 2012, 12:57:26 am »


               hmm ill take a look at that light
               
               

               
            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #10 on: May 17, 2012, 01:16:47 am »


               sigh...i made a copy of the equipable book renamed it made a new script to match the books tag and added the conversation script that the pc talks to himself to the on equip part and still nothing
               
               

               
            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #11 on: May 17, 2012, 01:23:42 am »


               nm guys i figured it out...omg im dumb...the conversation was invalid cause i had it just saying test and another saying done...never had a response in them...i had just thought of it out of nowhere... can u tell im just getting back into this after 5 years..lol....thank you all for your help you were all great
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
item scripting prob
« Reply #12 on: May 17, 2012, 01:27:50 am »


               

GhostOfGod wrote...
location lLoc = GetLocation(oPC);
object oBook = CreateObject(OBJECT_TYPE_PLACEABLE, "mageguildbookinv", lLoc, FALSE, "magebookinv");

delmetry wrote...

also ghost i had to declare location iLoc and object oBook or else i was getting errors..just fyi


???
               
               

               


                     Modifié par GhostOfGod, 17 mai 2012 - 12:33 .
                     
                  


            

Legacy_delmetry

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
item scripting prob
« Reply #13 on: May 17, 2012, 01:35:59 am »


               I had to declare them before the switch or i was getting error on the next case
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
item scripting prob
« Reply #14 on: May 17, 2012, 01:39:14 am »


               Oooohh. Cause it's a switch/case. Duh. I'm just so used to doing it if/then style I didn't even think of it. Sorry bout that.