Help with weapon script

Post » Fri Dec 11, 2009 1:38 pm

I am making a script for a mod. I can't test it in game because my computer has apparently forgotten that it has a disc drive :brokencomputer: (any ideas on that?).

Anyway, here's what I want it to do,

I have a mesh which has a "blade-out" and "blade-in" form. They both are actually set up as armor, so I made an invisible dagger. When the player draws the invisible dagger I want the active bracer to be added and equipped. When the blade is sheathed, I want the inactive version to be added and equipped. However, I'm not sure if my script will account for when the invisible dagger is NOT equipped, as in, I think that if the script runs through and then I unequip the invisible dagger, then the inactive bracer will still be there.

If I haven't been clear please ask me to clarify.

Will it do it? Any issues?

begin md_OOTL_bladeif (hasitemequipped "md_amael_invisidagger" == 0)	Returnendifif (getweapondrawn == 1)	additem "md_amael_blade_active" 1	equip "md_amael_blade_active"	removeitem "md_amael_blade_inactive" 1elseif (getweapondrawn == 0)	additem "md_amael_blade_inactive" 1	equip "md_amael_blade_inactive"	removeitem "md_amael_blade_active" 1endifend


Thanks,
-Melchior Dahrk
User avatar
Alex Blacke
 
Posts: 3460
Joined: Sun Feb 18, 2007 10:46 pm

Post » Fri Dec 11, 2009 10:55 pm

It looks like it would work, but that you already identified the issue -- if the latter section runs once and then the dagger is removed, the extra piece will remain in inventory. Here's one quick solution, though perhaps not elegant:

begin md_OOTL_bladeif ( hasitemequipped "md_amael_invisidagger" == 0 )	if ( GetItemCount "md_amael_blade_active" > 0 )		RemoveItem "md_amael_blade_active" 1	endif	if ( GetItemCount "md_amael_blade_inactive" > 0 )		RemoveItem "md_amael_blade_inactive" 1	endif	Returnendifif ( getweapondrawn == 1 )	additem "md_amael_blade_active" 1	equip "md_amael_blade_active"	removeitem "md_amael_blade_inactive" 1elseif ( getweapondrawn == 0 )	additem "md_amael_blade_inactive" 1	equip "md_amael_blade_inactive"	removeitem "md_amael_blade_active" 1endifend

User avatar
Elle H
 
Posts: 3407
Joined: Sun Aug 06, 2006 3:15 am

Post » Fri Dec 11, 2009 1:55 pm

Thanks NMZmaster. As soon as I am able to test it out (though that may be a while :meh:) I will try your version out. BTW, I have this attached to an NPC right now, could I have this attached to the dagger itself so that it would work for the Player?
User avatar
Julia Schwalbe
 
Posts: 3557
Joined: Wed Apr 11, 2007 3:02 pm

Post » Fri Dec 11, 2009 7:28 pm

Thanks NMZmaster. As soon as I am able to test it out (though that may be a while :meh:) I will try your version out. BTW, I have this attached to an NPC right now, could I have this attached to the dagger itself so that it would work for the Player?


You should be able to attach the script to the dagger directly without any issues, I think, but of course you'll have to make the minor syntax changes required to correctly check the player's status. So for instance, instead of:

if ( hasitemequipped "md_amael_invisidagger" == 0 )

It would be:

if ( Player -> HasItemEquipped "md_amael_invisdagger" == 0 )
User avatar
Roberta Obrien
 
Posts: 3499
Joined: Tue Oct 23, 2007 1:43 pm

Post » Fri Dec 11, 2009 2:04 pm

Could I make the script workable for NPCs and the Player? So it can transition seamlessly between the two?
User avatar
ONLY ME!!!!
 
Posts: 3479
Joined: Tue Aug 28, 2007 12:16 pm

Post » Fri Dec 11, 2009 1:50 pm

I just tried this out in-game (my computer gave me a short reprieve). It doesn't work... the NPC just attacks me with the invisible dagger. But not bracers appear. Any idea what might be going on?
User avatar
joseluis perez
 
Posts: 3507
Joined: Thu Nov 22, 2007 7:51 am

Post » Sat Dec 12, 2009 2:36 am

Do you have this script attached to the NPC, or the dagger itself, currently?

Assuming that the dagger is unique, the following script (attached to the dagger) should work for both the player and the particular NPC in question. Substitute npcID for the ID of the NPC in question.

If you wanted to optimize this a bit you could add a frameskip block, but it might delay updating the weapon status a bit. Again, this probably isn't the most elegant, but I believe it should function appropriately.

