Jump to content

Custom Script Effects


Recommended Posts

I've had many mods put on hold because I've found scripting a bit difficult. So Im just going to place what I WANT a script to do (with OBSE) witht eh hope that someone can translate it for me:

 

Scn GripChangerAlpha

 

When the UpArrowKey is pressed

Game detects of you have a weapon equipped

Detects what type of weapon you have equipped (1H Blade /2H Blade etc)

Will then switch the grip to opposite (1Hand Blade becomes 2H Blade vice verse)

endif

 

 

 

 

I have a spell that does this but it's only one way and has a few bugs.

 

Link to comment
Share on other sites

UNTESTED:

 

First, I made a UDF to get an actor's exact equipped weapon. This needs to be an Object script:

scn FnGetEquippedWeaponRef

;returns the passed actor's currently equipped weapon as an inventory reference

ref rActorRef

ref rWeap
array_var aEntry

begin Function { rActorRef }

	let rWeap := rActorRef.GetEquippedObject 16

	if (rWeap)

		foreach (aEntry <- GetInvRefsForItem rWeap)

			let rWeap := *aEntry

			if (rWeap.IsEquipped)
				break
			endif

		loop

	endif

	let aEntry := ar_Null

	SetFunctionValue rWeap

end

And this script will handle the keypress and grip changing (attach to a quest):

scn GripChangerQuestSCRIPT

float fQuestDelayTime

ref rWeap

begin GameMode

	if (fQuestDelayTime != 0.1)
		let fQuestDelayTime := 0.1
	endif

	if (PlayerREF.IsWeaponOut)
		if (OnControlDown 200)

			let rWeap := PlayerREF.GetEquippedObject 16

			if (rWeap)

				if (GetWeaponType rWeap == 0)
					SetWeaponType rWeap 1
				elseif  (rWeap.GetWeaponType rWeap == 1)
					SetWeaponType rWeap 0
				elseif  (rWeap.GetWeaponType rWeap == 2)
					SetWeaponType rWeap 3
				elseif  (rWeap.GetWeaponType rWeap == 3)
					SetWeaponType rWeap 2
				else
					let rWeap := 0
					return
				endif

				let rWeap := Call FnGetEquippedWeaponRef PlayerREF
				rWeap.UnEquipMe
				rWeap.EquipMe

				let rWeap := 0

			endif

		endif
	endif

end

Hopefully that should work...

Edited by PushTheWinButton
Link to comment
Share on other sites

Thanks, i'll test this right away. I should've posted in the original, but this is the magic effect alpha script that I made:

Scn GripChangerBladeOne
begin ScriptEffectStart
ref weapon
short weapontype
set weapon to player.GetEquippedObject 16
SetWeaponType 1 weapon
end
this spell script does indeed change a 1hand sword to 2hand if you have a weapon out and cast the spell. But no way to turn it back uless you use a different spell. And you will still have a shield equipped, even in a 2handed grip.
Link to comment
Share on other sites

Oops, I ordered the parameters wrong. Change them all to have rWeap after the number.

 

Also noticed that "GetInvRefsForItem" in the UDF needs to read "rActorRef.GetInvRefsForItem". Sorry 'bout that.

 

TBH, the UDF function could be incorporated into the main script but I just like to separate stuff like that out for ease of reading.

Edited by PushTheWinButton
Link to comment
Share on other sites

@PushTheWinButton

Your script is very good, but you made some unnecessary work.

The grip/weapon type is a weapon base object's property (not a reference's attribute). This means the property is one and shared across all the weapon's reference. Trying to change it for a specific reference is meaningless, as the game will not find such property on the reference, so it search in the base object (so, passing the base object lead to the same result: all weapons of that base object will change grip).

 

