Script failing to unquip right-hand weapon

Post » Wed Oct 10, 2012 8:16 am

Hey fellow modders.

It seems this script is failing to unequip the right-hand weapon which is a dagger type weapon, it does however work for the left hand.

Here is the script:

------------------------------------------------------------------------------------------------------------------------------------------------------
Scriptname aaaQManageEffectsThresholdsScript extends Quest

if (game.getplayer().GetEquippedItemType(0) == 2) && GlobalStatStrength.getvalue() &--#60; 1
Game.GetPlayer().UnequipItem(Game.GetPlayer().GetEquippedWeapon(false))
Debug.Notification("You require 1 strength to wield daggers")
endif
if (game.getplayer().GetEquippedItemType(1) == 2) && GlobalStatStrength.getvalue() &--#60;
1
Game.GetPlayer().UnequipItem(Game.GetPlayer().GetEquippedWeapon(true))
Debug.Notification("You require 1 strength to wield daggers")
endIf


------------------------------------------------------------------------------------------------------------------------------------------------------

Any ideas?

P.S. apologies for typos.

:confused:
User avatar
Kaley X
 
Posts: 3372
Joined: Wed Jul 05, 2006 5:46 pm

Post » Wed Oct 10, 2012 6:10 am

Try:
Spoiler
ScriptName YourPlayerAliasScript Extends ReferenceAliasActor Property PlayerREF AutoGlobalVariable Property GlobalStatStrength AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	If GlobalStatStrength.GetValue() < 1.0		If PlayerREF.GetEquippedItemType(0) == 2 || PlayerREF.GetEquippedItemType(1) == 2			Debug.Notification("You require 1 strength to wield daggers")			PlayerREF.UnequipItem(akBaseObject)		EndIf	EndIfEndEvent
?
User avatar
Gracie Dugdale
 
Posts: 3397
Joined: Wed Jun 14, 2006 11:02 pm

Post » Wed Oct 10, 2012 9:45 am

Hope you figure it out, though this should be in the Creation Kit forum.
User avatar
BrEezy Baby
 
Posts: 3478
Joined: Sun Mar 11, 2007 4:22 am

Post » Wed Oct 10, 2012 4:50 am

Try:
Spoiler
ScriptName YourPlayerAliasScript Extends ReferenceAliasActor Property PlayerREF AutoGlobalVariable Property GlobalStatStrength AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	If GlobalStatStrength.GetValue() < 1.0		If PlayerREF.GetEquippedItemType(0) == 2 || PlayerREF.GetEquippedItemType(1) == 2			Debug.Notification("You require 1 strength to wield daggers")			PlayerREF.UnequipItem(akBaseObject)		EndIf	EndIfEndEvent
?

Updated my post...

I am using a quest to handle this script which works with OnUpdate.

:ermm:
User avatar
Roberta Obrien
 
Posts: 3499
Joined: Tue Oct 23, 2007 1:43 pm

Post » Wed Oct 10, 2012 8:21 pm

Using an alias would work better and 'cost' less, running the code exactly when it needs to and at no other time.
User avatar
Mark Churchman
 
Posts: 3363
Joined: Sun Aug 05, 2007 5:58 am

Post » Wed Oct 10, 2012 12:25 pm

Try:
Spoiler
ScriptName YourPlayerAliasScript Extends ReferenceAlias Actor Property PlayerREF Auto GlobalVariable Property GlobalStatStrength Auto Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) If GlobalStatStrength.GetValue() &--#60; 1.0 If PlayerREF.GetEquippedItemType(0) == 2 || PlayerREF.GetEquippedItemType(1) == 2 Debug.Notification("You require 1 strength to wield daggers") PlayerREF.UnequipItem(akBaseObject) EndIf EndIf EndEvent
?

Here is the new script:
Scriptname aaaQManageEffectsThresholdsScript extends Quest

if GlobalSPECIALStatStrength.getvalue() &--#60; 1.0
if (game.getplayer().GetEquippedItemType(0) == 2) || (game.getplayer().GetEquippedItemType(1) == 2)
Game.GetPlayer().UnequipItem(Game.GetPlayer().GetEquippedWeapon(false))
Game.GetPlayer().UnequipItem(Game.GetPlayer().GetEquippedWeapon(true))
Debug.Notification("You require 1 SPECIAL strength to wield daggers")
endif
endIf

