Jump to content

Script Review


Recommended Posts

30 minutes ago, PeterMartyr said:

my comment was generic, If you post code for the Witcher, any game the nexus hosts, and you find that it does not look like the code you wrote, ? it is because your using tabs not spaces, say this is false any one I dare you?

at @dylbill are you still sore I wrote code you been working on for what days weeks months maybe in few hours and where you used 200 lines of code to create 4 objects I created over 50 objects with 70 lines of code?, it show your still bitter.. 😂😂😂😂 you had to come here uninvited to have a shot at me for stating a simple truth, cos no you look down on could write code 100 fold better than you 😅😅😅😅 that eats you up does it not?

Edit now I am taking the PISS out of you... see the difference 

Edit @dylbill these forum are like an audit trial,  it clear as day I never speak to you until you have cheap shot at me.. I am gonna repeat get a f*#@ing life, and at any nexus mod check to see what said is true ))

Man are you full of crap, stop projecting. It’s clear you have a mental deficiency. It took me 20 min to write that playing card example and was no where near 200 lines of code, where it took you all day to write sub par example of the same thing that didn’t even add a new type to papyrus. AND all you do here is take cheap shots at people. Here’s an idea, if you can’t take it, don’t dish it out clown 🤡 

Link to comment
Share on other sites

looks good, but I do not see the point of the states, you use states to simplify overly complex code, or to achieve what cannot be done without a state... I am not saying not to use states, but challenging you think about it, do you really need it, what other wise unattainable advantage does using states  bring 

Link to comment
Share on other sites

@dylbill dude we have audit trail, I never speak to you, ever, now stop this before I make official complaint, forcing Admin to do said audit trail 

EDIT @dylbill never speak to me again I have enough savvy, one more comment anywhere and I will lodge a complaint.. and let the admin judge

Link to comment
Share on other sites

@PeterMartyr 

So I guess you didn’t write this on a thread I started years ago about converting int to hex in papyrus, without posting your own “superior” function to do so. 
“Was this not this solved RAW without a framework... many many many many years ago? a quick google search would have found brilliant RAW recursive logarithms that make those here look like a child wrote them. hehehehe. that could have, should have, didn't get converted to papyrus to solved this for vanilla skyrim?? with NO SCRIPT EXTENDERS. just sayin'” 

https://forums.nexusmods.com/topic/8441118-convert-decimal-formid-to-hexadecimal/page/2/


That’s what's called a cheap shot. 

So I guess you didn’t say: 

“what..../?

most pointless question ever, or maybe something close to nothing.. “

In another thread:


https://forums.nexusmods.com/topic/13487337-persistence-and-location/#comment-130441952

Another cheap shot. There's cheap shots by you all over this forum. Again, stop being a hypocrite. If you can’t take it, don’t dish it out, and sure, be my guest, get an admin involved. Your posts are there for everyone to see. 👍

Link to comment
Share on other sites

57 minutes ago, PeterMartyr said:

looks good, but I do not see the point of the states, you use states to simplify overly complex code, or to achieve what cannot be done without a state... I am not saying not to use states, but challenging you think about it, do you really need it, what other wise unattainable advantage does using states  bring 

I edited the script without using states as you suggested.

Scriptname PlayerScript extends ReferenceAlias  

int counter
float currentCarryWeight

Event OnInit()
  RegisterForSingleUpdate(1.0)
  RegisterForSleep()
EndEvent

Event OnUpdate()
  if Game.GetPlayer().IsRunning() && !Game.GetPlayer().IsInCombat() && !Game.GetPlayer().IsSneaking()
    counter+=1
  endif

  if counter == 60
    counter=0
    currentCarryWeight = Game.GetPlayer().GetAV("CarryWeight")
    Game.GetPlayer().DamageAV("CarryWeight", -currentCarryWeight)
    Utility.WaitGameTime(1)
    Game.GetPlayer().RestoreAV("CarryWeight", currentCarryWeight)
    RegisterForSingleUpdate(1.0)
  Else 
    RegisterForSingleUpdate(1.0)
  endif
EndEvent

Event OnSleepStop(bool abInterrupted)
  counter = 0
EndEvent

 

Link to comment
Share on other sites

Just noticed you damaged by a negative value then restored via a positive one. Both should be a positive value

Like if you damage 500 health, you don't put -500. You put 500

Link to comment
Share on other sites

ONE look mate, sorry if that offend you but had a discussion about working out something that was in the public domain for hell like ever......   How is that a cheap shot?  That code is copyright free even... I felt it was pointless waste of time, and I stand by that.. The solution was quick google search.  Not what extenders do I need to install to achieve this...  the truth was you can do it vanilla.. 

this was your code 

Spoiler
String[] Property HexDigits Auto 
String[] Property BinDigits Auto 
String[] Property EvenNumbers Auto
 
Event OnInit()
    InitArrays()
EndEvent 
 
Function InitArrays()
    BinDigits = New String[16]
    BinDigits[0] = "0000"
    BinDigits[1] = "0001"
    BinDigits[2] = "0010"
    BinDigits[3] = "0011"
    BinDigits[4] = "0100"
    BinDigits[5] = "0101"
    BinDigits[6] = "0110"
    BinDigits[7] = "0111"
    BinDigits[8] = "1000"
    BinDigits[9] = "1001"
    BinDigits[10] = "1010"
    BinDigits[11] = "1011"
    BinDigits[12] = "1100"
    BinDigits[13] = "1101"
    BinDigits[14] = "1110"
    BinDigits[15] = "1111"
 

    HexDigits = New String[16]
    HexDigits[0] = "0"
    HexDigits[1] = "1"
    HexDigits[2] = "2"
    HexDigits[3] = "3"
    HexDigits[4] = "4"
    HexDigits[5] = "5"
    HexDigits[6] = "6"
    HexDigits[7] = "7"
    HexDigits[8] = "8"
    HexDigits[9] = "9"
    HexDigits[10] = "a"
    HexDigits[11] = "b"
    HexDigits[12] = "c"
    HexDigits[13] = "d"
    HexDigits[14] = "e"
    HexDigits[15] = "f"
    
    EvenNumbers = New String[5]
    EvenNumbers[0] = "0"
    EvenNumbers[1] = "2"
    EvenNumbers[2] = "4"
    EvenNumbers[3] = "6"
    EvenNumbers[4] = "8"
EndFunction

 
String Function ConvertIDToHex(Int IDToConvert)
    If IDToConvert >= 0
        Int A = IDToConvert
        String IntBinary
        If EvenNumbers.Find(StringUtil.GetNthChar(A, (StringUtil.GetLength(A as string) - 1))) > -1
            IntBinary = ("0")
        Else 
            IntBinary = ("1")
        Endif 
        
        Utility.WaitMenuMode(0.1)
        
        While A > 1
            A /= 2
            
            If EvenNumbers.Find(StringUtil.GetNthChar(A, (StringUtil.GetLength(A as string) - 1))) > -1
                IntBinary = ("0" + IntBinary)
            Else 
                IntBinary = ("1" + IntBinary)
            Endif 
            
            If A <= 1
                
                Float decCheck = ((StringUtil.GetLength(IntBinary) as float) / 4)
                Float decRemainder = decCheck - Math.Floor(decCheck)
                
                If decRemainder == 0.25
                    IntBinary = "000" + IntBinary
                Elseif decRemainder == 0.5
                    IntBinary = "00" + IntBinary
                Elseif decRemainder == 0.75
                    IntBinary = "0" + IntBinary
                Endif
                
                ;Debug.MessageBox("Bin is " + IntBinary)
                Utility.Wait(0.1)
                Return ConvertBinaryToHex(IntBinary)
            Endif
        EndWhile
    Else 
        Int A = ((IDToConvert - (IDToConvert * 2)) - 1) ;converts negative to positive.
        String IntBinary
        If EvenNumbers.Find(StringUtil.GetNthChar(A, (StringUtil.GetLength(A as string) - 1))) > -1
            IntBinary = ("1")
        Else 
            IntBinary = ("0")
        Endif 
        
        Utility.WaitMenuMode(0.1)
        
        While A > 1
            A /= 2
            
            If EvenNumbers.Find(StringUtil.GetNthChar(A, (StringUtil.GetLength(A as string) - 1))) > -1
                IntBinary = ("1" + IntBinary)
            Else 
                IntBinary = ("0" + IntBinary)
            Endif 
            
            If A <= 1
                
                Float decCheck = ((StringUtil.GetLength(IntBinary) as float) / 4)
                Float decRemainder = decCheck - Math.Floor(decCheck)
                
                If decRemainder == 0.25
                    IntBinary = "111" + IntBinary
                Elseif decRemainder == 0.5
                    IntBinary = "11" + IntBinary
                Elseif decRemainder == 0.75
                    IntBinary = "1" + IntBinary
                Endif
                
                ;Debug.MessageBox("Bin is " + IntBinary)
                Utility.Wait(0.1)
                Return "ff" + ConvertBinaryToHex(IntBinary)
            Endif
        EndWhile
    Endif 
