OnHit Player

Post » Mon Apr 11, 2011 6:23 pm

Hi all,

there is a way to use a script beginning when a player is hit and after a sum of damage knock down him letting the npc to rob or imprison him (this second one using some animation)?

I toughy about a quest script that get the player health at combat beginning and after for example fifty point of damage get it uncounsciouss stopping the combat for some seconds, and let the npc to rob him or imprison him (I saw same mod that let also to chain him). I'm not sure how his best to create this script and if there is a simple way than those I tought.

Thank you.
User avatar
Olga Xx
 
Posts: 3437
Joined: Tue Jul 11, 2006 8:31 pm

Post » Tue Apr 12, 2011 5:14 am

Hi all,

there is a way to use a script beginning when a player is hit and after a sum of damage knock down him letting the npc to rob or imprison him (this second one using some animation)?

I toughy about a quest script that get the player health at combat beginning and after for example fifty point of damage get it uncounsciouss stopping the combat for some seconds, and let the npc to rob him or imprison him (I saw same mod that let also to chain him). I'm not sure how his best to create this script and if there is a simple way than those I tought.

Thank you.

setav paralysis 1 for a few seconds? Plus maybe PushActorAway 1 to make it look better.

EDIT: I don't really know how to apply it to an NPC/Creature without a spell or an enchanted weapon... So no scripting in this post unless asked for enchantment or a spell :P
User avatar
Sweets Sweets
 
Posts: 3339
Joined: Tue Jun 13, 2006 3:26 am

Post » Mon Apr 11, 2011 9:17 pm

Hey man, I asked a similar question a while ago - It turns out there is no way to attach the OnHit block to the player. A work around you could use is cast a spell on the player via a triggered script, and in the scripteffectupdate block check to see if the players health is below a certain ammount. Dont know if that helps you much. The other work around someone mentioned was an OBSE function that involves checking what weapon sound is being played and using that as a work around for OnHit. If you want it to apply throughout the whole game I suppose you could even just use a GameMode script on a quest and check for certain values everyframe.

Something along the lines of

If (Getactorvalue fatigue == <5)
Player.Removeitem 0000000f 100
Messagebox "You have been robbed!"

or

Player.placeatme CageObject

thats not the right syntax I know, just throwing ideas out there.
User avatar
TASTY TRACY
 
Posts: 3282
Joined: Thu Jun 22, 2006 7:11 pm

Post » Mon Apr 11, 2011 7:02 pm

you might want to add the combat command to make sure if the player is in combat. I can see a very wrong thing here. Say your jumping. What happens when your fatigue gets below 5? You lose 100 gold! Actually, that would make a good joke mod. MWAHAHAHAHA.
User avatar
Ray
 
Posts: 3472
Joined: Tue Aug 07, 2007 10:17 am

Post » Mon Apr 11, 2011 9:58 pm

you might want to add the combat command to make sure if the player is in combat. I can see a very wrong thing here. Say your jumping. What happens when your fatigue gets below 5? You lose 100 gold! Actually, that would make a good joke mod. MWAHAHAHAHA.


What's the correct use for IsInCombat???? I tried the following script but never fire!!

scn knockingdownscript

float fQuestDelayTime

begin GameMode

set fQuestDelayTime to 0.2

if player.IsInCombat == 1
message "Combat Started" ; Debug Message
player.addspell GetEnemyRef ; Spell with script for getting attacker info
endif

end

What's wrong??
User avatar
Queen Bitch
 
Posts: 3312
Joined: Fri Dec 15, 2006 2:43 pm

Post » Mon Apr 11, 2011 9:14 pm

A silly question but you attached that script to a quest right?
User avatar
elliot mudd
 
Posts: 3426
Joined: Wed May 09, 2007 8:56 am

Post » Mon Apr 11, 2011 4:19 pm

scn knockingdownscriptfloat fQuestDelayTimeshort doonce ; ?begin GameModeset fQuestDelayTime to 0.2if player.IsInCombat == 1	message "Combat Started" ; Debug Message ; DO YOU SEE THIS ?	if doOnce == 0		set doOnce to 1		player.addspell GetEnemyRef ; Spell with script for getting attacker info	endifendifend


Indent your code and use codeboxes - and when you use a debug message and ask a question tell us if the message is seen :shakehead:
User avatar
Campbell
 
Posts: 3262
Joined: Tue Jun 05, 2007 8:54 am

Post » Mon Apr 11, 2011 3:00 pm

scn knockingdownscriptfloat fQuestDelayTimeshort doonce ; ?begin GameModeset fQuestDelayTime to 0.2if player.IsInCombat == 1	message "Combat Started" ; Debug Message ; DO YOU SEE THIS ?	if doOnce == 0		set doOnce to 1		player.addspell GetEnemyRef ; Spell with script for getting attacker info	endifendifend