For this reason, searching for the specific equipped weapon is not needed. You can use a much simpler script like one written by Manus812 (take the equipped weapon base object, change it's grip, unequip and equip it again).

scn GripChangerBladeOne

ref weapon
short weapontype

Begin ScriptEffectStart

  Set weapon to Player.GetEquippedObject 16
  Set weaponType to GetWeaponType weapon

  If (weaponType == 0 || weaponType == 2)    ;1H blade or blunt
    Let weaponType += 1    ;from 0/2 to 1/3
  ElseIf (weaponType == 1 || weaponType == 3)  ;2H blade or blunt
    Let weaponType -= 1   ;from 1/3 to 0/2
  Else   ;it's a staff or bow
    Return   ;don't touch it
  EndIf

  SetWeaponType weaponType weapon

End

Be careful anyway: as I said, the property is one and shared across all weapon's references: all weapons of that type in the world will have the new grip, and the NPC too will equip the weapon with the new grip.

Unluckily, there's no way to apply a similar change to a specific weapon (unless you clone it and create a new base object, but this will bloat the savegame). Oblivion limitations!

Edited by forli
Link to comment
Share on other sites

Thanks for the input forli, thats actually exactly what happens, any NPC who has teh same weapon as you will also change grips.

https://forums.nexusmods.com/index.php?/topic/3993345-custom-grip-spell-script/

here is a thread I made in April of this topic, you all can look at it for context and what it was before. Now I'm trying to remake the mod from the ground up, but some questions was answered in the old thread. Thanks for the help guys, I'll be testing it out soon.

In the previous version, some bugs were:

- If NPC has same weapon as you and you switch grips, they will too (Tested fighting guards with Silver Longswords, we changed grips at same time)

- If you switch grip without the weapon being drawn, it will be invisible when you draw, so you can only switch grips properly if you have the weapon drawn in your hand.

- If you have a shield + 1H and you switch to 2H, you will still have shield equipped and can use it with a 2H weapon, which is overpowered. (We should try and modify the script to also detect if you have a shield when switching from 1H --> 2H and unequip it. And somehow re-equip it if going 2H --> 1H)

 

IN future versions, I also want some way to increase/decrease damage values when switching grips, or else why would you change unless its just for cosmetics.

Edited by Manus812
Link to comment
Share on other sites

I know. The purpose of the reference was to re-equip the same weapon in case the player has multiple (i.e. so that it has the same condition and enchantment, etc). Using UnEquipItem and EquipItem equips your highest condition version of the item. Re-equipping the item is needed to change the grip animation visually, and should force-unequip the shield.

 

Of course, it wasn't my intention to fix all the problems with the concept - that wasn't what the OP asked for. But here goes:

 

To stop all NPCs using the grip, you'll need to clone the weapon - there's no way around that. By using two remote containers you could use the indices to pair all cloned weapons with their original versions, to save re-cloning weapons. So, for example, one container could be for one-handed and the other for two, and index one of the first chest will be the vanilla one-handed Iron Longsword and index one in the other will be the clones two-handed variant. When the player switches grip, their current weapon is removed (probably to a third container for safekeeping), and the paired weapon is added and equipped.

 

The upside of using clones is that changes to them are saved permanently, therefore any grip and damage changes would only need to be done once. Therefore all you have to do is write a script to retrieve/make clones when the player presses the key, depending on whether or not a clone already exists (container.GetItemCount would be the check). The downside is that there's a potential for savegame bloat. Enchanted items and player-made potions are also clones, though, so its down to you to decided whether cloning weapons only when the player switches their grip is more or less detrimental. A TempCloneForm like in New Vegas would be better, but Oblivion doesn't have that.

 

Hope that helps. I don't have time to write an example right now.

Edited by PushTheWinButton
Link to comment
Share on other sites

@PushTheWinButton: that's correct.

Yeah, I forgot the Equip/Unequip part to update the equipped weapon graphic and animation.

Still I don't feel it's necessary to keep track of the exact equipped weapon reference: having 2 or more weapons of the same type is not very common, and eventually (IMHO) I would like to have the highest condition one equipped (so it even makes me a favour!).

 

I advise against using CloneForm until the new OBSE v22 come out (it will add a command to destroy cloned forms).

Yeah, enchanted items and potions are clones as well, but they have been created by the vanilla game, which probably (can't be sure) track and then dispose them when unused. In the past some players reported their savegame size didn't increase after having enchanted tons items and created tons potions, sold them all and wait for the merchant to respawn its stock.

 

PS: little tip: you don't need to clean an array variables with let aEntry := ar_Null. OBSE keep track of arrays and automatically destroy them (as opposite to strings).

Edited by forli
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...