[no fix] OnPCHitMe (is local short variable)
Short OnPCHitMe
If ( OnPCHitme == 1 )
A local game variable (not a function, you must declare it as a variable as shown above) that gets set to 1 when the player hits the calling Actor. Must be manually reset. It seems the use of the variable "short-circuits" normal NPC behavior in that an NPC with a script that uses this variable will not attack on its own accord. If you don’t want the Actor to remain passive you have to manually StartCombat (see example below). Once the Actor is in combat mode, OnPCHitMe does not report any further hits by the PC. Except, according to information on the forum, OnPCHitMe gets reset (to 0) if another Actor hits the calling Actor after the PC did, then the variable gets reset to 1 if the player hits again.
Note: According to info provided by Nigedo, OnPCHitMe also registers if the PC commits a crime, and the Actor has a sufficiently high alarm setting.
Example Script: An example from my traveling merchants mod, to make a guar handler defend his charge while not in AIFollow mode, I attached this to the guar:
Begin _HB_Adros_GuarDefend
float timer
short attackstate
short OnPCHitMe
if ( OnPCHitMe == 1 )
set attackstate to 1
set OnPCHitMe to 0
endif
if (attackstate == 1)
StartCombat, player
set timer to ( timer + GetSecondsPassed)
if ( timer >= 1 )
set timer to 0
if ( GetLOS, HB_adros_darani == 1)
HB_adros_darani->StartCombat, Player
set attackstate to 0
endif
endif
endif
End
GetAttacked (returns Boolean/short)
If ( Actor->GetAttacked == 1 )
Returns 0 if the Actor has never been attacked and 1 if he has ever been attacked.
Example script: Uupse protects Yagrum Bagarn:
Begin uupse_Bagrum
short doOnce
if ( doOnce == 0 )
if ( "yagrum bagarn"->GetAttacked == 1 )
StartCombat player
SetFight 90
SetDisposition 0
set doOnce to 1
endif
endif
end uupse_Bagrum
GetTarget, "Actor ID" (returns Boolean/short)
If ( Actor->GetTarget, Player == 1 )
GetTarget tests to see if the target is in focus. For the player, it's the test to see if the target is currently in the crosshair and can be activated. Of course NPCs don't have a crosshair like the player, but they get the same logic. (Thanks to cdcooley for the explanation)
If you want to use GetTarget to see if one actor is fighting another, you would have to combine it with GetWeaponDrawn and GetSpellReadied.
short temp
set temp to GetWeaponDrawn
set temp to ( temp + GetSpellReadied )
if ( temp > 0 )
if ( GetTarget, Player == 1 )
; In combat with the player here
endif
endif
HitOnMe, "Weapon ID" (returns Boolean/short)
HitAttemptOnMe, "Weapon ID" (returns Boolean/short)
These functions return true (1) for 1 frame if the calling Actor is successfully hit or if it was attempted to hit it with a specified weapon. HitOnMe is used only in the LorkhanHeart script (only look at that if you have finished the game or don't mind severe spoilers). I guess it could be a nice function to script any kind of fight of the "you need this special weapon to kill this particular monster" type.