Jump to content

I can has scripting help?


jovialAssassin

Recommended Posts

Thanks you guys, but there's still a problem: the script won't accept the use of a variable for the amount of omnigel given.

 

If I select the button that's supposed to delete the items and add an appropriate amount of omnigel to the player's inventory, items are deleted and I get a message that omnigel's been added to the inventory (I've removed the variable that suppresses the message) but no omnigel's been added.

 

So, out of curiosity I changed

 

Player.AddItem OmniGel OmniConvert2

 

to

 

Player.AddItem OmniGel InvWt1

 

And the result was interesting: items removed like usual, but no message stating omnigel had been added to my inventory. To further rule out an error in syntax, I again changed the relevant section of code to:

 

Player.AddItem OmniGel 1

 

And 1 unit of omnigel was added to my inventory.

 

there is another potentially huge problem; whats preventing me from dropping all my useless raider armors in that container to trick the inventory weight metering?

 

Ah, that's the thing: you really can't. OmniConvert2, the floating variable I have set up to determine how much omnigel is dispensed to the player's inventory is only determined after the container's been closed.

 

The idea is as so:

Player opens OmniStorage and the script takes a measure of the player's inventory weight at that moment and assigns it to InvWt1.

Player moves items he wants converted over to OmniStorage.

Player closes OmniStorage and the script takes another measure and assigns that to InvWt2.

The script takes InvWt1 and subtracts InvWt2 from it.

 

For example: say the player's inventory weight is 200 and he moves a lot of items totalling 50 units of weight over to OmniStorage and his inventory weight is now 150. Invwt1 - InvWt2 = OmniConvert, where InvWt1 = 200 and InvWt2 = 150. 200 - 150 = 50. (I hope that all made sense).

 

Now we assign the amount of weight in OmniStorage to OmniConvert (which we determined from InvWt1 - InvWt2). From there, we multiply OmniConvert by 10 and assign that value to OmniConvert 2 (the reason I'm doing this is to enable the player to process items with a weight below 1, the multiplier 10 is just a placeholder value until the script is actually fully working).

 

That answer your question? :)

 

(Or is there some painfully obvious exploit in my concept that needs tweaking?)

 

Aaaand latest iteration of the script.

 

Changes include:

 


  •  
  • Floating variables have had an "f" placed in front of them to assist in identification.
  • Removed OnOpen and OnClose blocks and replaced them with OmniStorageREF.getopenstate in the GameMode block.
  • The value of OmniConvert is now calculated upon engaging the omnitool's hotkey.
  • iButton == 6 now calculates the value of OmniConvert 2, and sets convert to 1
  • Moved Player.AddItem Omnigel to its own section in GameMode and is activated by if convert == 1

 

 

ScriptName OmniToolMenuScript

int iButton
int iMenuLevel
float fInvWt1
float fInvWt2
float fOmniConvert
float fOmniConvert2
short on
short acti
short convert
long Caps
long Omni
long Omni2
int Reap
short remenu
int bIsNPressed

Begin OnEquip player
       set acti to 1
End

Begin GameMode
       if acti == 1
               if bIsNPressed != IsKeyPressed 49
                       set bIsNPressed to IsKeyPressed 49
                       if bIsNPressed
                               set on to 1
                               set iMenuLevel to 0
                               ShowMessage OmniToolMenuMessage
                       endif
               endif
       endif
if OmniStorageREF.getopenstate == 1
	set fInvWt1 to player.GetActorValue InventoryWeight
endif
if OmniStorageREF.getopenstate == 3
	set fInvWt2 to player.GetActorValue InventoryWeight
