Jump to content

Scripting: UnequipItem crashing Oblivion


McMutton

Recommended Posts

Hey guys. I'm working on some scripts that will have my armour and weapon level up with my character. They are as follows:

 

Armour

Scriptname BerserkLevelArmour

 

Begin GameMode

 

if Player.getlevel == 3

player.unequipitem SKBerserkWolfGreavesLV1

player.unequipitem SKBerserkWolfCuirassLV1

player.unequipitem SKBerserkWolfBootsLV1

player.removeitem SKBerserkWolfGreavesLV1 1

player.removeitem SKBerserkWolfCuirassLV1 1

player.removeitem SKBerserkWolfBootsLV1 1

player.removeitem SKBerserkWolfHelmetLV1 1

player.removeitem SKBerserkWolfGauntletsLV1 1

player.additem SKBerserkWolfGreavesLV2 1

player.additem SKBerserkWolfCuirassLV2 1

player.additem SKBerserkWolfBootsLV2 1

player.additem SKBerserkWolfHelmetLV2 1

player.additem SKBerserkWolfGauntletsLV2 1

player.equipitem SKBerserkWolfGreavesLV2

player.equipitem SKBerserkWolfCuirassLV2

player.equipitem SKBerserkWolfBootsLV2

 

endif

 

if Player.getlevel == 6

player.unequipitem SKBerserkWolfGreavesLV2

player.unequipitem SKBerserkWolfCuirassLV2

player.unequipitem SKBerserkWolfBootsLV2

player.removeitem SKBerserkWolfGreavesLV2 1

player.removeitem SKBerserkWolfCuirassLV2 1

player.removeitem SKBerserkWolfBootsLV2 1

player.removeitem SKBerserkWolfHelmetLV2 1

player.removeitem SKBerserkWolfGauntletsLV2 1

player.additem SKBerserkWolfGreavesLV3 1

player.additem SKBerserkWolfCuirassLV3 1

player.additem SKBerserkWolfBootsLV3 1

player.additem SKBerserkWolfHelmetLV3 1

player.additem SKBerserkWolfGauntletsLV3 1

player.equipitem SKBerserkWolfGreavesLV3

player.equipitem SKBerserkWolfCuirassLV3

player.equipitem SKBerserkWolfBootsLV3

 

endif

 

if Player.getlevel == 10

player.unequipitem SKBerserkWolfGreavesLV3

player.unequipitem SKBerserkWolfCuirassLV3

player.unequipitem SKBerserkWolfBootsLV3

player.removeitem SKBerserkWolfGreavesLV3 1

player.removeitem SKBerserkWolfCuirassLV3 1

player.removeitem SKBerserkWolfBootsLV3 1

player.removeitem SKBerserkWolfHelmetLV3 1

player.removeitem SKBerserkWolfGauntletsLV3 1

player.additem SKBerserkWolfGreavesLV4 1

player.additem SKBerserkWolfCuirassLV4 1

player.additem SKBerserkWolfBootsLV4 1

player.additem SKBerserkWolfHelmetLV4 1

player.additem SKBerserkWolfGauntletsLV4 1

player.equipitem SKBerserkWolfGreavesLV4

player.equipitem SKBerserkWolfCuirassLV4

player.equipitem SKBerserkWolfBootsLV4

 

endif

 

if Player.getlevel == 14

player.unequipitem SKBerserkWolfGreavesLV4

player.unequipitem SKBerserkWolfCuirassLV4

player.unequipitem SKBerserkWolfBootsLV4

player.removeitem SKBerserkWolfGreavesLV4 1

player.removeitem SKBerserkWolfCuirassLV4 1

player.removeitem SKBerserkWolfBootsLV4 1

player.removeitem SKBerserkWolfHelmetLV4 1

player.removeitem SKBerserkWolfGauntletsLV4 1

player.additem SKBerserkWolfGreavesLV5 1

player.additem SKBerserkWolfCuirassLV5 1

player.additem SKBerserkWolfBootsLV5 1

player.additem SKBerserkWolfHelmetLV5 1

player.additem SKBerserkWolfGauntletsLV5 1

player.equipitem SKBerserkWolfGreavesLV5

player.equipitem SKBerserkWolfCuirassLV5

player.equipitem SKBerserkWolfBootsLV5

 

 

endif

 

if Player.getlevel == 18

player.unequipitem SKBerserkWolfGreavesLV5

player.unequipitem SKBerserkWolfCuirassLV5

player.unequipitem SKBerserkWolfBootsLV5

player.removeitem SKBerserkWolfGreavesLV5 1

player.removeitem SKBerserkWolfCuirassLV5 1

