Scripting - OnHit Blocks

Post » Tue Jun 29, 2010 5:33 am

I'm considering taking on a project which would require things to be done whenever the player is hit. However I've heard that OnHit blocks require a weapon ID to work. Is this true? If so how could I work around this?
User avatar
james tait
 
Posts: 3385
Joined: Fri Jun 22, 2007 6:26 pm

Post » Mon Jun 28, 2010 7:10 pm

From the Wiki regarding OnHitWith blocks:
This block will be run once when the scripted actor is hit by the specified weapon. If no parameter is used, the block will be run when the scripted actor is hit by any weapon.

User avatar
Rozlyn Robinson
 
Posts: 3528
Joined: Wed Jun 21, 2006 1:25 am

Post » Tue Jun 29, 2010 3:53 am

Bear in mind this has horrible compatibility issues- only one mod can script the player.
User avatar
Rebekah Rebekah Nicole
 
Posts: 3477
Joined: Fri Oct 13, 2006 8:47 pm

Post » Mon Jun 28, 2010 7:46 pm

Ok then what would be another, more compatible, way?
User avatar
Juan Suarez
 
Posts: 3395
Joined: Sun Nov 25, 2007 4:09 am

Post » Mon Jun 28, 2010 5:13 pm

You could run a quest script that repeatedly checks the player's health and compares it to the last check. If there is a negative difference (the player lost health) then perform the actions. If you added a check to see if the player was in combat, you could also narrow down the chances that he had been damaged from enemies, but not necessarily all the time.
User avatar
rebecca moody
 
Posts: 3430
Joined: Mon Mar 05, 2007 3:01 pm

Post » Mon Jun 28, 2010 5:38 pm

Could some one whip up a mock up of that for me? I've tried before and failed, but it must be possible.
User avatar
Jessica White
 
Posts: 3419
Joined: Sun Aug 20, 2006 5:03 am

Post » Tue Jun 29, 2010 2:44 am

Well, since you're from Ontario, try this:

scn MyQuestScriptShort DoOnceFloat OldHealthFloat NewHealthBegin GameMode    If DoOnce == 0	Set OldHealth to player.GetAV Health	Set DoOnce to 1  Endif  Set NewHealth to player.getav Health  If NewHealth < OldHealth && Player.IsInCombat	;Do stuff when player has taken damage while in combat  Endif  Set OldHealth to NewHealthEnd

User avatar
Courtney Foren
 
Posts: 3418
Joined: Sun Mar 11, 2007 6:49 am

Post » Tue Jun 29, 2010 1:16 am

My wife is from Ontario, and she says to make sure the outcome of the script is polite. :P
User avatar
Jordan Moreno
 
Posts: 3462
Joined: Thu May 10, 2007 4:47 pm

Post » Mon Jun 28, 2010 6:56 pm

Lol thanks for the Ontarian comradeship, I'll give that script a go later. I think in my previous attempts I may have been missing that doonce catch.
User avatar
JaNnatul Naimah
 
Posts: 3455
Joined: Fri Jun 23, 2006 8:33 am

Post » Mon Jun 28, 2010 9:49 pm

Even if you missed the DoOnce part, it would only have made a false positive the very first iteration and then worked from then on.

As you can see from my avatar, I have an affinity for certain things from Ontario, being from there myself. What town doth thou hail from?
User avatar
Saul C
 
Posts: 3405
Joined: Wed Oct 17, 2007 12:41 pm

Post » Mon Jun 28, 2010 10:59 pm

Even if you missed the DoOnce part, it would only have made a false positive the very first iteration and then worked from then on.

As you can see from my avatar, I have an affinity for certain things from Ontario, being from there myself. What town doth thou hail from?


Pembroke, possibly best known for it's terrible roads.
User avatar
T. tacks Rims
 
Posts: 3447
Joined: Wed Oct 10, 2007 10:35 am

Post » Mon Jun 28, 2010 7:49 pm

Well, since you're from Ontario, try this:

