Jump to content

Why Does my script stop working when item is unequipped?


OvadWolfeye

Recommended Posts

scn OvadBowScript
short active
short Igot
short Iwant
short Ineed
Ref OvadArrow


Begin OnEquip
	set OvadArrow to Player.GetEquippedObject 17
	set active to 1
End

Begin OnUnEquip
	set active to 0
End

Begin GameMode

		If OnKeyDown 256 && Active == 1
			set OvadArrow to Player.GetEquippedObject 17
		Else
		 Return
		endif

		If active == 1
			set Igot to Player.GetItemCount OvadArrow
			set Iwant to 2
				If Igot == 1 || Igot < 1
				set Ineed to Iwant - Igot
				Player.AddItemNS OvadArrow Ineed
				endif

		endif
end

Begin MenuMode

End

So My script if for a bow to have unlimited arrows for whatever arrow is currently equipped. It works well enough, but has a major flaw. When I unequip an arrow and change arrows the bow changes the reference to the new narrow and life goes on, however, if I mistakenly unequip the bow ( whether or not the currently associated arrow remains equipped or has already been unequipped) the script seems to stop functioning.

 

Any advice on where to look for a remedy to this headache would be greatly appreciated.

 

 

 

I also just realized that I am posting in the wrong section, sorry I am still a bit new to all this forum stuff. I will be posting scripting questions under the mod talk construction set forum in the future.

Edited by CountryRoberts
Link to comment
Share on other sites

Ok I fixed the error of the bow being unequipped by changing script to this:

scn OvadBowScript
short active
short Igot
short Iwant
short Ineed
Ref OvadArrow


Begin OnEquip
	set active to 1
End

Begin OnUnEquip
	set active to 0
End

Begin GameMode
	If Active == 0
		set Ovadarrow to Arrow1Iron
	Endif

	If active == 1
	If onkeydown 256
		set Ovadarrow to player.getequippedobject 17
	Else
		 Return
	endif

		set Igot to Player.GetItemCount OvadArrow
		set Iwant to 2
			If Igot == 1 || Igot < 1
			set Ineed to Iwant - Igot
			player.additemNS OvadArrow Ineed
			endif

	endif
	
end

Begin MenuMode
	If Active == 0
		set Ovadarrow to Arrow1Iron
	Endif
End

Now I need to determine how to prevent attacking if no arrow is equipped from freezing this script.

Link to comment
Share on other sites

Well to start with, the script looks perfect.

 

What I do when a script not work as I thought it would, I would insert some debugging and the mod Conscribe is very helpful but not necessary needed and also messagelogger in case the game writes something about your bowscript there.

 

I would Insert some prIntc or scribe (From Conscribe (The format will be exact the same)) at 4 places. So if you use Conscribe, exchange printc with scribe.

scn OvadBowScript
short active
short Igot
short Iwant
short Ineed
Ref OvadArrow


Begin OnEquip
	set OvadArrow to Player.GetEquippedObject 17
	set active to 1

	Printc "Active = %.0f", active
End

Begin OnUnEquip
	set active to 0
End

Begin GameMode

		If OnKeyDown 256 && Active == 1
			set OvadArrow to Player.GetEquippedObject 17

			Printc "OvadArrow = %.i %n", OvadArrow, OvadArrow

		Else
		 Return
		endif

		If active == 1
			set Igot to Player.GetItemCount OvadArrow
			set Iwant to 2
				If Igot == 1 || Igot < 1
				set Ineed to Iwant - Igot
				Player.AddItemNS OvadArrow Ineed
				
				Printc "Ineed = %.0f", Ineed
				
				endif

		endif
end

Begin MenuMode
	Printc "Bow is used from the inventory"
End

So what is AddItemNS as it is painted blue in Notepad++ and obviously a working function according to its color but I cannot find it in CS Wiki nor in OBSE documentation. Try to exchange it to Additems maybe?

 

Well with the debug rows inserted in the script, you will see where it stops to function as it will run but stop in the middle somewhere and the last printc/scribe, will indicate where exactly it stops. You can later insert more rows to get info about each and every step your script makes. When a script runs into problems, it will never run again, so even if the script looks perfect, it might be not?

 

I saw you edited the script as well. Well insert the debug info anyway...

Edited by Pellape
Link to comment
Share on other sites

Odd that it is not mentioned anywhere, damn, I was newly awaken and searched for something else... :D

 

Okay. Well insert the debugging and see exactly where the script stops to work as it will also inform you if it is running or not in the console.

Link to comment
Share on other sites

  • 3 months later...

It seems your script is freezing within GameMode area because it's always assuming that GetEquippedObject command will return something. But if there aren't any arrows equipped or you are ran out of them, the result will be zero.

 

For possible solution I would suggest something like this:

 

adding extra reference for remembering the arrows:

ref LastArrow

 

and:

 

begin GameMode

If OnKeyDown 256 && active == 1

set OvadArrow to player.GetEquippedObject 17

If OvadArrow == 0 ; no arrows

If LastArrow != 0 ; there was arrows equipped

set OvadArrow to LastArrow ; select them

set Igot to player GetItemCount OvadArrow ; are there some ?

if Igot != 0

player.EquipItemSilent OvadArrow

return

endif

else ; no

set OvadArrow to Arrow1Iron ; set to some default arrows

set Igot to player.GetItemCount OvadArrow ; are they in inventory already?

If Igot != 0

player.EquipItemSilent OvadArrow ; equip them

return

endif

endif

else

If LastArrow != OvadArrow ; different arrows ?

set LastArrow to OvadArrow ; remeber them

endif

endif
else
return
endif

If active == 1 && OvadArrow != 0
set Igot to player.GetItemCount OvadArrow
set Iwant to 2
If Igot < Iwant
set Ineed to Iwant - Igot
player.AddItemNS OvadArrow Ineed
If Igot == 0 ; in this case you need equip arrows

player.EquipItemSilent OvadArrow
endif
endif

endif

end

 

I'm typing this from scratch, but I still hope this will help you.

Link to comment
Share on other sites

  • 2 years later...
On 1/18/2021 at 9:20 AM, OvadWolfeye said:

The AdditemNS adds the referenced object without haveing a message pop up on screen saying that said object has been added.

Hello, new modder here, somehow knew that it was for something like that...I just want to ask, is that a function of the Standard CS for Oblivion? I have found it in some mods but doesn´t compile if I try to use it.  And if I need to install/enabe something else could you tell me how please?

thanks in advance

Edited by DrekVolker
Link to comment
Share on other sites

6 minutes ago, DrekVolker said:

Hello, new modder here, somehow knew that it was for something like that...I just want to ask, is that a function of the Standard CS for Oblivion? I have found it in some mods but doesn´t compile if I try to use it.  And if I need to install/enabe something else could you tell me how please?

thanks in advance

AddItemNS is a function of  OBSE. It won't compile on plain CS.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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