Jump to content

Script to get the charge amount of an item?


allomerus

Recommended Posts

Heyall!

 

I've got a little question: Is there, or is there not, a script command, such as ''GetItemChargeCount'', that would allow me to actually get the charge amount of a magical weapon through a script? I've looked around for it, and couldn't fint it.

 

Once I get that figured, all that will remain between me and the release of an amazing magical bow that generates its own enchanted arrows but needs reloading through soulgems... will be the release of Blender`s new Nifscripts... and me getting enough time to model the damn thing hehehe.

 

 

Thanks in advance for your help!

Edited by allomerus
Link to comment
Share on other sites

Hmmm... well, actually, turns out I'm going to need more help than I thought. Figures.

 

So I far, my greatest achievement in adding that script command (or different variations found on TESCSwiki) was creating a script that could be saved in the CS...

 

Can you please take a look at it? (references IDs: AlloThoridal is a bow, and AlloThoriAr an arrow)

 

***

 

scn AlloThoriScr

 

Ref Item

Float fQuestDelayTime

 

begin GameMode

 

if player.GetEquipped AlloThoridal

set fQuestDelayTime to .01

if player.GetEquippedCurrentCharge 9 > 64

set Item to AlloThoriAr

if player.GetItemCount Item == 0

player.AdditemNS Item 1

player.EquipItemNS Item

endif

endif

endif

 

Set Item to AlloThoriAr

if Player.Getitemcount item > 1

player.removeitemNS item 1

endif

 

end

 

***

 

The script, without the ''if player.GetEquippedCurrentCharge 9 > 64'' (10th line) works perfectly otherwise. my first idea was to simply make a bow with infinite enchantment that could spawn infinite arrows (Like the ''Paralyze bow with unlimited arrows'' mod) but also keep the number of arrows to 1 (the bow itself has an object script that removes the arrows when unequipped, but that's not pertinent right now I guess).

 

As it is now, the script does not cause any crash, it just dosen,t do anything.

 

Can you tell me what I'm doing wrong?

 

thanks again in advance for the help

Link to comment
Share on other sites

What kind of script is this? By that I mean is it an object attached to the bow or arrows - make sure that it is attached to something, because there have been several times I have been stuck on a script only to find I forgot to assign it to an object.

 

If I'm reading the script correctly, you want the script to only run when the bow is equipped, then add 1 arrow to the player if they have none and the bows charge is greater than 64.

If that is what you wanted, then it has been done correctly as far as I can tell, although there are a few things you should do when presenting scripts:

 

First, whenever you post a script highlight it all and press the button that looks like < > at the top (it's near the smilies menu).

It makes your script look like this

 

Also, it becomes easier to read if you add "indentations" to clarify between if blocks. it looks like this:

 

scn AlloThoriScr

Ref Item 
Float fQuestDelayTime 

begin GameMode 

if player.GetEquipped AlloThoridal
   set fQuestDelayTime to .01
   if player.GetEquippedCurrentCharge 9 > 64
       set Item to AlloThoriAr
       if player.GetItemCount Item == 0 
           player.AdditemNS Item 1 
           player.EquipItemNS Item 
       endif 
   endif 
endif

Set Item to AlloThoriAr
if Player.Getitemcount item > 1
   player.removeitemNS item 1
endif

end

 

Finally, whenever there is one condition that defines the whole script, you should add a "return" function to reduce CPU usage whenever you aren't using the bow. By that I mean something like this....

 

scn AlloThoriScr

Ref Item 
Float fQuestDelayTime 

begin GameMode 

if player.GetEquipped AlloThoridal == 0
   Return
Else
   set fQuestDelayTime to .01
   if player.GetEquippedCurrentCharge 9 > 64
       set Item to AlloThoriAr

;;;......And so on.....

Edited by WarRatsG
Link to comment
Share on other sites

Thanks for the backup WarRatsG!

 

Now, my script looks like this:

 

scn AlloThoriScr

Ref Item 
Float fQuestDelayTime 

begin GameMode 

if player.GetEquipped AlloThoridal == 0
   Return
Else
if player.GetEquipped AlloThoridal
	set fQuestDelayTime to .01
	if player.GetEquippedCurrentCharge 9 > 64
		set Item to AlloThoriAr
			if player.GetItemCount Item == 0 
			player.AdditemNS Item 1 
			player.EquipItemNS Item 
		endif 
	endif 
endif

Set Item to AlloThoriAr
if Player.Getitemcount item > 1
player.removeitemNS item 1
endif
endif

end

 

Unfortunately, the arrow does not get added at all.

 

To answer your question, this is a quest script (I based it on the above mentionned ''paralyze bow with unlimited arrows'' mod), I imagine there's a way to make it an object script, but in that case, since it worked before I implemented that annoying line of code, I guess the script correctly assigned.

 

Or perhaps is it that the

player.GetEquippedCurrentCharge

command needs to be inside an object script?

 

If it is the case, what do I need to change to the script to make it work as an object script (beside assigning it to the bow itself). More precisely, do the

 

Ref Item 
Float fQuestDelayTime 

begin GameMode 

 

commands/codes/whatever (I apologise for my newbieshness, I never studied scripting in my entire existence...) need to be reworked?

 

Just for your information, I have already attached an object script to the bow itself:

 

Scriptname AlloThoriBowScript

Begin OnUnequip
Player.RemoveitemNS AlloThoriAr 99
end

 

which just removes eventual remaining arrows. Can it affect the above script? It worked perfectly well before...

 

Thanks again for your help! I'd be completely lost without it...

Link to comment
Share on other sites

Thanks for the backup WarRatsG!

 

Now, my script looks like this:

 

scn AlloThoriScr

Ref Item 
Float fQuestDelayTime 

begin GameMode 

if player.GetEquipped AlloThoridal == 0
   Return
Else
if player.GetEquipped AlloThoridal
	set fQuestDelayTime to .01
	if player.GetEquippedCurrentCharge 9 > 64
		set Item to AlloThoriAr
			if player.GetItemCount Item == 0 
			player.AdditemNS Item 1 
			player.EquipItemNS Item 
		endif 
	endif 
endif

Set Item to AlloThoriAr
if Player.Getitemcount item > 1
player.removeitemNS item 1
endif
endif

end

 

Unfortunately, the arrow does not get added at all.

 

To answer your question, this is a quest script (I based it on the above mentionned ''paralyze bow with unlimited arrows'' mod), I imagine there's a way to make it an object script, but in that case, since it worked before I implemented that annoying line of code, I guess the script correctly assigned.

 

Or perhaps is it that the

player.GetEquippedCurrentCharge

command needs to be inside an object script?

 

If it is the case, what do I need to change to the script to make it work as an object script (beside assigning it to the bow itself). More precisely, do the

 

Ref Item 
Float fQuestDelayTime 

begin GameMode 

 

commands/codes/whatever (I apologise for my newbieshness, I never studied scripting in my entire existence...) need to be reworked?

 

Just for your information, I have already attached an object script to the bow itself:

 

Scriptname AlloThoriBowScript

Begin OnUnequip
Player.RemoveitemNS AlloThoriAr 99
end

 

which just removes eventual remaining arrows. Can it affect the above script? It worked perfectly well before...

 

Thanks again for your help! I'd be completely lost without it...

 

I think I know what the problem is.

 

The script attached to the bow, "AlloThoriBowScript", removes 99 arrows. So you then have a negative number of arrows.

Basically, this means that all arrows you receive will essentially disappear until you can obtain enough to set the counter back to 0. I think the quick fix for this would be to change this line:

                                if player.GetItemCount Item == 0 

To this:

                                if player.GetItemCount Item <= 0 

Because now, if your item count is 0 or less, you will receive arrows.

You may also have to change your the script on your bow to remove less arrows. You will only have 1 arrow at a time I think, so you could just remove 1 arrow.

 

To answer your other questions:

 

1. "player.GetEquippedCurrentCharge" does not have to be within an object script.

2. The "variables" (Ref and Float) are declared correctly.

3. Your Block Type (begin GameMode) is also used correctly.

 

If this is one of your first scripts then I'm impressed. I couldn't understand the concept of references and base objects for weeks. ;)

Link to comment
Share on other sites

First of all, WarRatsG, I'm throwing Kudos at you. I might be repeating myself, but I do appreciate that much needed help.

 

And I'm somewhat glad to hear I'm not the only tormented soul who banged his head against walls for weeks before getting a glimpse of how this binary hell-hole works ; )

 

That being said... it's still not working. I've made a few tests, changing some values, applied your suggestion (at least they don't make it worse)

 

As of right now, the scripts look like this:

 

Scn AlloThoriScr

Ref Item 
Float fQuestDelayTime 

begin GameMode 

if player.GetEquipped AlloThoridal == 0
   Return
Else
if player.GetEquipped AlloThoridal
	set fQuestDelayTime to .01
;                    if player.GetEquippedCurrentCharge 9 > 74[/b]
		set Item to AlloThoriAr
			if player.GetItemCount Item <= 0 
			player.AdditemNS Item 1 
			player.EquipItemNS Item 
		endif 
;               endif
endif

Set Item to AlloThoriAr
if Player.Getitemcount item > 1
player.removeitemNS item 1
endif
endif

end

 

and

 

Scn AlloThoriBowScript

Begin OnUnequip
Player.RemoveitemNS AlloThoriAr 1
end

 

I changed the script that removed 99 arrows (I had aded it before the script that allows only 1 arrow at a time, thanks for pointing it out). Regarding this, however, you seemed to implie that the ''begin OnUnEquip'' command was working outside the bonds of the action of unequipping the bow, am I right? Does its effect keep running even after I unequipped it, or does it just remove the items once?

 

Even after making a clean save (and thus hopefully resetting the arrow count), the bow won't give me arrows.

 

I made a check, and added the ; sign before the GetEquippedCurrentCharge command (left them there to show), and everything started to work perfectly well again (bow adds arrows, allows only 1 arrow/time, removes arrows when unequipped)

 

My intuition is that somehow, the game does not recognize the command (I've got obse 2.0 so it should work), or gives a wrong value. (don't worry, in doubt, I made the bow enchant so that both the ''charge number'' - 7000 and the ''amount of charges'' - 75, were beyond the required parameter to make sure the arrow would spawn). I've tried to search for info on the niftools and TESCS wiki, but it's hard to find info on a specific question like this one.

 

Anyway, as for myself, I'm totally blocked. At least 75% of it actually works, which is much better that I had anticipated at the beginning... but if you can help me any further, I'll indeed be grateful.

 

Regardless of what turns out, you'll be in the credits for this mod.

Edited by allomerus
Link to comment
Share on other sites

WAIT!! I GOT IT!!! I GOT IT SO MUCH I'M USING CAPITALS!!!

 

I've found the answer!

 

In that context (burn me, Idk why)

 

player.GetEquippedCurrentCharge 9

 

must be replaced by

 

player.GetEquippedCurrentCharge 16

 

got that after double-checking on the Wiki.

 

wiki says it only return values, turns out it's what we needed.

 

Everything is working seamlessly.

 

Now onto the modeling part!!

 

And thank you so much for your help!!!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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