scn MyQuestScriptShort DoOnceFloat OldHealthFloat NewHealthBegin GameMode    If DoOnce == 0	Set OldHealth to player.GetAV Health	Set DoOnce to 1  Endif  Set NewHealth to player.getav Health  If NewHealth < OldHealth && Player.IsInCombat;Do stuff when player has taken damage while in combat  Endif  Set OldHealth to NewHealthEnd

Mississauga, and having been a fan of the buds since childhood, I have to respect your team spirit in flying the blue and white as your avatar. Not much to feel happy about for the boys in blue over the last few years!

Anyway, back to the topic at hand. If I might join the Ontarian script help club, I would certainly appreciate it!

My question is, what would I have to replace the ";Do stuff when player has taken damage while in combat" line with in order to add 5 points of health to the player each time they take damage?
I am guessing it might be something like 'AddHealth 5', or 'IncreaseHealth 5'?
Or perhaps I need to use [ActorREF.]RestoreAV Health 5 (though I am not sure what the 'ActorREF.' is) :shrug:

Any help (Ontarian or otherwise) greatly appreciated!
User avatar
Chad Holloway
 
Posts: 3388
Joined: Wed Nov 21, 2007 5:21 am

Post » Mon Jun 28, 2010 6:03 pm

Or perhaps I need to use [ActorREF.]RestoreAV Health 5 (though I am not sure what the 'ActorREF.' is) :shrug:


This is your answer. For the player, ActorRef is "player", so...

Player.RestoreAV Health 5


would be the line of code.

I once hailed from Kitchener many moons ago. I still have family all over though. Mostly in Kitchener, Milton and Bradford. And, Ya, like Darcy Tucker once said, "I bleed Blue & White". Emphasis on the 'bleed' over the past few years...
User avatar
Len swann
 
Posts: 3466
Joined: Mon Jun 18, 2007 5:02 pm

Post » Tue Jun 29, 2010 7:46 am

This is your answer. For the player, ActorRef is "player", so...

Player.RestoreAV Health 5


would be the line of code.

I once hailed from Kitchener many moons ago. I still have family all over though. Mostly in Kitchener, Milton and Bradford. And, Ya, like Darcy Tucker once said, "I bleed Blue & White". Emphasis on the 'bleed' over the past few years...

Oh for the days when Darcy was playing with Gary Roberts and Domi and Shane and Cujo was good...
Oh well, them days seem ancient now

Thanks for the script tips. I think this may be just what I was looking for
User avatar
bimsy
 
Posts: 3541
Joined: Wed Oct 11, 2006 3:04 pm

Post » Mon Jun 28, 2010 4:39 pm

...Thanks for the script tips. I think this may be just what I was looking for

Hmm May have spoken too soon.
Put this on outcast power armor and went hunting. To check whether it was working, I set script return 50 health per hit, then went hunting outcasts with an assault rifle.
they should have been almost invulnerable, but in fact I put down 2 in less than a single mag.

Here is th script as I used it:

scn DamageReduction10

Short DoOnce
Float OldHealth
Float NewHealth

Begin GameMode

If DoOnce == 0
Set OldHealth to player.GetAV Health
Set DoOnce to 1
Endif
Set NewHealth to player.getav Health
If NewHealth < OldHealth && Player.IsInCombat
Player.RestoreAV Health 50
Endif
Set OldHealth to NewHealth

End

Whats the proboem? Why is this not working?
Is it OK to have 2x '&"s?
User avatar
Monika Krzyzak
 
Posts: 3471
Joined: Fri Oct 13, 2006 11:29 pm

Post » Mon Jun 28, 2010 8:07 pm

Should work. Is the mod at the top of your load order? Otherwise it's probably getting overridden by another mod as everyone and their dog changes power armour.

Also, you can remove the if(doonce==0) check from it- the default value of OldHealth will be 0, so you'll never have a problem with OldHealth erroneously being flagged as higher than NewHealth.
User avatar
CHangohh BOyy
 
Posts: 3462
Joined: Mon Aug 20, 2007 12:12 pm

Post » Tue Jun 29, 2010 7:15 am

That script only restores the players health, not the wearers. so every hit, its looking at only the player's health. If you want it to affect the wearer then change it like this:

