Jump to content

Getting companion to switch weap depending on target distance


ClayPidgeon162

Recommended Posts

Basically, I'm trying to figure out how to get a custom companion to automatically switch their weapons depending on how close their target is. Their default weapons are a handgun and a shotgun, and I wanted them to switch to the handgun when the target was far away, and to the shotgun when the target gets in close.

 

Is there a script command that detects an NPC's current target that I could use with "GetDistance"? Or anything that could help accomplish this?

Link to comment
Share on other sites

GetCombatTarget what you're after?

 

Might want to put a timer in it, would be *interesting* if the target is hovering around the switch range, so they try and switch weapons every frame. Instead, maybe have a range which can use either weapon, ie range to switch to pistol > range to switch to shotgun.

Edited by Skevitj
Link to comment
Share on other sites

GetCombatTarget what you're after?

 

Might want to put a timer in it, would be *interesting* if the target is hovering around the switch range, so they try and switch weapons every frame. Instead, maybe have a range which can use either weapon, ie range to switch to pistol > range to switch to shotgun.

 

 

I tried that, but got a compile error in GECK. I'm not sure if I got the syntax right, I was trying "if ( CompanionREF.GetDistance CompanionREF.GetCombatTarget > 3000 )"

Link to comment
Share on other sites

Functions aren't nestable like that

 

scn...

ref combattarget
short targetdistance

begin...
...
if IsInCombat == 1
set combattarget to GetCombatTarget
set targetdistance to GetDistance combattarget
if targetdistance > *1*
 if GetEquipped pistol == 0
  ;remove shot
  ;add pistol
  ;equip pistol
 endif
elseif targetdistance < *2*
 if GetEquipped shot == 0
  ;remove pistol
  ;add shot
  ;equip shot
 endif
endif
endif
...
end

*1* being the range to switch to handgun, *2* being the range to switch to shotgun. shot being teh Object ID of the shotgun and pistol being the object ID of the handgun. That should take care of the switch, it can be simplified if you want just a single range to switch weapons, but as I said before, you may want to put a timer in to avoid the possibility of them oscillating weapons. The removeitem is there because I'm reasonably sure they'll dynamically select their own weapon as combat goes on, meaning they're likely to just switch back again.

Link to comment
Share on other sites

Functions aren't nestable like that

 

scn...

ref combattarget
short targetdistance

begin...
...
if IsInCombat == 1
set combattarget to GetCombatTarget
set targetdistance to GetDistance combattarget
if targetdistance > *1*
 if GetEquipped pistol == 0
  ;remove shot
  ;add pistol
  ;equip pistol
 endif
elseif targetdistance < *2*
 if GetEquipped shot == 0
  ;remove pistol
  ;add shot
  ;equip shot
 endif
endif
endif
...
end

*1* being the range to switch to handgun, *2* being the range to switch to shotgun. shot being teh Object ID of the shotgun and pistol being the object ID of the handgun. That should take care of the switch, it can be simplified if you want just a single range to switch weapons, but as I said before, you may want to put a timer in to avoid the possibility of them oscillating weapons. The removeitem is there because I'm reasonably sure they'll dynamically select their own weapon as combat goes on, meaning they're likely to just switch back again.

 

 

Seems to be working. Awesome, thank you very much.

 

It'll need some fine tuning, but I got something to work with now.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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