Jump to content

Refs to inventory items


cfh85

Recommended Posts

I've attempted to script an ability to create a new weapon, then improve it's speed. The weapon has it's appearance changed when it's updated to a new weapon, and then it's speed.

The problem I'm having is with inventory refs. The part of the script that scans the inventory doesn't seem to work. I'm using GetItems which is supposed to work on inventory items. The problem is occurring at the bottom of the script, after the marked point

 

 

Scriptname CFHCompanionsClass13AbilityScript

;Knife Dancer - Lightning Speed

Array_var Weapons

Ref Self
Ref Weapon1 ;The base weapon.
Ref Weapon1Base
Ref WeaponBase
Ref TempWeapon ;The new weapon to be copied
Ref InventoryItem

Float IISpeed
Float IIReach
Float IIDamage
Float IIRating
Float TempWeaponRating
Float Level
Float SpeedMod
Float Equip
Float DoOnce

Short Key

Begin Gamemode
If DoOnce == 1
If (Self.GetInFaction CFHCompanionSpecialFaction) == 0
If Equip == 0
Return
Else
Self.EquipItemNS Weapon1
Set Equip to 0
Return
EndIf
Else
Let TempWeapon := Call UDCFHClass13Update Self Weapon1

Set TempWeaponRating to 0
Let Weapons := (Self.GetItems 33)
Let Key := ar_Size Weapons

While Key > 0
Let Key -= 1
Let InventoryItem := Weapons[Key]

If (InventoryItem.IsWeapon == 0)
Continue
ElseIf (InventoryItem.GetWeaponType != 0)
Continue
ElseIf (InventoryItem == Weapon1)
Continue
ElseIf ((GetWeaponReach InventoryItem) > 0.7)
Continue
Else
Set IISpeed to (GetWeaponSpeed InventoryItem)
Set IIReach to (GetWeaponReach InventoryItem)
Set IIDamage to (GetAttackDamage InventoryItem)
Set IIRating to (IIDamage * IISpeed * IIReach * IIReach)
If IIRating > TempWeaponRating
Set TempWeapon to InventoryItem
Set TempWeaponRating to IIRating
EndIf
EndIf
Loop

If (TempWeapon.IsWeapon == 0)
Return
ElseIf (TempWeapon.GetWeaponType != 0)
Return
ElseIf ((GetWeaponReach TempWeapon) > 0.7)
Return
Else
Let Level := Call UDCFHCompanionLevelNeutral Self

Set SpeedMod to (1 + (Level / 50))
Weapon1.CopyModelPath TempWeapon
Set IISpeed to ((GetWeaponSpeed TempWeapon) * SpeedMod)
Set IIReach to (GetWeaponReach TempWeapon)
Set IIDamage to (GetAttackDamage TempWeapon)
SetWeaponSpeed IISpeed Weapon1
SetWeaponReach IIReach Weapon1
SetAttackDamage IIDamage Weapon1
Self.UnequipItemNS Weapon1
Set Equip to 1
Self.SetFactionRank CFHCompanionSpecialFaction -1
Return
EndIf
EndIf
Else


<------------------------PROBLEM AFTER HERE --------------->


Set Self to GetSelf

Let Weapons := (Self.GetItems 33)
Let Key := ar_Size Weapons

While Key > 0
Let Key -= 1
Let InventoryItem := Weapons[Key]

If (InventoryItem.IsWeapon == 0)
Continue
ElseIf (InventoryItem.GetWeaponType != 0)
Continue
ElseIf ((GetWeaponReach InventoryItem) > 0.7)
Continue
Else
Set IISpeed to (GetWeaponSpeed InventoryItem)
Set IIReach to (GetWeaponReach InventoryItem)
Set IIDamage to (GetAttackDamage InventoryItem)
Set IIRating to (IIDamage * IISpeed * IIReach * IIReach)
If IIRating > TempWeaponRating
Set TempWeapon to InventoryItem
Set TempWeaponRating to IIRating
EndIf
EndIf
Loop

If (TempWeapon.IsWeapon == 0)
Return
ElseIf (TempWeapon.GetWeaponType != 0)
Return
ElseIf ((GetWeaponReach TempWeapon) > 0.7)
Return
Else
Set WeaponBase to TempWeapon.GetBaseObject
Set Weapon1Base to CloneForm WeaponBase
Set Weapon1 to (Self.PlaceAtMe Weapon1Base 1, 0, 0,)
Weapon1.Activate Self
Self.EquipItem Weapon1
Set DoOnce to 1
EndIf
EndIf
End[/Code]

 

 

In the game version I've added a messagebox where I've marked the problem. There is a weapon in the NPCs inventory, so the last part should only run once (thus only displaying the messagebox once) but it doesn't

Edited by cfh85
Link to comment
Share on other sites

  • Recently Browsing   0 members

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