scn DamageReduction10Short IsWearingFloat OldHealthFloat NewHealthRef SelfBegin OnEquip  Set Self to GetContainer  Set IsWearing to 1EndBegin OnUnEquip  Set IsWearing to 0EndBegin GameMode  If (IsWearing)	Set NewHealth to self.getav Health	If NewHealth < OldHealth && self.IsInCombat	  self.RestoreAV Health 50	Endif	Set OldHealth to NewHealth  EndIfEnd


And TTT was right about the DoOnce part, so its now gone.
User avatar
REVLUTIN
 
Posts: 3498
Joined: Tue Dec 26, 2006 8:44 pm

Post » Tue Jun 29, 2010 6:45 am

Fantastic!
Thanks guys!
User avatar
Chloe Botham
 
Posts: 3537
Joined: Wed Aug 30, 2006 12:11 am

Post » Tue Jun 29, 2010 12:21 am

That script only restores the players health, not the wearers. so every hit, its looking at only the player's health. If you want it to affect the wearer then change it like this:

scn DamageReduction10Short IsWearingFloat OldHealthFloat NewHealthRef SelfBegin OnEquip  Set Self to GetContainer  Set IsWearing to 1EndBegin OnUnEquip  Set IsWearing to 0EndBegin GameMode  If (IsWearing)	Set NewHealth to self.getav Health	If NewHealth < OldHealth && self.IsInCombat	  self.RestoreAV Health 50	Endif	Set OldHealth to NewHealth  EndIfEnd


And TTT was right about the DoOnce part, so its now gone.

I hate to say it, but it doesnt seem to be working.
I added the script to outcast power armor, went out and paralyzed myself an outcast guinea pig (setrestrained), then proceeded to shoot him in the leg with a silenced pistol.
I have my Damage mult up around 2.8, but even so, with a DR of around 55 and the additional 50 health per hit,... he should have been getting stronger...
Instead he was dead in about 8 shots.

I am getting confused...
Any assistance with this issue greatly appreciated
User avatar
Tyler F
 
Posts: 3420
Joined: Mon Aug 27, 2007 8:07 pm

Post » Tue Jun 29, 2010 2:08 am

If he was wearing it from the begining, then the OnEquip block would never have run, so IsWearing would have never been set. Try it with a follower who you give the armor to, or just change the script to set Is Wearing to 1 by default. Or, if you use FOSE, you can add a check to see if the armor in slot 2 is Outcast PA with http://fose.silverlock.org/fose_command_doc.html#GetEquippedObjectand set IsWearing that way. Or instaed of a script on the armor, make it an enchantment

Or add this bit to the script:

Short DoOnceBegin OnLoad  If DoOnce == 0	Set self to getcontainer	self.UnequipItem ArmorPowerOutcast	self.EquipItem ArmorPowerOutcast	Set Doonce to 1  EndifEnd


You can then remove the "Set Self to GetContainer" line from the OnEquip block as it will be redundant. But that forces the NPC to wear the armor even if they would have chosen to wear something else, which may or may not be a problem. And check out http://geck.gamesas.com/index.php/Force_an_actor_to_equip_new_stuff for an alternative solution.
User avatar
bimsy
 
Posts: 3541
Joined: Wed Oct 11, 2006 3:04 pm

Post » Tue Jun 29, 2010 1:09 am

Sorry pkleiss,
I really appreciate your patient efforts on this, but I seem to be having a problem with this.
Here is the script with your new additions:
scn DamageReduction10

Short DoOnce

Begin OnLoad
If DoOnce == 0
Set Self to GetContainer
self.UnequipItem ArmorPowerOutcast
self.EquipItem ArmorPowerOutcast
Set Doonce to 1
Endif
End

Short IsWearing
Float OldHealth
Float NewHealth
Ref Self

Begin OnEquip
Set IsWearing to 1
End

Begin OnUnEquip
Set IsWearing to 0
End

