Jump to content

Problems with a knockdown script: IsAttacking VS OnHit?


Art_B

Recommended Posts

Hello all. I am working on a simple mod to make some enemies do more knockdowns. Right now I am just trying to get a basic version to work but already ran into a wall.

 

Currently they knock down just by attacking, even if them miss. I guess this is because I am using IsAttacking but am not how to make them only knockdown when their hits actually connect. I know there is an OnHit function in OBSE but not sure how it works. Couldn't find any examples. 

 

Anyway here is the code I have so far:

Scn AAAGoblin

Short KDChance
Float Cooldown
Ref MyTarget

Begin Gamemode
	

set Mytarget to GetCombatTarget

	
If Cooldown > 0
     Set Cooldown to (Cooldown - GetSecondsPassed)
Else
     If IsAttacking ==1							;While attacking? Not on hit?
			Set KDChance to (100/99 * GetRandomPercent)                
			If KDChance <= 100				;100% Chance for testing
            PushActorAway MyTarget 5			                ;Knockdown and Force
               Set Cooldown to 1                                        ;1 second cooldown
          endif
     endif
endif

end

I am a novice. Input from veteran coders is appreciated! 

Link to comment

 

I think OnHit is only for the actors (the script block is triggered when the actor is beaten, the script itself on the actor)

 

probably would have to use a block with events  - SetEventHandler and OnHit 

but I don’t know if this will work on the player

Link to comment

Last time I checked, the OnHit event worked. And the doc doesn't seem to have any special mention of it either, other than an use example. What part of it do you not understand?

 

Also, IsAttacking is to be used in a multi-frame script. It returns True while attack anim is playing. So if you knock back a dude as soon as it's True, you're going to push him away as soon as the attacker starts attacking. To use it for your purpose correctly, you should trap the state in a variable and check every frame with something else if the hit landed.

 

I think, you just better off using the OnHit event and forget about IsAttacking for now. I don't remember exactly when the OnHit event registers (before or after hit), but I have a mod that practically half of which relies on that single event type. It does just fine.. it's named "Class Advantages" I ended up modding that mod to my liking pretty heavily, but I'm pretty sure the original scripts used that event too.

Link to comment
47 minutes ago, Art_B said:

What would a use case of OnHit look like?

(OnHit SetEventHandler ) does not work on the Player  but these work -

p - Player ref

SetEventHandler "OnRecoil" aaaFunction ref::p
 

SetEventHandler "OnStagger" aaaFunction ref::p

Link to comment
	scn FnOnHitByPlayer
	ref target
	ref attacker

	begin Function { target, attacker }
		; we know the attacker must be the player, but the argument is still required
		print $target + " was hit by the player"
	end
	-------------
	scn FnOnPlayerRestoreHealth
	ref target
	long effectCode

	begin Function { target, effectCode }
		print "The player has been hit by a restore health effect"
	end
	--------------
	scn FnOnLoadGame
	string_var filename

	begin Function { filename }
		print "Loading game from " + $filename
	end
	---------------
	scn SomeQuestScript
	begin gamemode
		if getGameRestarted
			SetEventHandler "OnHit" FnOnHitByPlayer second::PlayerRef
			SetEventHandler "OnMagicEffectHit" FnOnPlayerRestoreHealth first::PlayerRef second::"REHE"
			SetEventHandler "LoadGame" FnOnLoadGame
		endif
	end

These examples are right from the obse documentation. I'm not sure what exactly you meant by asking for use cases. What you're trying to use this for is the use case... applying effects to physical hits. Additional critical damage whenever hit, make the target flee whenever hit, make the target fly whenever hit, all the same.

 

Note: Despite what it says, the filters (first/second or ref/object) pairs must be passed as per the stringmap key::value pair systax. That is, first::PlayerRef or ref::PlayerRef will not compile, while "first"::PlayerRef or "ref"::PlayerRef will compile. The quest script example above will not compile. The official obse documentation is often incorrect.

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use