Author Topic: On Use check Equipable  (Read 374 times)

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
On Use check Equipable
« on: February 01, 2014, 05:47:03 pm »


                
I am interested in writing a new script. I think it would be useful to a few but I thought I would check to see if anyone had one before I wander off to create one. 

It would be inserted into your current OnActivate script and look at the baseitems.2da column that checks it it is equipable and to which slot. If it is and it is equipable and not currently occupying a slot it would be equiped automatically. 

The only thing that would make me stop and have to look is how to convert the information in 2da into a simple check for each slot. 

thoughts?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
On Use check Equipable
« Reply #1 on: February 01, 2014, 06:22:55 pm »


               of course you will need to pull the hex value from the 2da and convert it to an int.   well maybe a float all according to the way you want to go.



I assume you would want to first mask out the creature slots.   If that is the case with the number as an int you can remove them by doing a bit mask with 2FFF

example.  

nEQSlots = EQSlots & 0x2FFF;

Now with the creature slots removed from the number, I would just pull the largest bit to check if the slot is occupied.   You can do that with a log of the number divided by a log of 2.  ex

nTopSLot = FloatToInt ( log(nEQSlot*1.0) / log(2.0));

That will give you the hiegest bit still set in the number.  I am currently assuming that it will match with the constants in NWN for the slot number.  

If that slot is already occupied remove the bit for that slot and check to see if there is another equipable slot.  

You can remove the bit by toggling it off.

ex.
nEQSlot  = nEQSlot ^ (1<< nTopSlot);
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
On Use check Equipable
« Reply #2 on: February 01, 2014, 06:25:40 pm »


               How would that be different from putting it in a quickslot? I'm not sure why one would do this.

That said, the code to use that hex string in the 2da could be done it two ways. I recently wrote code to turn that string into an int. Once in that format you can use bit operations to see what slots are set.  The other way is simply to use a bunch of string comparisons.


int getCharHexVal(string sHex) {
       
        if (sHex == "1") return 1;
        else if (sHex == "2") return 2;
        else if (sHex == "3") return 3;
        else if (sHex == "4") return 4;
        else if (sHex == "5") return 5;
        else if (sHex == "6") return 6;
        else if (sHex == "7") return 7;
        else if (sHex == "8") return 8;
        else if (sHex == "9") return 9;
        else if (sHex == "A" || sHex == "a") return 10;
        else if (sHex == "B" || sHex == "b") return 11;
        else if (sHex == "C" || sHex == "c") return 12;
        else if (sHex == "D" || sHex == "d") return 13;
        else if (sHex == "E" || sHex == "e") return 14;
        else if (sHex == "F" || sHex == "f") return 15;

        return 0;

}

int HexStringToInt(string sHex) {
        sHex = GetStringUpperCase(sHex);
        if (GetStringLeft(sHex, 2) == "0X") {
                sHex = GetStringRight(sHex, GetStringLength(sHex) -2);
        }
        int nLoc = GetStringLength(sHex);
        if (nLoc < 1 || nLoc > 8)
                return 0;

        int nRes = 0;
        string sRest;

        while (nLoc > 0) {
                string tmp = GetStringLeft(sRest, 1);
                nRes = nRes * 16 + getCharHexVal(tmp);
                nLoc --;
                sRest = GetStringRight(sRest, nLoc);                    
        }
        return nRes;
}

Cheers,
Meaglyn
               
               

               
            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
On Use check Equipable
« Reply #3 on: February 02, 2014, 01:32:09 am »


               Thanks for the assistnace, I will dive in and see what I can come up with.

@meaglyn: The reason I want to do it this way is that it would presumably not need two quick slots, one to equip and one to activate the item. For realism I still want the item to be equipped to use but this will make it a little easier on the players by auto-equipping. Not sure if this is the best way to do it, but thought it was worth a try.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
On Use check Equipable
« Reply #4 on: February 02, 2014, 01:44:48 am »


               

DM_Vecna wrote...

Thanks for the assistnace, I will dive in and see what I can come up with.

@meaglyn: The reason I want to do it this way is that it would presumably not need two quick slots, one to equip and one to activate the item. For realism I still want the item to be equipped to use but this will make it a little easier on the players by auto-equipping. Not sure if this is the best way to do it, but thought it was worth a try.


Oh I see, that makes sense. I though you just wanted the activation as a way to get the item equipped, with no other use '<img'>
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
On Use check Equipable
« Reply #5 on: February 02, 2014, 12:39:14 pm »


               ? but how do you want to trigger it? Using a spell on an equippable item from quickslot does nothing if that item isnt equipped. No script is run so I dont get it...
               
               

               
            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
On Use check Equipable
« Reply #6 on: February 02, 2014, 05:40:01 pm »


               Ahh, I was not sure if the script ran or not. I had not gotten that far in testing. Thanks for the heads. up.

So to be cear, the activate item works but not the cast spell property.