It works almost perfectly, only snag is that if you wield say a dagger and a sword then both weapons will be unequipped regardless of any value. Its almost impossible to avoid this happening when using a script to perform this action due to how dual-wielding functions in the game itself.

Using an alias would work better and 'cost' less, running the code exactly when it needs to and at no other time.

How would I go about using an alias?

:biggrin:
User avatar
Danii Brown
 
Posts: 3337
Joined: Tue Aug 22, 2006 7:13 am

Post » Wed Oct 10, 2012 7:58 am

The provided script will work better and substantially faster/'cheaper'. Using a PlayerREF property is literally *1,000 times faster/less 'expensive' than http://www.creationkit.com/GetPlayer_-_Game. Also, if you use the http://www.creationkit.com/Quest_Alias_Tab approach, the code will be more responsive and will only run when necessary. Polling for changes like that in an http://www.creationkit.com/OnUpdate_-_Form event is really not the way to go given Skyrim's scripting is event based and affords better ways (http://www.creationkit.com/OnObjectEquipped).

*
Spoiler
  • PlayerREF Property:
    [09/02/2012 - 10:33:09PM] Started 'PlayerRef' at: 36.411999 | Iterations to complete: 10000[09/02/2012 - 10:33:09PM] Finished 'PlayerRef' at: 36.410889 | Iterations completed: 10000[09/02/2012 - 10:33:09PM] Time elapsed (Raw) for 'PlayerRef': 0.041000[09/02/2012 - 10:33:09PM] Time elapsed (Calibrated) for 'PlayerRef': 0.000000[09/02/2012 - 10:33:09PM] Approximate time for each iteration (Raw): 0.000004[09/02/2012 - 10:33:09PM] Approximate time for each iteration (Calibrated): 0.000000
  • GetPlayer:
    [09/02/2012 - 10:34:53PM] Started 'GetPlayer' at: 37.485001 | Iterations to complete: 10000[09/02/2012 - 10:34:53PM] Finished 'GetPlayer' at: 140.839890 | Iterations completed: 10000[09/02/2012 - 10:34:53PM] Time elapsed (Raw) for 'GetPlayer': 103.397003[09/02/2012 - 10:34:53PM] Time elapsed (Calibrated) for 'GetPlayer': 103.354897[09/02/2012 - 10:34:53PM] Approximate time for each iteration (Raw): 0.010340[09/02/2012 - 10:34:53PM] Approximate time for each iteration (Calibrated): 0.010335
User avatar
JUan Martinez
 
Posts: 3552
Joined: Tue Oct 16, 2007 7:12 am

Post » Wed Oct 10, 2012 9:41 am

The provided script will work better and substantially faster/'cheaper'. Using a PlayerREF property is literally *1,000 times faster/less 'expensive' than http://www.creationkit.com/GetPlayer_-_Game. Also, if you use the ReferenceAlias approach, the code will be more responsive and will only run when necessary. Polling for changes like that in an http://www.creationkit.com/OnUpdate_-_Form event is really not the way to go given Skyrim's scripting is event based and affords better ways (http://www.creationkit.com/OnObjectEquipped).

Using PlayerREF would be better I suppose, but regardless I know next to nothing about using alias.

:banana:
User avatar
Rinceoir
 
Posts: 3407
Joined: Thu Jun 29, 2006 1:54 am

Post » Wed Oct 10, 2012 6:19 am

Aliases are a breeze and understanding/using them will prove highly enabling. All you've to do is open up your quest, go to the "Quest Aliases" tab > R-Click > "New Reference Alias". Once the alias is created, select "Specific Reference" and "Select Forced Reference". In the resulting "Choose Reference" window, select PlayerREF as found within the "(any)" cell of the "Cell" dropdown box. That alias is now filled with [ACHR:00000014], so ReferenceAlias script(s) attached to your alias will run accordingly.
User avatar
Lizzie
 
Posts: 3476
Joined: Sun Nov 19, 2006 5:51 am


Return to V - Skyrim