Skip to content

Script Help... changing weapons/equipping weapons

CuChoinneachCuChoinneach Member Posts: 105
edited February 2013 in General Modding
Working on DSotSC and running into a bit of snag... thought I would seek some help in this matter.

I have a weapon that will change abilities whether it's day or night. So I have made two versions of the weapon.

I can get the weapon to change on the NPC, but he won't equip it. It's in his weapon slot but NOT in his hand.

Here is the script (I have appended this to baldur.bcs) ...using "weapon_d", "weapon_n" and "NPC" to avoid revealing spoilers. :)

IF
TimeOfDay(NIGHT)
HasItem("weapon_d","NPC")


THEN

RESPONSE #100

TakeItemReplace("weapon_d","weapon_n","NPC")
SetGlobal("WEAPON_SWAP","GLOBAL",1)

END

IF
TimeOfDay(DAY)
HasItem("weapon_n","NPC")


THEN

RESPONSE #100

TakeItemReplace("weapon_n","weapon_d","NPC")
SetGlobal("WEAPON_SWAP","GLOBAL",1)
END


.....This works so far! The part below, does not...


// Night Version Not Equiped
IF
ActionListEmpty()
HasItem("weapon_n","NPC")
Global("WEAPON_SWAP","GLOBAL",1)
!HasItemEquipedReal("weapon_n","NPC")

THEN
RESPONSE #100

EquipItem("weapon_n","NPC")
SelectWeaponAbility(SLOT_WEAPON,0)
SetGlobal("WEAPON_SWAP","GLOBAL",0)
END

// Night Version Equiped
IF
ActionListEmpty()
HasItem("weapon_n","NPC")
Global("WEAPON_SWAP","GLOBAL",1)
HasItemEquiped("weapon_n","NPC")

THEN
RESPONSE #100

SelectWeaponAbility(SLOT_WEAPON,0)
SetGlobal("WEAPON_SWAP","GLOBAL",0)
END

// Day Version Not Equiped
IF
ActionListEmpty()
HasItem("weapon_d","NPC")
Global("WEAPON_SWAP","GLOBAL",1)
!HasItemEquipedReal("weapon_d","NPC")

THEN
RESPONSE #100

EquipItem("weapon_d","NPC")
SelectWeaponAbility(SLOT_WEAPON,0)
SetGlobal("WEAPON_SWAP","GLOBAL",0)
END

// Day Version Equiped
IF
ActionListEmpty()
HasItem("weapon_d","NPC")
Global("WEAPON_SWAP","GLOBAL",1)
HasItemEquiped("weapon_d","NPC")

THEN
RESPONSE #100

SelectWeaponAbility(SLOT_WEAPON,0)
SetGlobal("WEAPON_SWAP","GLOBAL",0)
END


Any suggestions?

Thanks!
Post edited by CuChoinneach on