player.removeitem SKBerserkWolfBootsLV5 1

player.removeitem SKBerserkWolfHelmetLV5 1

player.removeitem SKBerserkWolfGauntletsLV5 1

player.additem SKBerserkWolfGreavesLV6 1

player.additem SKBerserkWolfCuirassLV6 1

player.additem SKBerserkWolfBootsLV6 1

player.additem SKBerserkWolfHelmetLV6 1

player.additem SKBerserkWolfGauntletsLV6 1

player.equipitem SKBerserkWolfGreavesLV6

player.equipitem SKBerserkWolfCuirassLV6

player.equipitem SKBerserkWolfBootsLV6

 

 

endif

 

if Player.getlevel == 23

player.unequipitem SKBerserkWolfGreavesLV1

player.unequipitem SKBerserkWolfCuirassLV1

player.unequipitem SKBerserkWolfBootsLV1

player.removeitem SKBerserkWolfGreavesLV1 1

player.removeitem SKBerserkWolfCuirassLV1 1

player.removeitem SKBerserkWolfBootsLV1 1

player.removeitem SKBerserkWolfHelmetLV1 1

player.removeitem SKBerserkWolfGauntletsLV1 1

player.additem SKBerserkWolfGreavesLV2 1

player.additem SKBerserkWolfCuirassLV2 1

player.additem SKBerserkWolfBootsLV2 1

player.additem SKBerserkWolfHelmetLV2 1

player.additem SKBerserkWolfGauntletsLV2 1

player.equipitem SKBerserkWolfGreavesLV2

player.equipitem SKBerserkWolfCuirassLV2

player.equipitem SKBerserkWolfBootsLV2

player.equipitem SKBerserkWolfHelmetLV2

player.equipitem SKBerserkWolfGauntletsLV2

 

 

endif

 

end

 

Sword

 

Scriptname BerserkLevelSword

 

Begin GameMode

 

if Player.getlevel == 2

player.unequipitem SKBerserkDSLV1

player.removeitem SKBerserkDSLV1 1

player.additem SKBerserkDSLV2 1

player.equipitem SKBerserkDSLV2

 

endif

 

if Player.getlevel == 4

player.unequipitem SKBerserkDSLV2

player.removeitem SKBerserkDSLV2 1

player.additem SKBerserkDSLV3 1

player.equipitem SKBerserkDSLV3

 

endif

 

if Player.getlevel == 8

player.unequipitem SKBerserkDSLV3

player.removeitem SKBerserkDSLV3 1

player.additem SKBerserkDSLV4 1

player.equipitem SKBerserkDSLV4

 

endif

 

if Player.getlevel == 11

player.unequipitem SKBerserkDSLV4

player.removeitem SKBerserkDSLV4 1

player.additem SKBerserkDSLV5 1

player.equipitem SKBerserkDSLV5

 

 

endif

 

if Player.getlevel == 13

player.unequipitem SKBerserkDSLV5

player.removeitem SKBerserkDSLV5 1

player.additem SKBerserkDSLV6 1

player.equipitem SKBerserkDSLV6

 

 

endif

 

if Player.getlevel == 16

player.unequipitem SKBerserkDSLV6

player.removeitem SKBerserkDSLV6 1

player.additem SKBerserkDSLV7 1

player.equipitem SKBerserkDSLV7

 

 

endif

 

if Player.getlevel == 20

player.unequipitem SKBerserkDSLV7

player.removeitem SKBerserkDSLV7 1

player.additem SKBerserkDSLV8 1

player.equipitem SKBerserkDSLV8

 

 

endif

 

if Player.getlevel == 25

player.unequipitem SKBerserkDSLV8

player.removeitem SKBerserkDSLV8 1

player.additem SKBerserkDSLV9 1

player.equipitem SKBerserkDSLV9

 

 

endif

 

end

 

The problem with both of these is that when you reach one of the specified levels, Oblivion crashes the moment things start getting unequipped. Oddly enough, I made a second script that equips the helm and gauntlets when you enter combat:

 

Scriptname BerserkCombatHelm1

 

Begin GameMode

 

if Player.IsInCombat == 1

player.EquipItem SKBerserkWolfHelmetLV1

endif

 

if Player.IsInCombat == 0

player.UnequipItem SKBerserkWolfHelmetLV1

 

endif

 

end

 

Begin OnUnequip player

Playsound "Berserkdeact"

end

 

Begin OnEquip player

Playsound "Berserkact"

end

 

This one has an UnequipItem as well, but it doesn't crash the game. Any idea what the problem is?

Link to comment
Share on other sites

 

