Jump to content

Custom Bound Armor Spell


razorblade457

Recommended Posts

Hello! I'm new to modding.I am nearly finished creating a Bound Enchanted Armor Spell and the only thing that I need to add is the script where the player would go back to equipping whatever equipment they had on before casting this spell like in the regular bound armor spell.

 

Would anybody please help me?

 

Here is the script for the spell if required:

 

{Script}

 

scn MyPerfectArmorSpellScript

Begin ScriptEffectStart

 

player.additemns MyPerfectArmor001 1

player.additemns MyPerfectArmor002 1

player.additemns MyPerfectArmor003 1

player.additemns MyPerfectArmor004 1

player.additemns MyPerfectArmor005 1

 

player.equipitemns MyPerfectArmor001 1

player.equipitemns MyPerfectArmor002 1

player.equipitemns MyPerfectArmor003 1

player.equipitemns MyPerfectArmor004 1

player.equipitemns MyPerfectArmor005 1

 

ModPCSpellEffectiveness 0.05

end

 

Begin ScriptEffectFinish

 

player.removeitemns MyPerfectArmor001 1

player.removeitemns MyPerfectArmor002 1

player.removeitemns MyPerfectArmor003 1

player.removeitemns MyPerfectArmor004 1

player.removettemns MyPerfectArmor005 1

 

ModPCSpellEffectiveness -0.05

end

 

{/Script}

Link to comment
Share on other sites

To remember the original armor equip you can use two functions:

 

1. GetEquippedObject - given the slot number it will return Base Object equipped (or will be) in given slot. Best way is to use a field to store returning object, but you can use a ref variables too. After storing I would recommend a check to eliminate the duplicates as many items are multislotted.

2. GetEquippedItems - using a field it returns all equipped items on calling actor (Base Objects again). After run of this function you will again need run some checks - this time for eliminating items which aren't armor or clothing (IsArmor, IsClothing functions) and also check their slot assignment to eliminate rings, amulets, shields, quivers etc (GetBipedSlotMask function).

 

There are various way to stroll through inventory too (using ForEach for example), but as you are a beginner, I think these two functions will be most easy to use for you and for this task they are enough. It's also a good idea to ignore non-playable equip, because you never know if the mod using this type can solve the unequip/removal of this.

Edited by RomanR
Link to comment
Share on other sites

GetEquippedItems returns the items in the field, so you need a prepared field - this is how I made it:

.....
array_var items
int items_size
ref item
.....
begin ScriptEffectStart
...
;preparing field
let items_size := ar_Size items
if items_size ==  -1 ;field not prepared yet
	let items := ar_Construct Array
	let items[0] := 0
endif
...
let items := player.GetEquippedItems
;now checking if player has something equipped
let items_size := ar_Size items
set item to 0
if items_size > 0
        let item := items[0]
endif
if items_size > 0 && item != 0 ;there is something
   {success, insert commands for further checks}
endif
   

Just notice - before another use of GetEquippedItems I'm always cleaning a field:

ar_Resize items 1
let items[0] := 0
Edited by RomanR
Link to comment
Share on other sites

Thank you for replying.

 

I'm trying to use the GetEquippedItems function but I get an error when compiling the script.Can you please tell me how to use it with an example?

 

I checked in with the CSwiki and the syntax for that function is not of much help to be honest.

 

Are you starting the CS with OBSE support (GetEquippedItems is an OBSE function)).

Link to comment
Share on other sites

You need this field only to store original items you want equip after your spell finished. As I wrote the field also need cleanup of items which aren't armor or clothes and doesn't occupy the slots which your armor will do. Here's practically complete example:

 

 

scn CustomBoundSpellScript
ref item
ref actor
int items_size
int items_index
array_var items
int temp ; for various purposes
int cb_slots ; cb means custom bound 
int nonplay_slots 
short remove

