Jump to content

Assigning values to MiscObjects, not visible prices.


Recommended Posts

This is just an idea I am playing with and a small part of a larger script I will need to write. Player will place a certain type(s) of objects in a container, in my case they are fuses. Fuses have different values, for now say 20, 15, 10 and 5 these should not be prices (these will be different) but values that will be added together when player has finished placing fuses in order to reach a specific numeric value, in this case 75+.

Firstly how do I assign a value of 20 to a Red Fuse, 15 to a Blue Fuse, 10 to a Black Fuse and 5 to an Old Fuse?

Next how do I assure that the player only places the correct number of fuses - sometimes 3 need to be placed, sometimes only 1. This will avoid player dumping 10 fuses into a container which requires only 1 and should be the correct value or more - if less than required then messagebox "Not enough power being sent." In this case fuses placed (which can vary) will be returned to player inventory?

Also a method of adding up the value of the fuses?

I'm working on this myself but am unsure which approach to take.

Thanks.

 

Link to comment
Share on other sites

I would suggest if you have a small number of items dong this to hard code the values for each within the script and do a little math. Here is an example (not covering all possibilities)

 

 

 

MiscObject Property RedFuse Auto
MiscObject Property BlueFuse Auto
MiscObject Property BlackFuse Auto
MiscObject Property OldFuse Auto

Int TotalFuseValue = 0
Int Property RequiredFuseValue Auto

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  If akSourceContainer == Game.GetPlayer()  ; did player add the items
    If (akBaseItem as MiscObject)
      If (akBaseItem as MiscObject) == RedFuse
        TotalFuseValue += (20 * aiItemCount)
      ElseIf (akBaseItem as MiscObject) == BlueFuse
        TotalFuseValue += (15 * aiItemCount)
      ElseIf (akBaseItem as MiscObject) == BlackFuse
        TotalFuseValue += (10 * aiItemCount)
      ElseIf (akBaseItem as MiscObject) == OldFuse
        TotalFuseValue += (5 * aiItemCount)
      EndIf
      If TotalFuseValue < RequiredFuseValue
        Debug.Messagebox("Not enough power. "+TotalFuseValue+" / "+RequiredFuseValue)
      ElseIf TotalFuseValue > RequiredFuseValue
        Debug.Messagebox("Too much power"+TotalFuseValue+" / "+RequiredFuseValue)
      ElseIf TotalFuseVAlue == RequiredFuseValue
        Debug.Messagebox("Right amount of power"+TotalFuseValue+" / "+RequiredFuseValue)
      EndIf
    EndIf
  EndIf
EndEvent

You may wish to utilize states to prevent the player from spamming the container with fuses and potentially creating a stack dump.

 

 

Link to comment
Share on other sites

One approach to this is what IsharaMeradin suggested.


Another way is to separate those items in groups of values, for example:

1 Fuse A + 1 Fuse B + 1 Fuse C = 75

1 Fuse A + 2 Fuse B = 75

3 Fuse A + 1 Fuse C = 75

etc...

Then your script should check for any of those potential groups of items that equals 75.

* Values are fictional and they don't leave anywhere (they don't actually exists), only you know and define them.


* I tried to write a more detailed explanation but i got confused, then i checked my script to refresh my brain on how i actually did something similar, and i got even more confused because my mind is right now in a state of computing other complicated mod's related things.


But this is the general idea, oupss sorry...

Edited by maxarturo
Link to comment
Share on other sites

The approach I am currently taking is using quite a few global variables. Without posing the entire script,which I may end up doing, can you show me the reason this part, which points script to other functions, won't compile please/

 

Event OnActivate(ObjectReference akActionRef)
If (My_GVfuseboxShowMsg.GetValue()) == (0)
My_MSGfusebox1stEncounter.Show()
My_GVfuseboxShowMsg.SetValue(1)
EndIf

If (Game.GetPlayer().GetItemCount(My_FuseRed)) < 1 && (Game.GetPlayer().GetItemCount(My_FuseBlue) < 1) && (Game.GetPlayer().GetItemCount(My_FuseBlack) < 1) && (Game.GetPlayer().GetItemCount(My_FuseUsed) < 1) && (My_GVfuseColorSlot1.GetValue()) == 0
My_MSGnoFuses.Show(); player has no fuses
; if player does have fuses we continue

