Jump to content

Invalid Variable for Companion Script


panzersharkcat

Recommended Posts

scn 00MSWADornanScript
short HasBeenHired
short TSCBase
short Relax
short DoTSCOnce
int CombatStyleRanged
int CombatStyleMelee
int IsFollowingDefault
int IsFollowingLong
int FollowerSwitchAggressive
int Waiting
ref ScottDornanREF
Begin GameMode
if (DoTSCOnce != 1)
set HasBeenHired to 0
set TSCBase to 0
set CombatStyleRanged to 1
set CombatStyleMelee to 0
set IsFollowingDefault to 0
set IsFollowingLong to 0
set FollowerSwitchAggressive to 0
set Waiting to 0
set Relax to 0
set DoTSCOnce to 1
EndIf
End
;Begin OnLoad
set ScottDornanREF to GetSelf
; equip Dornan's uniform when not following and on duty shift
if (ScottDornanREF.HasBeenHired == 0 && ScottDornanREF.GetInCell 00MSEmbassyStaffRooms == 0)
if (ScottDornanREF.GetItemCount 00MSMarineArmorNPC >= 1)
EquipItem 00MSMarineArmorNPC 1 1
endif
if (ScottDornanREF.GetItemCount 00MSTSCFieldHatNPC >= 1)
EquipItem 00MSTSCFieldHatNPC 1 1
endif
if (ScottDornanREF.GetItemCount 00MSGlassesDornan >= 1)
EquipItem 00MSGlassesDornan 1 1
endif
endif
End

 

 

It keeps telling me HasBeenHired is an invalid variable, even though it works in recruiting him and getting him to follow. Same with ScottDornanREF. That's the reference used where I placed him. Any ideas what I'm doing wrong?

 

(He's a TSC sergeant from TSC Vegas. Intending to amend the follower script I made so he wears off duty clothing when he's in the TSC Embassy Staff Room or told to relax.)

Edited by panzersharkcat
Link to comment
Share on other sites

The compiler doesn't like it because ScottDornanREF is a reference variable instead of an actual persistent REF. A reference variable can be set to an instance of any object, so the compiler tends to barf on anything that isn't generic to all objects. That is, ScottDornanREF.GetInCell is okay because you can call GetInCell on any reference, but ScottDornanREF.HasBeenHired is not okay because it would only work for objects that have a HasBeenHired variable declared in their object script, and the compiler doesn't resolve those dependencies. Anyway, if the code is in his object script, you can skip the indirection and just check HasBeenHired directly:

if (HasBeenHired == 0 && GetInCell 00MSEmbassyStaffRooms == 0)

In fact, you could probably do away entirely with the ScottDornanREF variable, since reference functions in an object script will operate on the self by default.

 

Also, BEGIN OnLoad is commented out, so the code that follows it is currently outside the scope of any block, which will probably cause other unexpected behavior if it compiles.

Link to comment
Share on other sites

I use the following technique. It all happens in the same frame so I haven't noticed any visual glitches, but your mileage may vary. cesForceEquip is a dummy armor I created for this purpose. You could technically use any armor in its place, but if the character happens to have the same type in their inventory with less than 100% condition, the last function call could remove the damaged one and leave the new one in their inventory, which could potentially be exploited to get free 100% armor repair.

additem cesForceEquip 1
equipitem cesForceEquip
removeitem cesForceEquip 1
Link to comment
Share on other sites

Alright. Thanks. Will test it out. See how it works. Running into an issue where certain dialog option won't pop up. There's supposed to be a greeting for if you shoot up on chems or drink in uniform and then talk to him. Never triggers. It's set to check if target has anything from a form list equipped and if player has any of the chem effects. Never shows up. Thinking of just scrapping it.

Link to comment
Share on other sites

It works. For some reason, he seems to trigger my mines even though I used a script to give him Light Step and, you know, he's a teammate. He also aggroes if I accidentally shoot him. His hiring script has SetPlayerTeammate 1 and SetIgnoreFriendlyHits 1.

 

Set ScottDornanREF.Waiting to 0

Set ScottDornanREF.Relax to 0

Set ScottDornanREF.IsFollowingDefault to 1

Set ScottDornanREF.IsFollowingLong to 0

Set ScottDornanREF.CombatStyleRanged to 1

Set ScottDornanREF.CombatStyleMelee to 0

Set ScottDornanREF.HasBeenHired to 1

SetPlayerTeammate 1

SetIgnoreFriendlyHits 1

Player.AddPerk 00MSWAPerkDornan

UnequipItem 00MSOffDutySoldierOutfitDornan 1 1

AddItem PSCDummyArmor 1

EquipItem PSCDummyArmor 1

RemoveItem PSCDummyArmor 1

AddItem PSCDummyHelmet 1

EquipItem PSCDummyHelmet 1

RemoveItem PSCDummyHelmet 1

ScottDornanREF.evp

EDIT: Never mind, Figured it out. Needed to add the player to his faction. Edited by panzersharkcat
Link to comment
Share on other sites

  • Recently Browsing   0 members

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