endif
       if on == 1
	set fOmniConvert to fInvWt1 - fInvWt2
               set iButton to GetButtonPressed
               if iButton == -1
                       Return
               elseif iMenuLevel == 0
                       if iButton == 0
                               Set iMenuLevel to 1
                               ShowMessage OmniToolMenuRepairMessage
                               return
                       elseif iButton == 1
                               player.showrecipemenu WorkbenchRecipes
                               set on to 0
                               return
                       elseif iButton == 2
                               player.showrecipemenu ReloadingBenchRecipes
                               set on to 0
                               return
                       elseif iButton == 3
                               player.showrecipemenu CampfireRecipes
                               set on to 0
                               return
                       elseif iButton == 4
                               player.showrecipemenu OmniToolRecipes
                               set on to 0
                               return
                       elseif iButton == 5
                               OmniStorageREF.Activate Player
                               set on to 0
                               return
                       elseif iButton == 6
		        set fOmniConvert2 to fOmniConvert * 10
                               OmniStorageREF.RemoveAllItems
			 set convert to 1
                               set on to 0
                               return
                       elseif iButton == 7
                               set on to 0
                               return
                       endif
               elseif iMenuLevel == 1
                       if iButton != 7
                               set Caps to player.GetItemCount Caps001
                               set Omni to player.GetItemCount OmniGel
                               player.removeitem Caps001 Caps 1
                               player.removeitem OmniGel Omni 1
                               player.additem Caps001 Omni 1
                               if iButton == 0
                                       OmniRepairmanREF.ForceAV Repair 25
                               elseif iButton == 1
                                       OmniRepairmanREF.ForceAV Repair 50
                               elseif iButton == 2
                                       OmniRepairmanREF.ForceAV Repair 75
                               elseif iButton == 3
                                       OmniRepairmanREF.ForceAV Repair 100
                               elseif iButton == 4
                                       set Reap to player.getav Repair + 10
                                       OmniRepairmanREF.ForceAV Repair Reap
                               endif
                               set remenu to 1
                               OmniRepairmanREF.ShowRepairMenu
                               set on to 0
                               return
                       elseif iButton == 7
                               Set iMenuLevel to 0
                               ShowMessage OmniToolMenuMessage
                               return
                       endif
               endif
       endif
       if remenu == 2
               OmniRepairmanREF.ResetInventory
               set Omni2 to player.GetItemCount Caps001
               player.removeitem Caps001 Omni 1
               player.additem OmniGel Omni2 1
               player.additem Caps001 Caps 1
               set remenu to 0
       endif
if convert == 1
	Player.AddItem OmniGel fOmniconvert2
	set convert to 0
endif
End

Begin OnUnEquip player
       set acti to 0
End

Begin MenuMode 1058
       if remenu == 1
               Set remenu to 2
       endif
End

 

 

[/wall of text]

Link to comment
Share on other sites

oh i misunderstood the point of the script..

 

i didnt realize that your point was for any item to be be able to be converted just based on weight.

 

this should work out ok then.

 

 

ill look through again and see if i can figure it out.

 

 

 

ok there is still a problem with the code we were working on earlier.

remember that toggle i was referring to? you need to do it.

 

as it stands right now EVERY frame it is setting the second inventory weight to the player weight.

 

so when you hit the button it is taking your instant weight for the second variable rather that your weight when it was closed.

 

im not sure what the other problem is right now as im am getting pretty damn tired and i wanna spend some time with meh lady before bed time, tomorrow though if you dont have anything ill try again to look through it.

Edited by angelwraith
Link to comment
Share on other sites

Have you tried declaring the quantity variable as an integer?

 

set iOmniConvert2 to (fOmniConvert * 10 + 0.5)

 

If you've got NVSE installed, also use the printtoConsole function so you can test that your script logic matches the logic you've got in your head :)

 

printc "Trying to add %.0f Gels" iOmniConvert2

Link to comment
Share on other sites

oh i misunderstood the point of the script..

 

i didnt realize that your point was for any item to be be able to be converted just based on weight.

 

this should work out ok then.

 

 

ill look through again and see if i can figure it out.

 

 

 

ok there is still a problem with the code we were working on earlier.

remember that toggle i was referring to? you need to do it.

 

as it stands right now EVERY frame it is setting the second inventory weight to the player weight.

 

so when you hit the button it is taking your instant weight for the second variable rather that your weight when it was closed.

 

im not sure what the other problem is right now as im am getting pretty damn tired and i wanna spend some time with meh lady before bed time, tomorrow though if you dont have anything ill try again to look through it.

 

Tried adding the aforementioned toggle. No dice, unfortunately (or, more likely I'm implementing it incorrectly).

 

 

Have you tried declaring the quantity variable as an integer?

 

set iOmniConvert2 to (fOmniConvert * 10 + 0.5)

 

If you've got NVSE installed, also use the printtoConsole function so you can test that your script logic matches the logic you've got in your head :)

 

printc "Trying to add %.0f Gels" iOmniConvert2

 