begin ScriptEffectStart
	; custom bound begins
	let items_size := ar_Size items
	if items_size == -1
		let items := ar_Construct array
		let items[0] := 0
	endif
	set actor to GetSelf
	if actor != 0 
		let items := actor.GetEquippedItems
	endif
	let items_size := ar_Size items
	if items_size > 0
		let item := items[0]
	endif
	if items_size > 0 && item != 0
		; actor has some equipped, we need checks for armor/clothing
		set cb_slots to 63 ;head+hair+upper+lower+hands+feet
		set items_index to 0 
		while items_index < items_size
			set remove to 0
			let item := items[items_index]
			if eval (IsArmor item != 0 || IsClothing item != 0) ;cloth or armor?
				let temp := GetBipedSlotMask item
				if temp != 0
					if eval ( IsPlayable item == 0 && IsPlayable2 item == 0 ) ;non-playable item?
						set remove to 1
						let nonplay_slots := nonplay_slots | temp ; update "forbidden" slots 
					else
						let temp := temp & cb_slots
						if temp == 0 ; no match
							set remove to 1
						endif
					endif
				else
					set remove to 1
				endif				
			else
				set remove to 1
			endif
			if remove != 0
				ar_Erase items items_index
				let items_size := ar_Size items
			else
				set items_index to items_index + 1
			endif
		loop
	endif
	; now the equip part
	set items_index to 1 ;we will reuse this
	while items_index < 6
		if items_index == 1
			set item to MyPerfectArmor001
		endif
		if items_index == 2
			set item to MyPerfectArmor002
		endif
		if items_index == 3
			set item to MyPerfectArmor003
		endif
		if items_index == 4
			set item to MyPerfectArmor004
		endif
		if items_index == 5
			set item to MyPerfectArmor005
		endif
		if nonplay_slots != 0
			let temp := GetBipedSlotMask item
			let temp := nonplay_slots & temp
			if temp == 0
				actor.AddItemNS item 1
				actor.EquipItemNS item
			endif
		else
			actor.AdditemNS item 1
			actor.EquipItemNS item
		endif
		set items_index to items_index + 1
	loop	
end

begin ScriptEffectFinish
	;remove the bound armor
	set items_index to 1
	while items_index < 6
		if items_index == 1
			set item to MyPerfectArmor001
		endif
		if items_index == 2
			set item to MyPerfectArmor002
		endif
		if items_index == 3
			set item to MyPerfectArmor003
		endif
		if items_index == 4
			set item to MyPerfectArmor004
		endif
		if items_index == 5
			set item to MyPerfectArmor005
		endif
		set temp to actor.GetItemCount item
		if temp > 0
			actor.UnequipItemNS item ; if armor is unique, you can skip this
			actor.RemoveItemNS item 1
		endif
		set items_index to items_index + 1
	loop
	; and equip back original items
	let items_size := ar_Size items
	set item to 0
	if items_size > 0
		let item := items[0]
	endif
	if items_size > 0 && item != 0
		set items_index to 0
		while items_index < items_size
			set temp to 0
			let item := items[items_index]
			if item != 0
				set temp to actor.GetItemCount item
			endif
			if temp > 0
				actor.EquipItemNS item
			endif
			set items_index to items_index + 1
		loop
	endif
	; field cleanup
	ar_Resize items 0
	let items := ar_Null
end

 

 

 

This example also cares about nonplayable items and for safety reasons will not add and equip the pieces to the slots which such item occupies. Regarding your armor pieces they should in my opinion be also flagged as nonplayable, quest item and with zero weight, so other mods will not touch them and they will be invisible to the player in inventory. And if you want to be your armor to be unequipable, you can attach this simple script to your pieces:

scn CustomBoundItemScript
ref actor
ref me

begin OnUnEquip
	set actor to GetContainer
	set me to GetBaseObject
	if actor != 0 && me != 0
		actor.EquipItemNS me
		Message "This piece of armor is now bound to you."
	endif
end
Link to comment
Share on other sites

RomanR

 

First of all I don't know how to thank you for writing that much code for me.It must've taken you a long time.You've been a great help.

 

I've read some of it and I'm slowly trying to understand it.(I know its purpose basically based on what you've told me but I'm trying to learn more about what exactly the code does.)

 

 

As I've said I'm new to all this.You are obviously very good at CS and I have a question: How did you learn all of this?

Would you please offer me some advice on learning?

 

 

 

I've also applied the script into my spell and while it does work and equip my character with their previous equipment when the spell ends, the game crashes whenever I recast the spell while it is already in effect.Dispelling works though.

 

I think it's better to write a script where it will cancel the casting of the spell while it is in effect and put in a message saying that the spell is already in effect same as in regular Bound-spells?How about you?

Edited by razorblade457
Link to comment
Share on other sites

  • Recently Browsing   0 members

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