Comments

  • horredtheplaguehorredtheplague Member, Developer Posts: 186
    Equipping specific weapons in IE scripting is problematic at best. EquipItem(S:Object*) has only one parameter not two, in the IDS file. Odd how it accepts both item RES and script variable. It's a tough one to get working though; despite the example given in IEDSP it's more commonly used for quickslot items. Their script might possibly work if there were no weapons in any slots.

    If you can determine which slot the weapon is in with a series of GetItemInSlot checks, chances are you could use FillSlot to switch them over. Try DestroyItem and CreateItem in place of TakeItemReplace, also. Perhaps you can go further by trying UseItemSlot...maybe this will equip it by default. The reason that you have to determine which slot with FillSlot is because it destroys anything already in the slot before adding the new item--your sword could be in any one of up to 4 slots depending on player choice. Hells, try FillSlot and then EquipItem, too--might take a combination effort.

    The only very reliable way to equip any weapon is with EquipMostDamagingMelee() and EquipRanged(), but this is too general for your needs. Unless you know your blade will do more damage than the others a player may equip. You may just get stuck on this one, sorry.
  • CuChoinneachCuChoinneach Member Posts: 105
    I fixed it... :)

    I made two spells that creates the weapon for day and night version... then in Baldur.bsc appended the following:

    IF
    TimeOfDay(NIGHT)
    HasItem("weapon_d","NPC")


    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_nightversion"))
    SetGlobal("MYWEAPON","GLOBAL",1)
    Continue()

    END

    IF
    TimeOfDay(DAY)
    HasItem("weapon_n","NPC")


    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_dayversion"))
    SetGlobal("MYWEAPON","GLOBAL",1)
    Continue()
    END




    Then in a script I added to the NPC Overide:


    // Equip Day Version
    IF
    ActionListEmpty()
    HasItem("weapon_d",Myself)
    Global("MYWEAPON","GLOBAL",1)

    THEN
    RESPONSE #100

    FillSlot(SLOT_WEAPON0)
    EquipMostDamagingMelee()
    SetGlobal("MYWEAPON","GLOBAL",0)
    Continue()
    END


    // Night Version Equip
    IF
    ActionListEmpty()
    HasItem("weapon_n",Myself)
    Global("MYWEAPON","GLOBAL",1)

    THEN
    RESPONSE #100

    FillSlot(SLOT_WEAPON0)
    EquipMostDamagingMelee()
    SetGlobal("MYWEAPON","GLOBAL",0)
    Continue()
    END



    Seems to work perfectly!
  • horredtheplaguehorredtheplague Member, Developer Posts: 186
    @CuChoinneach : Did you test with your special sword in the second/third/fourth slot, and some other weapon in SLOT_WEAPON0? That's the side of this scenario that worried me, and why I suggested a GetItemInSlot() check. It would just be replacing your HasItem() check, and the block would need to be replicated 4 times (one for each weapon slot). The spell is a nice touch, however :)
  • CuChoinneachCuChoinneach Member Posts: 105
    @horredtheplague Thanks, I'll give a try. I went with the spell so that the party would not keep getting the message "party has gained a new item" message. The spell just makes things cleaner. :)
  • CuChoinneachCuChoinneach Member Posts: 105
    @horredtheplague GetItemInSlot() appears to be a NWN script element. :/
  • horredtheplaguehorredtheplague Member, Developer Posts: 186
    edited February 2013
    TRIGGER.IDS: 0x40b2: HasItemSlot(O:Object*,I:SLOTS*) Not nearly as effective as the NWN equivalent, it doesn't tell what you have in the slot only that you have something there. (or not there...) It could prevent you from destroying a wrong item via FillSlot(), perhaps? What you do is find an empty slot, w/ these checks starting @ SLOT_WEAPON0 and checking through SLOT_WEAPON3. The sword should have been removed from the first available empty slot.

    This might take two spells to accomplish, one to Destroy the old and one to Create the new (at different times), but won't ever destroy the players' +1Longbow (etc) in the effort.
  • CuChoinneachCuChoinneach Member Posts: 105
    @horredtheplague Thanks... I should be able to do something with that! :)
  • CuChoinneachCuChoinneach Member Posts: 105
    edited February 2013
    @horredtheplague I'll give this a try!


    //---- To Remove Weapon THAT IS IN A QUICK SLOT ----

    IF

    TimeOfDay(NIGHT)
    Global("MYWEAPON","GLOBAL",0)
    HasItem("weapon_d","NPC")
    HasItemEquiped("weapon_d","NPC")

    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_removedayversion"))
    Continue()

    END


    //---- To Remove and CREATE Weapon THAT IS IN INVENTORY ONLY  ----

    IF

    TimeOfDay(NIGHT)
    Global("MYWEAPON","GLOBAL",0)
    HasItem("weapon_d","NPC")
    !HasItemEquiped("weapon_d","NPC")

    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_removedayandcreatenightversion"))
    Continue()
    SetGlobal("MYWEAPON","GLOBAL",1)

    END

    //---- Find Empty Slot to Create Weapon ----

    IF

    TimeOfDay(NIGHT)
    Global("MYWEAPON","GLOBAL",0)
    !HasItemSlot("NPC",SLOT_WEAPON0)

    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_createnightversion"))
    SetGlobal("MYWEAPON","GLOBAL",1)
    Continue()

    END

    IF

    TimeOfDay(NIGHT)
    Global("MYWEAPON","GLOBAL",0)
    !HasItemSlot("NPC",SLOT_WEAPON1)
    !HasItem("weapon_n","NPC")

    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_createnightversion"))
    SetGlobal("MYWEAPON","GLOBAL",1)
    Continue()

    END

    IF

    TimeOfDay(NIGHT)
    Global("MYWEAPON","GLOBAL",0)
    !HasItemSlot("NPC",SLOT_WEAPON2)
    !HasItem("weapon_n","NPC")

    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_createnightversion"))
    SetGlobal("MYWEAPON","GLOBAL",1)
    Continue()

    END

    IF

    TimeOfDay(NIGHT)
    Global("MYWEAPON","GLOBAL",0)
    !HasItemSlot("NPC",SLOT_WEAPON3)
    !HasItem("weapon_n","NPC")

    THEN

    RESPONSE #100

    ActionOverride("NPC",ApplySpellRES("spell_createnightversion"))
    SetGlobal("MYWEAPON","GLOBAL",1)
    Continue()

    END



    This should do it... :)
    Post edited by CuChoinneach on
Sign In or Register to comment.