As a floating variable OmniConvert2 returned 1. As an integer it returned 0. Not quite sure what to make of that, either way still nothing.

 

Anyways, CODE FOR THE CODE GOD.

 

 

ScriptName OmniToolMenuScript

int iButton
int iMenuLevel
float fInvWt1
float fInvWt2
int iOmniConvert
float fOmniConvert2
float fTimer
float fTimer2
short on
short acti
short convert
int Caps
int Omni
int Omni2
int Reap
short remenu
int bIsNPressed

Begin OnEquip player
set acti to 1
End

Begin GameMode
if acti == 1
	if bIsNPressed != IsKeyPressed 49
		set bIsNPressed to IsKeyPressed 49
		if bIsNPressed
			ShowMessage OmniToolMenuMessage
			set fTimer to .5
			Label 1
			if fTimer > 0
				set fTimer to fTimer - GetSecondsPassed
				Goto 1
			endif
			set on to 1
			set iMenuLevel to 0
			printc "Trying to add %.0f Gels" fOmniConvert2
		endif
	endif
endif
if OmniStorageREF.GetOpenState == 1
	set fInvWt1 to player.GetActorValue InventoryWeight
endif
if OmniStorageREF.GetOpenState == 3
	set fTimer2 to .5
			Label 2
			if fTimer2 > 0
				set fTimer2 to fTimer2 - GetSecondsPassed
				Goto 2
				set fInvWt2 to player.GetActorValue InventoryWeight
			endif
endif
if on == 1
	set iOmniConvert to fInvWt1 - fInvWt2
	set iButton to GetButtonPressed
	if iButton == -1
		Return
	elseif iMenuLevel == 0
		if iButton == 0
			set iMenuLevel to 1
			ShowMessage OmniToolMenuRepairMessage
			Return
		elseif iButton == 1
			player.showrecipemenu WorkbenchRecipes
			set on to 0
			Return
		elseif iButton == 2
			player.showrecipemenu ReloadingBenchRecipes
			set on to 0
			Return
		elseif iButton == 3
			player.showrecipemenu CampfireRecipes
			set on to 0
			Return
		elseif iButton == 4
			player.showrecipemenu OmniToolRecipes
			set on to 0
			Return
		elseif iButton == 5
			OmniStorageREF.Activate Player
			set on to 0
			Return
		elseif iButton == 6
			set fOmniConvert2 to (iOmniConvert * 10 +0.5)
			OmniStorageREF.RemoveAllItems
			set convert to 1
			set on to 0
			Return
		elseif iButton == 7
			set on to 0
			Return
		endif
	elseif iMenuLevel == 1
		if iButton != 7
			set Caps to player.GetItemCount Caps001
			set Omni to player.GetItemCount OmniGel
			player.RemoveItem Caps001 Caps 1
			player.RemoveItem OmniGel Omni 1
			player.AddItem Caps001 Omni 1
			if iButton == 0
				OmniRepairmanREF.ForceAV Repair 25
			elseif iButton == 1
				OmniRepairmanREF.ForceAV Repair 50
			elseif iButton == 2
				OmniRepairmanREF.ForceAV Repair 75
			elseif iButton == 3
				OmniRepairmanREF.ForceAV Repair 100
			elseif iButton == 4
				set Reap to player.GetAV Repair + 10
				OmniRepairmanREF.ForceAV Repair Reap
			endif
			set remenu to 1
			OmniRepairmanREF.ShowRepairMenu
			set on to 0
			Return
		elseif iButton == 7
			set iMenuLevel to 0
			ShowMessage OmniToolMenuMessage
			Return
		endif
	endif
endif
if remenu == 2
	OmniRepairmanREF.ResetInventory
	set Omni2 to player.GetItemCount Caps001
	player.RemoveItem Caps001 Omni 1
	player.AddItem OmniGel Omni2 1
	player.AddItem Caps001 Caps 1
	set remenu to 0
endif
if convert == 1
	Player.AddItem OmniGel fOmniconvert2
	set convert to 0
endif
End

Begin OnUnequip player
set acti to 0
End

Begin MenuMode 1058
if remenu == 1
	set remenu to 2
endif
End

 

Link to comment
Share on other sites