The problem with both of these is that when you reach one of the specified levels, Oblivion crashes the moment things start getting unequipped.

 

 

Which level is it that causes the script to crash Oblivion? That would narrow the search for a culprit down to the contents of a specific "if" and its set of items... Have you recompiled these scripts recently and do they compile successfully? I have seen a script like this compile and then later on one of the items referred to by the script was deleted - that guarantees a CTD.

Link to comment
Share on other sites

Problem partially solved. It seemed like the game crashed whenever you were above level one and in the same room as any of the items, so I added a line that made sure the item was in the player's possession before changing to the better version. With this, Oblivion didn't crash when the sword was upgraded to level 2. After that, another problem showed up: It only upgrades at the level 2 mark, but no further. So I tried separating each portion, which ended up like this:

 

Scriptname BerserkLevelSword

 

Begin GameMode

 

if player.getitemcount dragonslayerLV1 == 1

if Player.getlevel == 2

player.unequipitem dragonslayerLV1

player.removeitem dragonslayerLV1 1

player.additem dragonslayerLV2 1

player.equipitem dragonslayerLV2

endif

endif

 

End

 

Scriptname BerserkLevelSword2

 

Begin GameMode

 

if player.getitemcount dragonslayerLV2 == 1

if Player.getlevel == 4

player.unequipitem dragonslayerLV2

player.removeitem dragonslayerLV2 1

player.additem dragonslayerLV3 1

player.equipitem dragonslayerLV3

endif

endif

 

End

 

Et cetera.

 

After this, though, the second upgrade resulted in a CTD, just as the first did. And yeah, they compile.

 

MORE: After removing the UnequipItem, RemoveItem, AddItem, and EquipItem portions from BerserkLevelSword2, it doesn't crash. But removing only the UnequipItem and RemoveItem still results in a crash. Same with removing only AddItem and EquipItem

 

Is there a more efficient method for this sort of thing?

Link to comment
Share on other sites

A couple of suggestions:

 

1- It looks like you might need a 'do once' trigger under each section, otherwise the script is going to keep trying to unequip and re-equip your items every single time it runs, which is constantly. Your crashes may be due to the fact it runs once but then you no longer have the items the second time it runs because it already removed them from your inventory.

 

so...

Short DoOnce

 

If level == x

If DoOnce == 0

UnequipItem

RemoveItem

AddItem

EquipItem

Set DoOnce to 1

 

You'll need a different DoOnce trigger for each level, so...

 

Short DoOnce2

Short DoOnce4

Short DoOnce8

 

etc.

 

2- I'd replace all the separate 'If' statements with 'ElseIf' statements, that way the script doesn't have to parse every single section, only the one that matches your current level. It will free up a lot of processing power.

 

-Razorpony

 

**Edit** Also, what are you attaching these scripts to?

Link to comment
Share on other sites

Here is a thought... Try moving the RemoveItem line to the very bottom of the if block. In other words,

 

Scriptname BerserkLevelSword2

Begin GameMode

if player.getitemcount dragonslayerLV2 == 1
if Player.getlevel == 4
player.unequipitem dragonslayerLV2
player.removeitem dragonslayerLV2 1
player.additem dragonslayerLV3 1
player.equipitem dragonslayerLV3
endif
endif

End

 

should become

Scriptname BerserkLevelSword2

Begin GameMode

if player.getitemcount dragonslayerLV2 == 1
if Player.getlevel == 4
player.unequipitem dragonslayerLV2
player.additem dragonslayerLV3 1
player.equipitem dragonslayerLV3
; remove the item once Im done with everything else the script must do
player.removeitem dragonslayerLV2 1
endif
endif

End

 

The theory is that you are running dragonslayerLV2's object script and so when you have it remove itself and then do anything other than exit the script you will get a crash because the object owning the running script went away.

 

You do still need the doonce variables in order to keep from killing your performance since the gamemode block will run multiple times per second for an object in your inventory. Also, using elseif's is recommended - again to improve the performance of your script.

Link to comment
Share on other sites

That's why I thought to ask what it's attached to. Having the script remove itself causes problems, it's why you can't make a bound item out of another item of that same type. Just to elaborate on what Shadowfen said, break your script into seperate blocks and attach each block to a different version of the sword so that a level 2 sword only has the block to check for level 4, level 4 only has the block to check for level 8, etc.

 

-Razorpony

Link to comment
Share on other sites

That's why I thought to ask what it's attached to. Having the script remove itself causes problems

 

This gave me an idea: Combine the sword scripts into one again, and put it on something that ISN'T the swords themselves. problem solved. Thanks for the help, guys.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...