Else
int Function GetValueInt()
int SlotsCurrentlyFilled = My_GVfuseSlotNum.GetValueInt()

If (SlotsCurrentlyFilled.GetValue()) < (NumSlots)
Int iButton = My_MENU_Fuses.Show()

If (iButton == 4); removes all fuses
RemoveAll()
EndIf

If (iButton == 0); red fuse 20
Slot1Red()
EndIf

If (iButton == 1); blue fuse 15
Slot1Blue()
EndIf

If (iButton == 2); black fuse 10
Slot1Black()
EndIf

If (iButton == 3); used fuse depends on fixed value of fuse
Slot1Used()
EndIf
EndIf

EndFunction
EndEvent

 

(42,0): no viable alternative at input 'int'
(42,0): no viable alternative at input 'int'
(69,0): mismatched input 'EndFunction' expecting ENDEVENT

Link to comment
Share on other sites

You have Int Function GetValueInt() and EndFunction both inside of an event. You cannot define a function inside of an event. Events and functions are basically the same thing and cannot be nested. One can call the other but cannot be defined within the other.

 

Plus GetValueInt() is already a defined function within papyrus and it is slightly slower than using GetValue() as Int

 

For this case, just remove those two lines and it should be good.

Link to comment
Share on other sites

Thank you. Sorted out the issue. Now can I ask, I read the information a long time ago and don't remember how to do it. Within a script how can I call a function from a different script. This would be very helpful and obviously save a lot of excessive scripting.

Link to comment
Share on other sites

Thanks but it kind of doesn't address what I need to do but anyway I have worked around it. Just a quick question, how can I show a float value as a percentage. I'll post the entire script so you can see. I'm setting the fuse values at 2.5, 2.0 and 1.5 (in game player would eventually guess them as having values of 25, 20 and 15). The issue is with the math and as I said show a percentage instead of a decimal.

If you think there is a better way to represent the fuse values and do the math please tell me. Script is not finished, it only checks the fuse colour/value in Slot1.

 

; Values Red=25 Blue=20 Black-15
Float Property Slot1Value Auto
Float Property Slot2Value Auto
Float Property Slot3Value Auto
Float Property FuseValueTotal Auto
GlobalVariable Property My_GVfuseSlotNum Auto; slot check global is ALREADY set to 1
GlobalVariable Property My_GVfusebox1stTrySlotEmpty Auto
GlobalVariable Property My_GVfuseColorSlot1 Auto
GlobalVariable Property My_GVfuseColorSlot2 Auto
GlobalVariable Property My_GVfuseColorSlot3 Auto
Int Property NumSlots = 1 Auto; user input for how many slots on this fusebox
Message Property My_MSGfillSlots Auto
ObjectReference Property ObjToAct1 Auto

Event OnActivate(ObjectReference akActionRef)

If (My_GVfusebox1stTrySlotEmpty.GetValue() == 0)
My_MSGfillSlots.Show()
My_GVfusebox1stTrySlotEmpty.SetValue(1)
EndIf

int SlotsCurrentlyFilled = My_GVfuseSlotNum.GetValue() as Int
If (SlotsCurrentlyFilled) == (NumSlots)
DoMath()

Else

debug.notification("At Least 1 Slot Is Empty.")
EndIf
EndEvent
;----------------------------------------------------------------------------------------------
Function DoMath()
debug.notification("Math Function.")
;----------------------------------- Slot 1 Red -----------------------------------------------
If (My_GVfuseColorSlot1.GetValue() == 1); red fuse in slot 1
Slot1Value = 2.5
debug.notification("Red Fuse In Slot 1.")
EndIf
;----------------------------------- Slot 1 Blue -----------------------------------------------
If (My_GVfuseColorSlot1.GetValue() == 2); blue fuse in slot 1
Slot1Value = 2.0
debug.notification("Blue Fuse In Slot 1.")
EndIf
;----------------------------------- Slot 1 Black -----------------------------------------------
If (My_GVfuseColorSlot1.GetValue() == 3); black fuse in slot 1
Slot1Value = 1.5
debug.notification("Black Fuse In Slot 1.")
EndIf

FuseValueTotal = Slot1Value + Slot2Value + Slot3Value

Debug.Messagebox("Power = "+ Slot1Value)



EndFunction

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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