begin md_OOTL_blade;Make sure that the NPC doesn't get left with any extra pieces when the player takes the blade or it is otherwise unequippedif ( npcID -> HasItemEquipped "md_amael_invisidagger" == 0 )	if ( npcID -> GetItemCount "md_amael_blade_active" > 0 )		npcID -> RemoveItem "md_amael_blade_active" 1	endif	if ( npcID -> GetItemCount "md_amael_blade_inactive" > 0 )		npcID -> RemoveItem "md_amael_blade_inactive" 1	endifendif;Make sure that the player doesn't get left with any extra pieces if they drop the blade or if it is otherwise unequippedif ( Player -> HasItemEquipped "md_amael_invisidagger" == 0 )	if ( Player -> GetItemCount "md_amael_blade_active" > 0 )		Player -> RemoveItem "md_amael_blade_active" 1	endif		if ( Player -> GetItemCount "md_amael_blade_inactive" > 0 )		Player -> RemoveItem "md_amael_blade_inactive" 1	endif	Returnendif;If the NPC has the dagger equipped, adjust state accordinglyif ( npcID -> HasItemEquipped "md_amael_invisidagger" == 1 )	if ( npcID -> GetWeaponDrawn == 1 )		npcID -> AddItem "md_amael_blade_active" 1		npcID -> Equip "md_amael_blade_active"		npcID -> RemoveItem "md_amael_blade_inactive" 1	elseif ( npcID -> GetWeaponDrawn == 0 )		npcID -> AddItem "md_amael_blade_inactive" 1		npcID -> Equip "md_amael_blade_inactive"		npcID -> RemoveItem "md_amael_blade_active" 1	endifendif;If the player has the dagger equipped, adjust state accordinglyif ( Player -> HasItemEquipped "md_amael_invisidagger" == 1 )	if ( Player -> GetWeaponDrawn == 1 )		Player -> AddItem "md_amael_blade_active" 1		Player -> Equip "md_amael_blade_active"		Player -> RemoveItem "md_amael_blade_inactive" 1	elseif ( Player -> GetWeaponDrawn == 0 )		Player -> AddItem "md_amael_blade_inactive" 1		Player -> Equip "md_amael_blade_inactive"		Player -> RemoveItem "md_amael_blade_active" 1	endifendifend

User avatar
Tai Scott
 
Posts: 3446
Joined: Sat Jan 20, 2007 6:58 pm

Post » Fri Dec 11, 2009 6:29 pm

Thank you very much! I will try this out tomorrow!

p.s. I tested it attached to the dagger.
User avatar
Steve Bates
 
Posts: 3447
Joined: Sun Aug 26, 2007 2:51 pm

Post » Fri Dec 11, 2009 2:00 pm

Thank you very much! I will try this out tomorrow!

p.s. I tested it attached to the dagger.


No problem, hope it helps :)

That explains why you got no result previously; the dagger was running the script, and so all commands called without a specific object (i.e. GetWeaponDrawn instead of object -> GetWeaponDrawn) will assume the attached object is the intended target. With the new script, it should properly target your NPC and the Player so long as that NPC and the dagger are both unique.
User avatar
celebrity
 
Posts: 3522
Joined: Mon Jul 02, 2007 12:53 pm

Post » Fri Dec 11, 2009 12:35 pm

Well, actually the NPC I want to attach it to will be set up as a reocurring guard. Will that break the script?
User avatar
naana
 
Posts: 3362
Joined: Fri Dec 08, 2006 2:00 pm

Post » Fri Dec 11, 2009 10:05 pm

Do you mean that the NPC will respwan, or that there will be multiple copies of it simultaneously?

If there are multiple copies of the NPC, it would be best to create a local script attached to the NPC which handles things, while a second script could be attached to the dagger which would handle the player side.

The NPC's local script could be as we defined earlier:

begin md_OOTL_NPCif ( hasitemequipped "md_amael_invisidagger" == 0 )	if ( GetItemCount "md_amael_blade_active" > 0 )		RemoveItem "md_amael_blade_active" 1	endif	if ( GetItemCount "md_amael_blade_inactive" > 0 )		RemoveItem "md_amael_blade_inactive" 1	endif	Returnendifif ( getweapondrawn == 1 )	additem "md_amael_blade_active" 1	equip "md_amael_blade_active"	removeitem "md_amael_blade_inactive" 1elseif ( getweapondrawn == 0 )	additem "md_amael_blade_inactive" 1	equip "md_amael_blade_inactive"	removeitem "md_amael_blade_active" 1endifend


The dagger's script (which would affect the player) could be a variant of the previous script:

begin md_OOTL_blade;Make sure that the player doesn't get left with any extra pieces if they drop the blade or if it is otherwise unequippedif ( Player -> HasItemEquipped "md_amael_invisidagger" == 0 )	if ( Player -> GetItemCount "md_amael_blade_active" > 0 )		Player -> RemoveItem "md_amael_blade_active" 1	endif		if ( Player -> GetItemCount "md_amael_blade_inactive" > 0 )		Player -> RemoveItem "md_amael_blade_inactive" 1	endif	Returnendif;If the player has the dagger equipped, adjust state accordinglyif ( Player -> HasItemEquipped "md_amael_invisidagger" == 1 )	if ( Player -> GetWeaponDrawn == 1 )		Player -> AddItem "md_amael_blade_active" 1		Player -> Equip "md_amael_blade_active"		Player -> RemoveItem "md_amael_blade_inactive" 1	elseif ( Player -> GetWeaponDrawn == 0 )		Player -> AddItem "md_amael_blade_inactive" 1		Player -> Equip "md_amael_blade_inactive"		Player -> RemoveItem "md_amael_blade_active" 1	endifendifend


Hopefully I didn't miss anything, but I believe those should perform as you'd like.
User avatar
Emilie Joseph
 
Posts: 3387
Joined: Thu Mar 15, 2007 6:28 am

Post » Sat Dec 12, 2009 1:18 am

Yeah, the NPC will both respawn and have multiple copies. But will do what you suggest and attach one script to the dagger for the player and then script the other NPCs. Thanks again. I'll post here again if it works/doesn't work.
User avatar
SamanthaLove
 
Posts: 3565
Joined: Mon Dec 11, 2006 3:54 am


Return to III - Morrowind