Begin GameMode
If (IsWearing)
Set NewHealth to self.getav Health
If NewHealth < OldHealth && self.IsInCombat
self.RestoreAV Health 50
Endif
Set OldHealth to NewHealth
EndIf
End

When I try to save this I get a warning that "... Line 7, Unknown variable 'Self'.

Problems here, and team Canada got beat....
User avatar
Bad News Rogers
 
Posts: 3356
Joined: Fri Sep 08, 2006 8:37 am

Post » Mon Jun 28, 2010 6:47 pm

You have to group like stuff together. Sorry if I wasn't clear. So It should look like this:

scn DamageReduction10Short DoOnceShort IsWearingFloat OldHealthFloat NewHealthRef SelfBegin OnLoad  If DoOnce == 0	Set Self to GetContainer	self.UnequipItem ArmorPowerOutcast	self.EquipItem ArmorPowerOutcast	Set IsWearing to 1;this line makes the two above obsolete, but should ensure that the effect will work for your test	Set Doonce to 1  EndifEndBegin OnEquip  Set IsWearing to 1EndBegin OnUnEquip  Set IsWearing to 0EndBegin GameMode  If (IsWearing)	Set NewHealth to self.getav Health	If NewHealth < OldHealth && self.IsInCombat	  self.RestoreAV Health 50	Endif	Set OldHealth to NewHealth  EndIfEnd


Was it me or did 3 of the USA's goals come off of Canadian deflections and a fourth came after Brodeur was knocked over - no penalty. I thought the USA was virtually immune to any infractions untill the last 7 minutes. No matter, the extra game will give the team more time to gell. But the game was very exiting. Hockey really doens't get much better than this.
User avatar
Ross Thomas
 
Posts: 3371
Joined: Sat Jul 21, 2007 12:06 am

Post » Tue Jun 29, 2010 5:27 am

I hate to say it but this also seems to not be working.
I tried both using your script verbatim and then cutting out the two "self.equip..." lines
I also bumped the health addition up to 200 just to be sure there would be a clear increase, but I was still able to drop my paralyzed Outcase armor guy with a silenced 10 mm in about a dozen shots to the leg.

The armor also has an object effect (+rad, +strength). Could this be conflicting with the script?
Getting a bit frustrating now...


As to the hockey, I downloaded the game but havent been able to work up the nerve to watch it yet.
You are right, best to look at this as opening the door for another tune up game.
Damn glad I'm not a canadian living in the US, though!
User avatar
mollypop
 
Posts: 3420
Joined: Fri Jan 05, 2007 1:47 am

Post » Mon Jun 28, 2010 9:13 pm

Damn glad I'm not a canadian living in the US, though!

Heh. I did take a bit of heat from the neighbors...

I'm going to try this out myself and see if I can't get it to work...

EDIT: Well, I got it to work, sort of. I got the outcast to receive the benefits of the armour, but I'm having problems with a follower using it and getting the benefits. To that end I started another thread to see if anyone had any suggestions. I could get it to work flawlessly using FOSE, but I'm trying to do it without FOSE. Once I have a total sloution (if any), I'll post the completed script.
User avatar
D IV
 
Posts: 3406
Joined: Fri Nov 24, 2006 1:32 am

Post » Mon Jun 28, 2010 4:27 pm

Okay, with a bit of help, I came up with this script. It only works if the wearer is in combat and takes damage. The damage can be of any type.

scn UCDamageReduction10Short IsWearingFloat OldHealthFloat NewHealthRef SelfBegin OnUnEquip	Set IsWearing to 0EndBegin GameMode	Set Self to GetContainer	If Self.Getequipped ArmorPowerOutcast && IsWearing == 0		Set IsWearing to 1	ElseIf Self.GetEquipped ArmorPowerOutcast == 0 && IsWearing		Set IsWearing to 0	Endif	If (IsWearing)		Set NewHealth to self.getav Health		If NewHealth < OldHealth && self.IsInCombat			self.RestoreAV Health 50		Endif		Set OldHealth to NewHealth	EndIfEnd

User avatar
willow
 
Posts: 3414
Joined: Wed Jul 26, 2006 9:43 pm

Next

Return to Fallout 3