Scripts: Hitting Object via Arrow/Bolt

Post » Tue Aug 23, 2011 5:18 am

My question is quite simple - is there any possibility to return true when arrow, bolt or anything other related to marksman skill hits specific object? For example, player aim (can be bow in that case) at a bell, fire and the bell rings. I've tried to pin a script with GetDistance for specific type of arrows but it doesn't work. Any ideas, mates?
User avatar
FABIAN RUIZ
 
Posts: 3495
Joined: Mon Oct 15, 2007 11:13 am

Post » Tue Aug 23, 2011 1:46 am

You could make the object you want to make "hittable" into a creature, or just place an invisible creature/NPC in front or on top of it. Then you can detect hits on the actor by using the variable OnPCHitMe.

If you'd like the hits to only perform a certain function when performed by a marksman weapon, you can combine the above technique with GetWeaponType which can determine what weapon type the player has equipped at any given time.
User avatar
LijLuva
 
Posts: 3347
Joined: Wed Sep 20, 2006 1:59 am

Post » Tue Aug 23, 2011 5:48 am

Yeah, I was thinking about this method, however, is there any way to get it around without making hittable creature?
User avatar
GEo LIme
 
Posts: 3304
Joined: Wed Oct 03, 2007 7:18 pm

Post » Mon Aug 22, 2011 11:29 pm

Yeah, I was thinking about this method, however, is there any way to get it around without making hittable creature?


Hmm, maybe. It would most likely require some testing an tinkering though.

You could perhaps try using player->GetSoundPlaying with certain sounds to see when the player performs a weapon swish, a bow fire, or a crossbow fire sound. I think I did something similar at some point in the past and actually got it to work.

The harder part would be determining whether the player has the object in his crosshair or not. GetTarget should work for this purpose, but only as long as the object is actually in activation reach. But maybe, just maybe you could add a high magnitude one frame telekinesis effect (spell ability) to the player. If you make the object an item (e.g. a misc item instead of an activator), the telekinesis should make the object's name appear on screen for a frame even if it's far away, as long as you're looking in its way. At this point it should be possible to check whether or not the player was looking at the object using GetTarget.

There are a lot of ifs and maybes in this method, but if you manage to get it working that would be pretty cool.

Edit: Nevermind about GetTarget, it only works with actors. You can use the MWSE function xGetPCTarget instead.
User avatar
kristy dunn
 
Posts: 3410
Joined: Thu Mar 01, 2007 2:08 am

Post » Tue Aug 23, 2011 2:22 pm

Desired object dont return true on gettarget for me, unfortunately. Now, I'm trying to make full-transparent creature (I've picked lorkhan's heart because of static model), but I don't have any idea how to hide it completely...
User avatar
SUck MYdIck
 
Posts: 3378
Joined: Fri Nov 30, 2007 6:43 am

Post » Tue Aug 23, 2011 11:22 am

What about a paralyzed NPC of a race with no mesh assigned? They are usually used as collision "sonar" detectors, but should do for your needs too.
User avatar
Russell Davies
 
Posts: 3429
Joined: Wed Nov 07, 2007 5:01 am

Post » Tue Aug 23, 2011 12:07 am

Desired object dont return true on gettarget for me, unfortunately. Now, I'm trying to make full-transparent creature (I've picked lorkhan's heart because of static model), but I don't have any idea how to hide it completely...

Yeah, sorry. Shortly after I wrote my post I've realized GetTarget only works between two actors for some reason. It cannot be used to check for the player targeting an item or container.

That said, I've since tried making something similar to my suggestion above using xGetPCTarget instead of GetTarget. It requires MWSE but it works. And there's no invisible creature or NPC involved.

What I did was add a barrel (container) to the Balmora Guild of Mages, and add this script to it:

Begin adul_test_lookatme_b_scrshort doOnceif ( MenuMode == 1 )	Returnendifif ( "player"->GetSoundPlaying, "Weapon Swish" == 1 )	if ( doOnce == 0 )		StartScript, "adul_test_lookatme_scr"		set doOnce to 1	endifelseif ( doOnce == 1 )	set doOnce to 0endifEnd

This script checks every frame whether the player is swishing his weapon, and if he does, it runs the global script "adul_test_lookatme_scr". Right now it does not work with bows or crossbows but making changes to it to allow that wouldn't be too hard. The adul_test_lookatme_scr script is as follows:

Begin adul_test_lookatme_scrshort doOnceshort stemplong pcreflong tempif ( MenuMode == 1 )	Returnendifif ( doOnce == 0 )	"player"->AddSpell, "adul_test_lookatme_sp"	set doOnce to 1	Returnendifsetx pcref to xGetRef, "player"xSetRef, pcrefset stemp to GetSpellEffects, "adul_test_lookatme_sp"if ( stemp == 0 )	Returnendifsetx temp to xGetPCTarget"player"->RemoveSpell, "adul_test_lookatme_sp"set doOnce to 0StopScript, "adul_test_lookatme_scr"if ( temp == 0 )	Returnendifsetx temp to temp->xGetBaseIDsetx temp to xStringCompare, temp, "adul_test_lookatme"if ( temp != 0 )	ReturnendifMessageBox, "Ouch!"End

The spell "adul_test_lookatme_sp" is a 1000 point telekinesis spell that has the ability checkbox checked. Every time you swing your weapon, the spell gets added to you for 1 frame, and if you're looking in the direction of the barrel, the barrel will say "Ouch!"
User avatar
Katy Hogben
 
Posts: 3457
Joined: Mon Oct 30, 2006 12:20 am


Return to III - Morrowind