Indent your code and use codeboxes - and when you use a debug message and ask a question tell us if the message is seen :shakehead:


Sorry,

the code wrote here was not indented because has been made quickly!
Anyway it work correctly, sorry, the first time I tried I don't know why the script didn't fired, sorry. This is a quest script and it's only the first part.
User avatar
Flutterby
 
Posts: 3379
Joined: Mon Sep 25, 2006 11:28 am

Post » Mon Apr 11, 2011 4:45 pm

So, at the end I wrote two separate code, the first one is for a quest script, the second for a script attached to a ability spell with 1 of duration. The problem is that look like the remove spell doesn't work at all, so the script work only the first time.

Global variable set to 0 at start:
spelladded and enemyref

Quest name knockingout
Quest Script:

scn knokcingdownscriptshort dooncefloat fQuestDelayTime begin gamemode 	set fQuestDelayTime to 0.2	if player.isincombat != 0 		player.addspell getenemyref 		set spelladded to 1 		message "Combat started, spelladded set to %g", spelladded, 5 	endif 	if spelladded == 2; 		if enemyref !=0 			message "Combat stopped, spelladded set to %g", spelladded, 5 			player.removespell getenemyref; 		endif 	endifend


Script attached to a ability spell with duration 1 (getenemyref)

scn getenemyrefscriptref enemyref creatureshort numenemyshort countershort removeshort distshort dist2ref attackerbegin scripteffectstart 	set numenemy to getnumrefs 69 1 	set creature to getnumrefs 36 1 	message "Enemy Number: %g, Creature: %g", numenemy, creature, 14 	set enemy to getfirstref 69 1 	set attacker to enemy 	set dist to 12 	while (enemy) 		if  enemy.getdistance player <= dist 			if enemy.getisplayablerace != 0 				set enemyref to enemy 			else 				set dist2 to enemy.getdistance player 				message "enemy distance: %g", dist2, 14 			endif 		endif 		set enemy to getnextref 		message "distance: %g, enemy: %g", dist, enemyref, 14 	loopendbegin scripteffectupdateendbegin scripteffectfinish 	if player.isincombat == 0 		set spelladded to 2 		stopquest Knockingout  		message "stopped quest", 14 	endifend
The begin scripteffectfinish never fire when combat finish. Surely there must be a really dumb error, but I'm unable to find it...
User avatar
Smokey
 
Posts: 3378
Joined: Mon May 07, 2007 11:35 pm

Post » Tue Apr 12, 2011 5:26 am

Oops
Basically the only way to remove the spell set spelladded to 2 is the player not being in combat once the spell finishes - scripteffectfinish only runs once - and since duration is 1 and the player was in combat when the spell started this is very unlikely - so the spell is never dispelled (not sure how abilities with duration > 0 work). Also check --> ;!!!!!!!!!!!!!!
In short :
Spoiler
scn knokcingdownscriptshort dooncefloat fQuestDelayTimebegin gamemode 	set fQuestDelayTime to 0.2 ; do once here	if player.isincombat && spelladded == 0 ; !!!!!!!!!!!!!!!!!!!!!!!!you add the spell all the time !  add "&& spelladded == 0" 		player.addspell getenemyref 		set spelladded to 1 		message "Combat started, spelladded set to %g", spelladded, 5 	endif 	if player.isincombat == 0; 		if enemyref !=0			set spelladded to 0 			message "Combat stopped, spelladded set to %g", spelladded, 5 			player.removespell getenemyref; 		endif 		; stopquest Knockingout 		; message "stopped quest", 14 	endifendscn getenemyrefscriptref enemyref creatureshort numenemyshort countershort removeshort distshort dist2ref attackerbegin scripteffectstart 	set numenemy to getnumrefs 69 1 	set creature to getnumrefs 36 1 	message "Enemy Number: %g, Creature: %g", numenemy, creature, 14 	set enemy to getfirstref 69 1 	set attacker to enemy 	set dist to 12 	while (enemy)	; maybe also check if in combat ? 		set dist2 to enemy.getdistance player 		if  dist2 <= dist 			if enemy.getisplayablerace != 0 				set enemyref to enemy 			else 				message "enemy distance: %g", dist2, 14 			endif 		endif 		set enemy to getnextref		if IsFormValid enemyref			message "distance: %g, enemy: %g", dist, enemyref, 14		endif 	loopend


Not sure what the loop does but this must solve the problem
User avatar
DarkGypsy
 
Posts: 3309
Joined: Tue Jan 23, 2007 11:32 am

Post » Mon Apr 11, 2011 7:09 pm

Oops
Basically the only way to remove the spell set spelladded to 2 is the player not being in combat once the spell finishes - scripteffectfinish only runs once - and since duration is 1 and the player was in combat when the spell started this is very unlikely - so the spell is never dispelled (not sure how abilities with duration > 0 work). Also check --> ;!!!!!!!!!!!!!!
In short :
Spoiler
scn knokcingdownscriptshort dooncefloat fQuestDelayTimebegin gamemode 	set fQuestDelayTime to 0.2 ; do once here	if player.isincombat && spelladded == 0 ; !!!!!!!!!!!!!!!!!!!!!!!!you add the spell all the time !  add "&& spelladded == 0" 		player.addspell getenemyref 		set spelladded to 1 		message "Combat started, spelladded set to %g", spelladded, 5 	endif 	if player.isincombat == 0; 		if enemyref !=0			set spelladded to 0 			message "Combat stopped, spelladded set to %g", spelladded, 5 			player.removespell getenemyref; 		endif 		; stopquest Knockingout 		; message "stopped quest", 14 	endifendscn getenemyrefscriptref enemyref creatureshort numenemyshort countershort removeshort distshort dist2ref attackerbegin scripteffectstart 	set numenemy to getnumrefs 69 1 	set creature to getnumrefs 36 1 	message "Enemy Number: %g, Creature: %g", numenemy, creature, 14 	set enemy to getfirstref 69 1 	set attacker to enemy 	set dist to 12 	while (enemy)	; maybe also check if in combat ? 		set dist2 to enemy.getdistance player 		if  dist2 <= dist 			if enemy.getisplayablerace != 0 				set enemyref to enemy 			else 				message "enemy distance: %g", dist2, 14 			endif 		endif 		set enemy to getnextref		if IsFormValid enemyref			message "distance: %g, enemy: %g", dist, enemyref, 14		endif 	loopend


Not sure what the loop does but this must solve the problem



Thank you a lot!!!

the script solved my problem and just for info, the spell was added only once so I solved the problem adding only two thing and setting to 0 the ability spell duration:

scn knokcingdownscriptshort dooncefloat fQuestDelayTime begin gamemode	if doonce == 0                                                  ; added this check for set only once the time check and for reset the spelladded variable		set fQuestDelayTime to 0.2		set doonce to 1		set spelladded to 0	endif	if player.isincombat && spelladded == 0		player.addspell getenemyref		set spelladded to 1		message "Combat started, spelladded set to %g", spelladded, 5	endif	if player.isincombat == 0  && spelladded == 1 ; <--- added spelladded check, else the spell was constantly removed;		if enemyref !=0			set spelladded to 0			message "Combat stopped, spelladded set to %g", spelladded, 5			player.removespell getenemyref;		endif	endifend


In the second script I had to move the IsFormValid check because the CS say to me that enemyref isn't a valid inventory object!!!

scn getenemyrefscriptref enemyref creatureshort numenemyshort countershort removeshort distshort dist2ref attackerbegin scripteffectstart	set numenemy to getnumrefs 69 1	set creature to getnumrefs 36 1	message "Enemy Number: %g, Creature: %g", numenemy, creature, 14	set enemy to getfirstref 69 1	set attacker to enemy	set dist to 12	while (enemy)		set dist2 to enemy.getdistance player		if  dist2 <= dist			if enemy.getisplayablerace 				set enemyref to enemy				message "Enemy found! %g", enemyref, 14			else				message "enemy distance: %g", dist2, 14			endif		endif		set enemy to getnextref;		if isformvalid enemyref			message "distance: %g, enemy: %g", dist, enemyref, 14;		endif	loopend


Now I must check the script also where there are enemy with playable race, until now I checked at beginning game after character creation.
User avatar
Jhenna lee Lizama
 
Posts: 3344
Joined: Wed Jun 06, 2007 5:39 am

Post » Tue Apr 12, 2011 3:04 am

Spoiler
Thank you a lot!!!

the script solved my problem and just for info, the spell was added only once so I solved the problem adding only two thing and setting to 0 the ability spell duration:

scn knokcingdownscriptshort dooncefloat fQuestDelayTime begin gamemode	if doonce == 0                                                  ; added this check for set only once the time check and for reset the spelladded variable		set fQuestDelayTime to 0.2		set doonce to 1		set spelladded to 0	endif	if player.isincombat && spelladded == 0		player.addspell getenemyref		set spelladded to 1		message "Combat started, spelladded set to %g", spelladded, 5	endif	if player.isincombat == 0  && spelladded == 1 ; <--- added spelladded check, else the spell was constantly removed;		if enemyref !=0			set spelladded to 0			message "Combat stopped, spelladded set to %g", spelladded, 5			player.removespell getenemyref;		endif	endifend


