Jump to content

Some scripted math help, please


Paliben

Recommended Posts

Okay, so I have a math formula. In a debug spell I use to get the value of the formula, it reads out 1240 (I believe it was, bad memory ftw). Now, I take that same math formula and put it inside another script, and it comes out -224. I don't know if it's just weird flow, how it's executed, if it's not doing the whole math problem before providing an answer or what. Any help in this would be appreciated, or even a better way to do the formula.

As a breakdown of it, it's basically "required amount to level". Where x is current level, and y is required amount to level. I'll provide scripts below.

The debug script, which gives an amount I am fine with.

 

Scriptname SSTestScript extends ActiveMagicEffect
GlobalVariable Property SSPlayerLevel Auto
MiscObject Property Gold001 Auto
Actor Property PlayerRef Auto
Event OnEffectStart(Actor target, Actor caster)
Int x = SSPlayerLevel.GetValueInt()
Int y = (((x * 3) + (3 * x * 2)) + 105 * x) * 10 as Int
Int SoulCost = y
Debug.Messagebox("Soul cost = " + SoulCost)
EndEvent



Then the leveling script, which for some reason comes out -224.xxxx. I'll add in the whole script to give a better picture.


Scriptname SSBonfireScript extends ObjectReference
{handles usage of bonfires and activation}
Quest Property SSLALSkySouls Auto
ObjectReference Property Marker Auto
Message Property SSBonfireMain Auto
Message Property SSBonfireLevelOne Auto
Message Property SSBonfireLevelTwo Auto
MiscObject Property Gold001 Auto
GlobalVariable Property SSStatAttunement Auto
GlobalVariable Property SSStatDexterity Auto
GlobalVariable Property SSStatEndurance Auto
GlobalVariable Property SSStatFaith Auto
GlobalVariable Property SSStatIntelligence Auto
GlobalVariable Property SSStatLuck Auto
GlobalVariable Property SSStatStrength Auto
GlobalVariable Property SSStatVigor Auto
GlobalVariable Property SSStatVitality Auto
GlobalVariable Property SSPlayerLevel Auto
GlobalVariable Property SSPlayerReqSouls Auto
Actor Property PlayerRef Auto
Bool IsEnabled = False
Bool DoOnce = False
Int CurSouls
Int ReqSouls
Event OnActivate(ObjectReference ActRef)
If ActRef == Game.GetPlayer()
If IsEnabled == False
IsEnabled = True
Marker.Enable()
EndIf
EndIf
If DoOnce == False
SetQuest(10)
Else
BonfireMain()
EndIf
EndEvent
Function SetQuest(Int Stage)
SSLALSkySouls.SetStage(Stage)
DoOnce = True
EndFunction
Function BonfireMain()
Int Op = SSBonfireMain.Show()
If Op == 0 ;travel
;return later
ElseIf Op == 1 ;level
LevelOne()
ElseIf Op == 2 ;storage
;return once storage is set up
ElseIf Op == 3
;close
EndIf
EndFunction
Function LevelOne()
Int O = SSBonfireLevelOne.Show()
If O == 0 ;strength
LevelUp(0)
ElseIf O == 1 ;dex
LevelUp(1)
ElseIf O == 2 ;Intel
LevelUp(2)
ElseIf O == 3 ;fai
LevelUp(3)
ElseIf O == 4 ;next
LevelTwo()
ElseIf O == 5 ;close
;close
EndIf
EndFunction
Function LevelTwo()
Int O = SSBonfireLevelTwo.Show()
If O == 0 ;vigor
LevelUp(4)
ElseIf O == 1 ;vitality
LevelUp(5)
ElseIf O == 2 ;endurance
LevelUp(6)
ElseIf O == 3 ;luck
LevelUp(7)
ElseIf O == 4 ;prev
LevelOne()
ElseIf O == 5 ;close
;close
EndIf
EndFunction
Function LevelUp(Int Stat)
CurSouls = PlayerRef.GetItemCount(Gold001)
Int x = SSPlayerLevel.GetValueInt()
Float y = (((x * 3) + (3 * x * 2)) + 105 * x)
Utility.Wait(0.5)
SSPlayerReqSouls.SetValue(y)
Utility.Wait(0.2)
ReqSouls = SSPlayerReqSouls.GetValue() as Int
Debug.Notification("Required Souls: " + ReqSouls + ", Current Souls: " + CurSouls)
If Stat == 0 ;strength
If ReqSouls > CurSouls
Debug.MessageBox("Insufficient souls to level")
Else
PlayerRef.RemoveItem(Gold001, ReqSouls)
SSStatStrength.SetValue((SSStatStrength.GetValue()) + 1)
SSPlayerLevel.SetValue((SSPlayerLevel.GetValue()) + 1)
EndIf
EndIf
EndFunction

 

Amount shown in level menu

https://drive.google.com/file/d/1hpm15tA2yDYJctlILk-Bm7-0hwBc8w6P/view


Debug amount
https://drive.google.com/file/d/1pYDYVFivcouZp-5ma97Xfx1pAtQiZI8Y/view

Link to comment
Share on other sites

your first script

Scriptname SSTestScript extends ActiveMagicEffect
Int x = SSPlayerLevel.GetValueInt()
Int y = (((x * 3) + (3 * x * 2)) + 105 * x) * 10 as Int

your second script

Scriptname SSBonfireScript extends ObjectReference
Int x = SSPlayerLevel.GetValueInt()
Float y = (((x * 3) + (3 * x * 2)) + 105 * x)

By using x, y or z (inside an ObjectReference or Actor script) it will be treated here as self.X, self.Y or self.Z, that means self.X is the same as self.GetPositionX()

 

Workaround use other variable names like fx, fy or fz for float, ix, iy or iz for int variables

 

 

;-------------------------
FUNCTION LevelUp(Int Stat)
;-------------------------
    actor player = Game.GetPlayer()

    CurSouls = player.GetItemCount(Gold001 as Form)      ; script variable
 
    int   i = SSPlayerLevel.GetValueInt()                ; i = x
    float f = ((i * 3) + (i * 6) + (i * 105)) * 10       ; f = y, 3*2 = 6
    Utility.Wait(0.5)
 
    SSPlayerReqSouls.SetValue(f)
    Utility.Wait(0.2)

    ReqSouls = SSPlayerReqSouls.GetValueInt()            ; script variable
    Debug.Notification("Required Souls: " + ReqSouls + ", Current Souls: " + CurSouls)
 
    IF (Stat == 0)            ; strength
        IF (ReqSouls > CurSouls)
            Debug.MessageBox("Insufficient souls to level")
        ELSE
            player.RemoveItem(Gold001 as Form, ReqSouls)
            SSStatStrength.Mod(1)                        ; SSStatStrength.SetValue((SSStatStrength.GetValue()) + 1)
            SSPlayerLevel.Mod(1)
        ENDIF
    ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Ugh if that's all it is. RIP. I forgot about .mod too, so used to adding/subtracting from variables using that method it's burned in to my brain. I'll give the variable name change a go. If you don't hear back from me, all is well and I appreciate your help. Many thanks, friend!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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