cfh85 Posted September 15, 2012 Share Posted September 15, 2012 (edited) 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 SpeedArray_var WeaponsRef SelfRef Weapon1 ;The base weapon.Ref Weapon1BaseRef WeaponBaseRef TempWeapon ;The new weapon to be copiedRef InventoryItemFloat IISpeedFloat IIReachFloat IIDamageFloat IIRatingFloat TempWeaponRatingFloat LevelFloat SpeedModFloat EquipFloat DoOnceShort KeyBegin 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 EndIfEnd[/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 September 15, 2012 by cfh85 Link to comment Share on other sites More sharing options...
QQuix Posted September 15, 2012 Share Posted September 15, 2012 GetItems returns Base Objects, therefore your InventoryItem ref is a Base object, therefore the syntax for IsWeapon (and following lines) must be ". . . IsWeapon InventoryItem . . ." Link to comment Share on other sites More sharing options...
cfh85 Posted September 15, 2012 Author Share Posted September 15, 2012 That did it. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts