scn aaaSFWbtcBookPerkScrFunc
int i
int LuckAffects
int LuckValue
float BookRandom
float Treshold1000
float Treshold725
float Treshold450
int CountForExchange
int SFWBookGeneric1000Count
int SFWBookGeneric725Count
int SFWBookGeneric450Count
int PreWarBookCount
int CountDivided
int DivOffset
int RandomBooksCount
int i2
float RandomMin
float RandomMax
int RecycleArrSize
int PreBookArrSize
Begin Function { LuckAffects }
If Player.GetItemCount aaaSFWBooksFormList
RecycleArrSize = ListGetCount aaaSFWbtcBooksFormList
PreBookArrSize = ListGetCount aaaSFWBooksFormList
LuckValue = Player.GetAV Luck
If LuckAffects
Treshold1000 = 99 - LuckValue / 10 ; Luck 10 = 98 (2%)
Treshold725 = 97 - LuckValue / 5 ; = 95 (3%)
Treshold450 = 94 - LuckValue / 3.333 ; = 91 (4%)
Else
Treshold1000 = 98.5 ; EQ 5 = 1.5%
Treshold725 = 96.0 ; = 2.5%
Treshold450 = 92.5 ; = 3.5%
EndIf
EndIf
While (Player.GetItemCount aaaSFWBooksFormList)
If (Player.GetItemCount (ListGetNthForm aaaSFWBooksFormList i)) > CountForExchange
CountForExchange += 1
BookRandom = Rand 0.00, 100.00 ; FLOAT
If BookRandom > Treshold1000
SFWBookGeneric1000Count += 1
ElseIf BookRandom > Treshold725
SFWBookGeneric725Count += 1
ElseIf BookRandom > Treshold450
SFWBookGeneric450Count += 1
Else
PreWarBookCount += 1
EndIf
Else
If CountForExchange
Player.RemoveItem (ListGetNthForm aaaSFWBooksFormList i) CountForExchange 1
CountForExchange = 0
EndIf
i += 1
If i >= PreBookArrSize
i = 0
EndIf
EndIf
Loop
If SFWBookGeneric1000Count || SFWBookGeneric725Count || SFWBookGeneric450Count
ShowMessage aaaSFWbtcBooksVALUABLEmsg
If SFWBookGeneric1000Count
Player.AddItem SFWBookGeneric1000 SFWBookGeneric1000Count 1
;SFWBookGeneric1000Count = 0 ; ТИП "ФУНКЦИЯ" НЕ СОХРАНЯЕТ ПЕРЕМЕННЫЕ
EndIf
If SFWBookGeneric725Count
Player.AddItem SFWBookGeneric725 SFWBookGeneric725Count 1
;SFWBookGeneric725Count = 0 ; ТИП "ФУНКЦИЯ" НЕ СОХРАНЯЕТ ПЕРЕМЕННЫЕ
EndIf
If SFWBookGeneric450Count
Player.AddItem SFWBookGeneric450 SFWBookGeneric450Count 1
;SFWBookGeneric450Count = 0 ; ТИП "ФУНКЦИЯ" НЕ СОХРАНЯЕТ ПЕРЕМЕННЫЕ
EndIf
EndIf
If PreWarBookCount
CountDivided = PreWarBookCount / RecycleArrSize
DivOffset = PreWarBookCount % RecycleArrSize
;i2 = 0 ; ТИП "ФУНКЦИЯ" НЕ СОХРАНЯЕТ ПЕРЕМЕННЫЕ
If DivOffset
Player.AddItem (ListGetNthForm aaaSFWbtcBooksFormList (GetRandomInRange 0 (RecycleArrSize + 1))) DivOffset 1
EndIf
If CountDivided
RandomMin = 1 / (fsqrt CountDivided)
RandomMax = 2 / (fsqrt CountDivided)
If RecycleArrSize % 2
i2 = 1
Player.AddItem (ListGetNthForm aaaSFWbtcBooksFormList 0) CountDivided 1
EndIf
While i2 < RecycleArrSize
If CountDivided > 1
RandomBooksCount = (Rand RandomMin, RandomMax) * CountDivided - 1
Else
RandomBooksCount = 0
EndIf
Player.AddItem (ListGetNthForm aaaSFWbtcBooksFormList i2) (CountDivided - RandomBooksCount) 1
Player.AddItem (ListGetNthForm aaaSFWbtcBooksFormList (i2 + 1)) (CountDivided + RandomBooksCount) 1
i2 += 2
Loop
EndIf
;PreWarBookCount = 0 ; ТИП "ФУНКЦИЯ" НЕ СОХРАНЯЕТ ПЕРЕМЕННЫЕ
EndIf
End
BTC-ReducedScript.esp