EndFunction
 
String Function ConvertBinaryToHex(String BinToConvert)
    String HexResult
    Int I = -4
    Int M = (StringUtil.GetLength(BinToConvert) - 1)
    While I < M
        I += 4
        If I < M
            String Bin4 = (StringUtil.Substring(BinToConvert, I, 4))
            HexResult = (HexResult + HexDigits[BinDigits.Find(Bin4)])
        Else
           Return  HexResult
        Endif
    EndWhile
EndFunction
 

Event SomeEvent()
    String HexID =  ConvertIDToHex(SomeForm.GetformId())
EndEvent

 

this is the solution mate not that, and sorry if it offends you, As you can see it straight to the point, is that why you hate me? cos I said I your code was bad? I stand by that, is was bad, and it is bad, let the community compare what started the feud ,btw OFC hex can be express as negative but you never find a Skyrim form ID that is negative, so why bother, seriously I am asking you? Ever heard of keeping it simple, and not making code overly complicated for no reason what so ever, if honest constructive criticism is insulting to you, I am guilty as charged 

Spoiler
string Function DecimalToHexadecimalVanilla(int decimal) Global

    if (decimal < 0)
        Debug.Trace("Negative numbers not supported")
        Return ""
    EndIf

    If decimal == 0
        Return "0x0"
    EndIf

	string[] letters = new string[6]
	letters[0]="A"
	letters[1]="B"
	letters[2]="C"
	letters[3]="D"
	letters[4]="E"
	letters[5]="F"

    string hexadecimal = ""
    while (decimal > 0)
        int remainder = decimal % 16
        if remainder < 10
            hexadecimal = remainder As string + hexadecimal
        Else
            hexadecimal = letters[remainder - 10] + hexadecimal
        EndIf
        decimal /= 16
    endwhile
    return "0x" + hexadecimal
EndFunction

 

 

TWO LOL your lucky he was not pirate, he implying something that was is impossible in the KIT....  I further stated that abuse of xEdit is harmful, and no one would give advice that would break a mod.... you think all the post have merit?  I told him to stop abusing xEdit and use the KIT, How is that bad?

THREE what next the the Fibonacci sequence, both both alliterative and recursive

 

 

 

Link to comment
Share on other sites

17 minutes ago, Sphered said:

Just noticed you damaged by a negative value then restored via a positive one. Both should be a positive value

Like if you damage 500 health, you don't put -500. You put 500

I wasn't aware of that due to negative values given for DamageAV are converted to positive (https://ck.uesp.net/wiki/DamageActorValue_-_Actor). Thank you for the warning.

Link to comment
Share on other sites

@PeterMartyr

1. I know my original code on that thread was bad. It wasn't working, which was why I posted to get help with the function. That's what the forums are for. 

