Jump to content

Script Sort value in alphabetical order


Swe-DivX

Recommended Posts

Posted

Trying to fin out how to sort a value.

 

Ex MFMMF to MMMFF. Cant find anything on sorting values. And remove the last letter ?

Will be used if animation is not found, remove one actor and try again.

Posted
string Function SortPositionsByGender(string positions)
    string[] genderPositions = new string[3]
    int i

    i = 0

    while i < StringUtil.GetLength(positions)
        string pos = StringUtil.GetNthChar(positions, i)
        int gender

        if pos == "M"
            gender = 0
        elseif pos == "F"
            gender = 1
        else
            gender = 2
        endif

        genderPositions[gender] += pos

        i += 1
    endwhile

    string output = ""

    i = 0

    while i < genderPositions.Length
        output += genderPositions[i]

        i += 1
    endwhile

    return output
EndFunction

string Function NextPositionsTag(string positions)
    int len = StringUtil.GetLength(positions)

    if len <= 1
        return positions
    endif

    return StringUtil.Substring(positions, 0, len - 1)
EndFunction

 

Posted

I am stuck ?

 

akrefTags result in "M" I want it to be MMFFMF

 

;Advanced Actor Tags
	string akref1Tags
	string akref2Tags
	string akref3Tags
	string akref4Tags
	string akref5Tags
	string akref6Tags
	string akref7Tags
	string akrefTags
	string akrefTagss
	
	if Sextype >= 1 && bAdvancedActorTags
		if (SexLab.GetGender(akref1) >= 2) || (SexLab.GetGender(akref2) >= 2) || (SexLab.GetGender(akref3) >= 2) || (SexLab.GetGender(akref4) >= 2) || (SexLab.GetGender(akref5) >= 2) || (SexLab.GetGender(akref6) >= 2) || (SexLab.GetGender(akref7) >= 2)
			tags = ""
			suppress = ""
		elseif (SexLab.GetGender(akref1) == 0)
			akref1Tags = "M"
		elseif (SexLab.GetGender(akref1) == 1)
			akref1Tags = "F"
		elseif (SexLab.GetGender(akref2) == 0)
			akref2Tags = "M"
		elseif (SexLab.GetGender(akref2) == 1)
			akref2Tags = "F"
		elseif (SexLab.GetGender(akref3) == 0)
			akref3Tags = "M"
		elseif (SexLab.GetGender(akref3) == 1)
			akref3Tags = "F"
		elseif (SexLab.GetGender(akref4) == 0)
			akref4Tags = "M"
		elseif (SexLab.GetGender(akref4) == 1)
			akref4Tags = "F"
		elseif (SexLab.GetGender(akref5) == 0)
			akref5Tags = "M"
		elseif (SexLab.GetGender(akref5) == 1)
			akref5Tags = "F"
		elseif (SexLab.GetGender(akref6) == 0)
			akref6Tags = "M"
		elseif (SexLab.GetGender(akref6) == 1)
			akref6Tags = "F"
		elseif (SexLab.GetGender(akref7) == 0)
			akref7Tags = "M"
		elseif (SexLab.GetGender(akref7) == 1)
			akref7Tags = "F"
		endif
			akrefTags = akref1Tags + akref2Tags + akref3Tags + akref4Tags + akref5Tags + akref6Tags + akref7Tags
			tags = akrefTags + addtags

 

Posted
  1. Why are you not using arrays like in my example? This is just ugly, slow and most of all unnecessary. As for the error, it's because you've an elseif chain; only one or no statement block will be processed.
  2. I am assuming you are using this to get animations, why not use GetAnimationsByType instead?
  3. MMFFMF requires 6 actors. SexLab caps at 5.
  4. You clearly don't want it in alphabetical order.
sslBaseAnimation[] Function GetAnimationsByGenders(Actor[] actors, int[] exclude = none)
    int[] count = new int[2]

    int i = 0

    while i < actors.Length
        int gender = SexLab.GetGender(actors[i])

        if gender >= 0 && gender < count.Length
            count[gender] += 1
        endif

        i += 1
    endwhile

    if exclude != none && exclude.Length == count.Length
        int j = 0

        while j < count.Length
            count[j] -= exclude[j]

            if count[j] < 0
                return none
            endif

            j += 1
        endwhile
    endif

    ; this 
    int countTotal = count[0] + count[1]
    ; or this
    int countTotal = PapyrusUtil.AddIntValues(count)

    if countTotal > 5
        return none
    endif

    return SexLab.GetAnimationsByType(countTotal, Males = count[0], Females = count[1], Aggressive = true)
EndFunction
int[] exclude = new int[2]
sslBaseAnimation[] anims

string[] addTags = new string[1]
addTags[0] = "whatever"

bool break = false

while !break
    anims = sslUtility.FilterTaggedAnimations(GetAnimationsByGenders(myActors, exclude), addTags)

    if anims != none && anims.Length > 0
        break = true
    else
        int gender

        if ... ; whatever your condition is for removing genders
            gender = 1
        else
            gender = 0
        endif
        
        exclude[gender] += 1

        if (exclude[0] + exclude[1]) >= myActors.Length
        if PapyrusUtil.AddIntValues(exclude) >= myActors.Length
            break = true
        endif
    endif
endwhile

if anims == none || anims.Length < 1
    DoError()
endif

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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