Author Topic: Equipping Hat removes Helm script  (Read 423 times)

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Equipping Hat removes Helm script
« on: March 23, 2011, 07:02:23 pm »


               I'd like to make use of the CEP cloak based hats in a module. I don't want them being stacked with helms though. How would I OnEquip for the Hat, autoremove any equipped helms? Yes, tag based scripting is enabled. Thanks as always.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Equipping Hat removes Helm script
« Reply #1 on: March 23, 2011, 08:23:52 pm »


               A few different ways you could do this. Not sure how many hats are available since I never used em. You could make a tagbased script for each hat. Or you could give all the hats the same tag(assuming you don't need to use the tags for anything else) or you could add a piece of code to your modules OnPlayerEquip script with a list of all the tags and perform the actions there.

I'm going to take the simplest route here and just say that all the hat tags will be the same.
This script does not need any checks for cloak or tag because it is a tag based script we already know it is a cloak and its tag. This will automaitcally remove a helmet if one of the cloak/hats is equipped.

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

    object oPC = GetPCItemLastEquippedBy();
    object oHelm = GetItemInSlot(INVENTORY_SLOT_HEAD, oPC);
    AssignCommand(oPC, ActionUnequipItem(oHelm));
}

NOTE: This will be a bit trickier in reverse. If someone equips a helmet then the cloak should be removed if it's tag is that of the cloak/hat (again using the same tag for all the hats will come in handy here). This would probably be best if it were a piece of code added to the OnPlayerEquipItem.

Hope that helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 23 mars 2011 - 08:36 .
                     
                  


            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Equipping Hat removes Helm script
« Reply #2 on: March 23, 2011, 08:40:39 pm »


               Yeah, I'll likely add it there. Thanks. Was suffering a massive brain fart earlier and couldn't recall how to check an invetory slot. Thanks .. GoG = Gassex for the Brain '<img'>
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Equipping Hat removes Helm script
« Reply #3 on: March 23, 2011, 08:47:27 pm »


               Haha. No problem. While I was at it I went ahead and did a reverse bit.

I just added this to the default nwn OnPlayerEquipItem. Something like this should work:

void main()
{

    object oItem = GetPCItemLastEquipped();
    object oPC   = GetPCItemLastEquippedBy();

    if (GetBaseItemType(oItem) == BASE_ITEM_HELMET)
    {
        object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC);
        if (GetTag(oCloak) == "TAG OF HAT/CLOAK HERE")
        AssignCommand(oPC, ActionUnequipItem(oCloak));
    }
   
    etc.....
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Equipping Hat removes Helm script
« Reply #4 on: April 15, 2011, 04:25:20 pm »


               OK ... time to complicate things. I'm using the following to force PCs to not wear a cloak based hat and a helm at the same time and it's working fine.

Working code for my module's OnEquip posted for others to make use of. Players are liking it so far. '<img'> Special thanks to GoG above for the previous help too.

**Code includes timed torches which can be easilly deleted if you don't use them already
#include "loc_inc_torches"

void main()
{
ExecuteScript ("x2_mod_def_equ",OBJECT_SELF);

object oItem = GetPCItemLastEquipped();
object oPC = GetPCItemLastEquippedBy();
if (GetTag(oItem) == "NW_IT_TORCH001")
{
TorchPrep(oItem);
}
else if (GetBaseItemType(oItem) == BASE_ITEM_HELMET)
{
object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC);
if (GetTag(oCloak) == "kal_hat")
AssignCommand(oPC, ActionUnequipItem(oCloak));
SendMessageToPC(oPC, "You cannot equip both a helm and a hat");
}
else if (GetBaseItemType(oItem) == BASE_ITEM_CLOAK &&GetTag(oItem) == "kal_hat" )
{
object oHelm = GetItemInSlot(INVENTORY_SLOT_HEAD, oPC);
AssignCommand(oPC, ActionUnequipItem(oHelm));
SendMessageToPC(oPC, "You cannot equip both a helm and a hat");
}
}

What I'd like to do next is to convert the tags of cloaks that use one of the two hat appearances to the proper tag to catch older items PCs may have already (rows 20 & 70 in my cloak appearance 2da). Ideally used in the OnEnter of a trigger which I'll place in my starting area. So I need a script that will search inventory and retag any base item cloak that uses only those appearances and likely set it as a once per PC check.

Any help is greatly appreciated.
               
               

               


                     Modifié par kalbaern, 15 avril 2011 - 03:26 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Equipping Hat removes Helm script
« Reply #5 on: April 15, 2011, 10:46:11 pm »


               The only way you can change the tags of items is to create a new item and give it a specific tag. So you could either do some more tag based scripts for each of these older items or you could add a chunk of script to your OnPlayerEquipItem script listing the tags of these older items, that creates a new item based on the res ref of the last equipped and gives the item your new tag, then destroys the old one and reequips the new one.

Something like this as an example of a tag based:


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

    object oItem = GetPCItemLastEquipped();
    object oPC = GetPCItemLastEquippedBy();
    string sResRef = GetResRef(oItem);
    object oNewItem = CreateItemOnObject(sResRef, oPC, 1, "NEW_TAG_HERE");

    DestroyObject(oItem, 0.1);
    AssignCommand(oPC, ActionEquipItem(oNewItem, INVENTORY_SLOT_CLOAK));
}

And then theoretically your script above would fire because you just equpped the new item with the new tag. Something like that anyway. Hope it helps.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Equipping Hat removes Helm script
« Reply #6 on: April 16, 2011, 01:33:18 am »


               I normally do the Updating of old stuff in the OnClient Enter Event.  That is just me, I find it eaiser to find again if I need to modify it again.  A trigger in the starting area works just as well.  

The way I handle it is by giving the PC a version number stored on a DB item in there inventory.  An extrenal DB entry would work just as well if that is what you use.   Any way everytime a PC enters the module I check there version number.   If there version is current I just return out of the function.   If there version is less then current I run the code to take them from there current version to the next version and repeat untill there version is current.  

Now that system may not work for you current situation, I you have ant persistant storage for your players on you server, a one time check of the PC will not catch an item when the PC logs in then retrives an item from the DB.   if that is the case a TagBased script for the items in question would be a better solution, That is if you know all of there Tags.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Equipping Hat removes Helm script
« Reply #7 on: April 16, 2011, 03:58:24 pm »


               OK ... my issue is how if possible would I determine that in this case . .a cloak when equipped uses one of my two hat appearances? There's no list of tags as the the PW this is for had many gifted by DMs or the appearance of a cloak changed by a player during a window where that was allowed.