In the second script I had to move the IsFormValid check because the CS say to me that enemyref isn't a valid inventory object!!!

scn getenemyrefscriptref enemyref creatureshort numenemyshort countershort removeshort distshort dist2ref attackerbegin scripteffectstart	set numenemy to getnumrefs 69 1	set creature to getnumrefs 36 1	message "Enemy Number: %g, Creature: %g", numenemy, creature, 14	set enemy to getfirstref 69 1	set attacker to enemy	set dist to 12	while (enemy)		set dist2 to enemy.getdistance player		if  dist2 <= dist			if enemy.getisplayablerace 				set enemyref to enemy				message "Enemy found! %g", enemyref, 14			else				message "enemy distance: %g", dist2, 14			endif		endif		set enemy to getnextref;		if isformvalid enemyref			message "distance: %g, enemy: %g", dist, enemyref, 14;		endif	loopend


Now I must check the script also where there are enemy with playable race, until now I checked at beginning game after character creation.

Glad it helped :goodjob:

Anyway why global vars (that's why form valid did not work - I didn't know this)?

Spoiler
scn knokcingdownscriptshort dooncefloat fQuestDelayTime short spelladdedref enemyrefbegin gamemode	if doonce == 0      ; added this check for set only once the time check and for reset the spelladded variable		set fQuestDelayTime to 0.2		set doonce to 1	endif	if player.isincombat && spelladded == 0		player.addspell getenemyref		set spelladded to 1		message "Combat started, spelladded set to %g", spelladded, 5	endif	if player.isincombat == 0  && spelladded == 1 ; <--- added spelladded check, else the spell was constantly removed;		if enemyref !=0			set spelladded to 0			message "Combat stopped, spelladded set to %g", spelladded, 5			player.removespell getenemyref;		endif	endifendscn getenemyrefscriptref enemyref creatureshort numenemyshort countershort removeshort distshort dist2ref attackerbegin scripteffectstart	set numenemy to getnumrefs 69 1	set creature to getnumrefs 36 1	message "Enemy Number: %g, Creature: %g", numenemy, creature, 14	set enemy to getfirstref 69 1	set attacker to enemy	set dist to 12	while (enemy)		set dist2 to enemy.getdistance player		if  dist2 <= dist			if enemy.getisplayablerace 				set knockingout.enemyref to enemy				message "Enemy found! %g", enemy, 14			else				message "enemy distance: %g", dist2, 14			endif		endif		set enemy to getnextref;		if isformvalid knockingout.enemyref			message "distance: %g, enemy: %g", dist, knockingout.enemyref, 14;		endif	loopend

User avatar
Madison Poo
 
Posts: 3414
Joined: Wed Oct 24, 2007 9:09 pm

Post » Mon Apr 11, 2011 7:20 pm

Glad it helped :goodjob:

Anyway why global vars (that's why form valid did not work - I didn't know this)?

Spoiler
scn knokcingdownscriptshort dooncefloat fQuestDelayTime short spelladdedref enemyrefbegin gamemode	if doonce == 0      ; added this check for set only once the time check and for reset the spelladded variable		set fQuestDelayTime to 0.2		set doonce to 1	endif	if player.isincombat && spelladded == 0		player.addspell getenemyref		set spelladded to 1		message "Combat started, spelladded set to %g", spelladded, 5	endif	if player.isincombat == 0  && spelladded == 1 ; <--- added spelladded check, else the spell was constantly removed;		if enemyref !=0			set spelladded to 0			message "Combat stopped, spelladded set to %g", spelladded, 5			player.removespell getenemyref;		endif	endifendscn getenemyrefscriptref enemyref creatureshort numenemyshort countershort removeshort distshort dist2ref attackerbegin scripteffectstart	set numenemy to getnumrefs 69 1	set creature to getnumrefs 36 1	message "Enemy Number: %g, Creature: %g", numenemy, creature, 14	set enemy to getfirstref 69 1	set attacker to enemy	set dist to 12	while (enemy)		set dist2 to enemy.getdistance player		if  dist2 <= dist			if enemy.getisplayablerace 				set knockingout.enemyref to enemy				message "Enemy found! %g", enemy, 14			else				message "enemy distance: %g", dist2, 14			endif		endif		set enemy to getnextref;		if isformvalid knockingout.enemyref			message "distance: %g, enemy: %g", dist, knockingout.enemyref, 14;		endif	loopend



Yes, you're right: I used global var for testing because the script didn't worked like I wanted and then I forgot to set them to local var :)
User avatar
Marine Arrègle
 
Posts: 3423
Joined: Sat Mar 24, 2007 5:19 am


Return to IV - Oblivion