Author Topic: Something not right with script  (Read 359 times)

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Something not right with script
« on: April 18, 2011, 05:41:31 pm »


               I am using this script to restrict use of certain items,

#include "x2_inc_switches"
void main()
{
object oPC;
oPC = GetPCItemLastEquippedBy();
object oItem;
int nSlot;
//If not level 40, unequip the item!
if(GetHitDice(oPC)<=39)
 {
    for (nSlot=0; nSlot<NUM_INVENTORY_SLOTS; nSlot++)
    {
        oItem=GetItemInSlot(nSlot, oPC);
        if (GetIsObjectValid(oItem))
        {
         //Unequip all items tag named "epic"
         if(GetTag(oItem) == "epic")
          {
          AssignCommand(oPC, ActionUnequipItem(oItem));
          FloatingTextStringOnCreature
          ("You are not level 40 and cannot use this item!", oPC);
          }
         else
         { }
        }
    }
 }
}



When players equip the items it unequips it right away,  thing is when they try to equipe it the second time it allows this ????
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Something not right with script
« Reply #1 on: April 18, 2011, 06:35:59 pm »


               #include "x2_inc_switches"
void main()
{
   object oPC;
   oPC = GetPCItemLastEquippedBy();
   object oItem = GetPCItemLastEquipped();

    //If not level 40, unequip the item!
    if(GetHitDice(oPC)<=39) 
   {
       AssignCommand(oPC, ClrarAllActions(TRUE));
       AssignCommand(oPC, ActionUnequipItem(oItem));
       AssignCommand(oPC, ActionDoCommand(SetCommandable(TRUE)));
       SetCommandable(FALSE,oPC);
   }
}


I am currently not near the toolset, SO sorry  if it does not compile right the first time. 

There Is no need to search for the item.   GetPCItemLastEquipped(); will return the correct item that triggered the event without a search.    We also set the PC uncommandable untill he has unequiped the item.  This way he can not do anything so clear his action of unequiping it.
 

Edit:  Now that I look at the script again.  If you are running the script as a TagBasedScript  you will also need a check for the Event that is runnung the script.  If you are running it directly in the module Event you will need  some kind of filter for the item, Such as the Tag, Or else the will not be able to equip any item. 

  
               
               

               


                     Modifié par Lightfoot8, 19 avril 2011 - 02:01 .
                     
                  


            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Something not right with script
« Reply #2 on: April 18, 2011, 09:52:43 pm »


               Thanks for the reply, I still have the same problem. the first time I try to equip the item all is good, second time i try it equips the item but its shaded out but still usable.
               
               

               
            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Something not right with script
« Reply #3 on: April 18, 2011, 09:58:59 pm »


               Ok just checked again and it looks as if its been equiped but does not apply enhancements
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Something not right with script
« Reply #4 on: April 18, 2011, 10:21:43 pm »


               Close your Character window and reopen it.   What you are seing is either  a Display Bug. Or a problem with the script trying to unequip again on the unequip event.

Note my Edit Above.  Your script is not compleate.  In order compleate it, I would have to know How you are running it.   Is it a TagBased Script Or entered directly into the OnEquip Event Script.

Either Was once an Item Grays out just close the character Screen and reopen it.  The Item is not really equipted.   It is Que-ed up to get equipted but something is stopping it.  In this case it is your script that is stopping it.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Something not right with script
« Reply #5 on: April 18, 2011, 10:33:06 pm »


               I will assume that you are useing it as a TagBasedScript.  in that case it should look like this. 

#include "x2_inc_switches"
void main()
{
   if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_UNEQUIP) return;
   object oPC;
   oPC = GetPCItemLastEquippedBy();
   object oItem = GetPCItemLastEquipped();

    //If not level 40, unequip the item!
    if(GetHitDice(oPC)<=39)
   {
       AssignCommand(oPC, ClearAllActions(TRUE));
       AssignCommand(oPC, ActionUnequipItem(oItem));
       AssignCommand(oPC, ActionDoCommand(SetCommandable(TRUE)));
       SetCommandable(FALSE,oPC);
   }
}


               
               

               


                     Modifié par Lightfoot8, 19 avril 2011 - 02:01 .