Jump to content

Scripting Help Needed


Xiron

Recommended Posts

Ok, so the purpose of this bit of script was to attach it to a container with the effect of it doubling the count of the item placed inside it (1 at a time) once you exited its inventory menu screen. This function works fine, when I open the container and place something inside, and open/close the container, the item count doubles. HOWEVER, if I open the container and close it without putting any items into it, or open it, put items in it, close/open it again and remove them, the container will not reopen. Script follows in code tags, I cannot find an error in my code, what did I do wrong? :/

 

 

Scriptname ItemDuplicatorChestScript


short runvar == 0
short itemcount == 0
ref boxeditem


begin OnActivate
if runvar < 5
	set runvar to runvar + 1
	Activate
elseif runvar == 5
	Activate
endif
End

begin Gamemode
if runvar >= 1
	set boxeditem to (GetInventoryObject 0)
	set itemcount to (GetItemCount boxeditem)
	if itemcount >= 1
		if boxeditem == MS04HornGift
			removeitem MS04HornGift itemcount
			set boxeditem to MinotaurHorn
		elseif boxeditem == MG01Bonemeal
			removeitem MG01Bonemeal itemcount
			set boxeditem to bonemeal
		elseif boxeditem == MG13VampireDust
			removeitem MG13VampireDust itemcount
			set boxeditem to vampiredust
		endif
		additem boxeditem itemcount
	endif
	set runvar to runvar - 1
endif
End

Link to comment
Share on other sites

Offhand I'd be tempted to say that the problem is due to either the container returning a different item after it's opened and closed, or because the counter you use gets screwed up when the container isn't empty.

 

A solution might be to just purge the container (removeallitems) to the player if it's activated after the item is duplicated. Then you remove the possibility of the two instances where the script fails from happening, or should.

 

 

You should also refrain from bumping posts that have less than a few days since the last response. In particular, scripting and higher level modding questions can take longer to answer since there aren't many who know enough, and answering them usually requires having the time to really look at what is going on.

Edited by Vagrant0
Link to comment
Share on other sites

I apologize for the bumping, I've just been frustrated with it for a day now heheh....

 

EDITEDIT: Solved my problem, figured out that it had to do with the items, but not returning a different item. Apparently it does NOT like null returns, so the following code is the final (fixed, working) version.

 

Scriptname ItemDuplicatorChestScript


short runvar = 0
long itemcount = 0
ref boxeditem


begin OnActivate
set runvar to 1
Activate
End

begin Gamemode
if runvar > 0
	set runvar to 0
	if GetNumItems > 0
		set boxeditem to (GetInventoryObject 0)
		set itemcount to (GetItemCount boxeditem)
		if boxeditem == MS04HornGift
			removeitem MS04HornGift itemcount
			set boxeditem to MinotaurHorn
		elseif boxeditem == MG01Bonemeal
			removeitem MG01Bonemeal itemcount
			set boxeditem to bonemeal
		elseif boxeditem == MG13VampireDust
			removeitem MG13VampireDust itemcount
			set boxeditem to vampiredust
		endif
		RemoveAllItems
		set itemcount to itemcount + itemcount
		additem boxeditem itemcount
	endif
endif
End

Link to comment
Share on other sites

  • Recently Browsing   0 members

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