2. The issue was already solved, there was no need for you to comment. ALSO 4 or 5 other members posted actual working code for that function. What offended me was 
"that make those here look like a child wrote them". That's condescending and definitely a cheap shot, not just to me but to everyone else who had posted functions in that thread that work. 

3. The function you just posted didn't solve my original problem, which was to account for negative numbers, not just return "". This is the code I'm now using that works: 

;requires skse. Convert int to hex string.
;if result string length is less than minDigits,
;adds 0's to the start for positive numbers, or f's to the start for negative numbers.
;default is 8 (for form IDs)
String function ConvertIntToHex(int i, int minDigits = 8) Global
    String s = ""
     
    If i >= 0
        String HexDigits = "0123456789abcdef"
        while i > 0
            s = StringUtil.GetNthChar(HexDigits , (i % 16)) + s
            i /= 16
        EndWhile 
        
        While StringUtil.GetLength(s) < minDigits 
            s = "0" + s 
        EndWhile
    Else 
        String HexDigits = "fedcba9876543210"
        i = DbMiscFunctions.IntAbs(i) - 1
        while i > 0
            s = StringUtil.GetNthChar(HexDigits , (i % 16)) + s
            i /= 16
        EndWhile 
        
        While StringUtil.GetLength(s) < minDigits 
            s = "F" + s 
        EndWhile
    Endif
    
    return s
EndFunction

 

 

Link to comment
Share on other sites

Posted (edited)
10 hours ago, xkkmEl said:

Sometimes PeterMartyr is a bit of a code puritan, wanting to impose his own customs and ethics on others.  Indentation is important; it's part of keeping the code readable and maintainable, but it's the objective that's important and you're doing fine.

His comment on bKeepUpdating should be attended.  If you had a use for it in mind, your code is not doing that.

More important, and this you really MUST address, is the placement of RegisterForSingleUpdate inside the OnUpdate event.  It needs to be one of the very last things in the event function... otherwise you risk having multiple copies of that event code running concurrently which may cause all sorts of difficult to trace or understand logic flows.

You may think that the 1.0 second delay is more than adequate to finish the 1st OnUpdate call before the second kicks in.  That may be right most of the time, but once in a while the 1st instance will be delayed (for a variety of reasons, including a critter spawn event that launches 80 script events at once, which trigger a suspended stack event, which holds your script back 10 seconds, or more).  These problems are hell to debug because they will be rare, random and virtually impossible to replicate.

Don't take chances, properly chain your RegisterForSingleUpdate calls from tail to head.

Following your informations, I changed the frequency of checking the player's running status to every five seconds, instead of every second. And if the player is running during the check, they are counted as having run for five seconds. I was concerned that the player could exploit this by running for less than five seconds to prevent the counter from incrementing, but it doesn't seem likely since they can't detect the check times.

This is the current version of the script, and I hope it's ready to use. Thank you all again for your help.

Scriptname PlayerScript extends ReferenceAlias  

int counter
float currentCarryWeight

Event OnInit()
  RegisterForSingleUpdate(1.0)
  RegisterForSleep()
EndEvent

Event OnUpdate()
  if Game.GetPlayer().IsRunning() && !Game.GetPlayer().IsInCombat() && !Game.GetPlayer().IsSneaking()
    counter+=5
  endif

  if counter == 60
    counter=0
    currentCarryWeight = Game.GetPlayer().GetAV("CarryWeight")
    Game.GetPlayer().DamageAV("CarryWeight", currentCarryWeight)
    Utility.WaitGameTime(1)
    Game.GetPlayer().RestoreAV("CarryWeight", currentCarryWeight)
    RegisterForSingleUpdate(1.0)
  Else 
    RegisterForSingleUpdate(5.0)
  endif
EndEvent

Event OnSleepStop(bool abInterrupted)
  counter = 0
EndEvent

 

Edited by vn524135
Link to comment
Share on other sites

  • Recently Browsing   0 members

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