i think this is a part of the problem:

       if OmniStorageREF.GetOpenState == 3
               set fTimer2 to .5
                               Label 2
                               if fTimer2 > 0
                                       set fTimer2 to fTimer2 - GetSecondsPassed
                                       Goto 2
                                       set fInvWt2 to player.GetActorValue InventoryWeight
                               endif
       endif

 

as it stands there is no way for the "set fInvWt2 to player.GetActorValue InventoryWeight" line to run.

the goto 2 will prevent the line from firing when the timer is below 0, and isnt available when above 0 sooo never gets used.

goto immendiatlry goes to the line it points to.. so that means it doesnt finish the script it was on...

 

anyway i dont think a timer is the best route.

 

i meant more along the lines make a variable that the second part needs to have set to run and then set it with the first bit of code and have it set itself to not tun again once it has once. the way your doing it now adds a pause through a timer that runs on every frame.. this way would run dependent on what the settings are so much less resource allocation on the system as well.

 

also im almost positive this has something to do with the root of the main problem as if those variables arent set at the right time when the equation fires you wont be getting predictable results.

 

this i think will help:


  	if OmniStorageREF.GetOpenState == 1
               set fInvWt1 to player.GetActorValue InventoryWeight
	set omnistorageactivatedd to 1
       endif
       if OmniStorageREF.GetOpenState == 3 && omnistorageactivatedd == 1
	set fInvWt2 to player.GetActorValue InventoryWeight
	set omnistorageactivatedd to 0
       endif

dont forget you'll need to establish the omnistorageactivatedd variable somewhere before its called in the script. i usually just group all mine at the top.

 

so this script wont do anything until the container is opened, then itll set that variable thatll cause it to wait until the conditions of the box are set and its closed, then upon closing the box it unsets those conditions so it only happens once each time you open the container.

 

with console BEFORE you hit the hotkey and after youve accessed the container to set the variables use these lines in order:

"prid player" (hit enter to select player reference)

"sv" (hit enter to bring up current script variables)

 

now look for the variables were working with.

didi the initial values and modified values your working with here get set?

 

also you are going to need to figure out a way of preventing the player from repeatedly hitting the button to gain the reward as with the variables setting once and sticking like this would allow them to repeat the process indefinitely, but you can simply set the modified value to 0 after its used (do this later though as its implementation could make this a lot more confusing while the script isnt functioning properly.)

Edited by angelwraith
Link to comment
Share on other sites

... No. No the variables did not get set. At all. T.T

 

At each stage of the process (before opening the omnitool, while storage was opened, after storage was closed and the item moved over). Each of the relevant variables, fInvwt1, fInvwt2, fOmniConvert and fOmniConvert2 read 0 across the board. :wallbash:

 

No appended code this time because the only changes were according to angelwraith's post.

 

Going to rigup a hotkey that (hopefully) records the player's inventory weight, independent of the script just to test if Player.GetActorValue InventoryWeight actually works in NV/NVSE. First though, off to class. Huzzah.

Link to comment
Share on other sites

... No. No the variables did not get set. At all. T.T

 

At each stage of the process (before opening the omnitool, while storage was opened, after storage was closed and the item moved over). Each of the relevant variables, fInvwt1, fInvwt2, fOmniConvert and fOmniConvert2 read 0 across the board. :wallbash:

 

No appended code this time because the only changes were according to angelwraith's post.

 

Going to rigup a hotkey that (hopefully) records the player's inventory weight, independent of the script just to test if Player.GetActorValue InventoryWeight actually works in NV/NVSE. First though, off to class. Huzzah.

 

 

s*** with those changes its still reading 0?

 

hmmph.. ill look again.

 

maybe try to set up a local copy.. or do you have this set up already somewhere i can look at it in the mod?

 

 

ok so i though getopenstate worked with containers but im starting to wonder if it only works with doors..

gonna test this.

 

*EDIT*

 

YEP that was it..

seems containers DO return values for containers, however, the returns do NOT match that of doors.

 

so what i have is :

getopenstate on a closed container returns 3

 

getopenstate on a activated container returns 4

 

try these values instead. sorry about the confusion. i was following the returns found here

 

but i forgot that it says door there sooo.. yeah

but hey it still has a return when called on a container that changes with the state, so go with it.

Edited by angelwraith
Link to comment
Share on other sites

  • Recently Browsing   0 members

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