Jump to content
  • Announcements

    • AndalayBay

      Leaving IP.Board   11/13/2017

      See full announcement here.
    • AndalayBay

      New Theme Set Up   11/14/2017

      We have a new theme created by Vincent that's now available to everyone. It has been set as the default theme, so everyone should see it when you refresh the page. If you still aren't seeing it, you can select it from the Theme drop-down at the bottom of the page. It's called Assimilation. Thanks Vincent. Awesome looking theme!
Sign in to follow this  
tegeusCromis

Coda, this time with something to download...

Recommended Posts

OK, since I re-invented the wheel last time dammit, let's try again. Well, I don't actually regret that, it turned out to be a very productive thread (thanks, Vorians!), and I can think of other uses for that map code too. But wouldn't it be nice if we could actually see a result sometimes?

So this time, I've taken an older piece of batch editing, which in turn was inspired by AB's floater-detect code, and used it to make all the Unique Landscapes logs into Qarl's Harvest activators that give you fungal ingredients.

The result is here: Qarl's Harvest for Unique Landscapes

And here's the code (yes, it does need more comments, but I'm losing the will to live right now :). Need a beer, soonest.):

 

CODA(ULLogsToQarls01, "5.0")

;Substitutes new forms for old

var cellUsage
var cellCounter
var baseObject
var baseToSub
var instance
var arCells
var cell
var arRefs
var objectRef
var newRef
var objCount
var cellCount
var cellX
var cellY
var cellCoords
var formInt

var currX
var currY
var currZ
var currRotX
var currRotY
var currRotZ
var currScale

var newRotX
var newRotY
var newRotZ

var arOldForm
var arNewForm
var formCount

var n1

begin
    
    cellCoords = arcreate(2)
    arinsert(cellCoords,0,-1)
    arinsert(cellCoords,0,-1)

    arOldForm = ArrayCreate (20)
     arNewForm = ArrayCreate (20)
        
     n1 = 0
    while (n1 < 20)
        arinsert(arOldForm, "", -1)
        arinsert(arNewForm, "", -1)
        n1+=1
    loop
       
        arOldForm[0]="LandscapeLogBirch01"
        arNewForm[0]="Qarllandscapelogbirch01"
        arOldForm[1]="LandscapeLogBirchMoss01"
        arNewForm[1]="Qarllandscapelogbirchmoss01"
           arOldForm[2]="LandscapeLogHemlock01"
        arNewForm[2]="Qarllandscapeloghemlock01"
           arOldForm[3]="LandscapeLogMaple01"
        arNewForm[3]="Qarllandscapelogmaple01"
           arOldForm[4]="LandscapeLogMapleMoss01"
        arNewForm[4]="Qarllandscapelogmaplemoss01"
           arOldForm[5]="LandscapeLogOak01"
        arNewForm[5]="Qarllandscapelogoak01"
           arOldForm[6]="LandscapeLogOak02"
        arNewForm[6]="Qarllandscapelogoak02"
           arOldForm[7]="LandscapeLogOakMoss01"
        arNewForm[7]="Qarllandscapelogoakmoss01"
           arOldForm[8]="LandscapeLogOakMoss02"
        arNewForm[8]="Qarllandscapelogoakmoss02"
           arOldForm[9]="LandscapeLogPine01"
        arNewForm[9]="Qarllandscapelogpine01"
           arOldForm[10]="LandscapeLogPineMoss01"
        arNewForm[10]="Qarllandscapelogpinemoss01"
           arOldForm[11]="LandscapeLogRedwood01"
        arNewForm[11]="Qarllandscapelogredwood01"
           arOldForm[12]="LandscapeLogScotchPine01"
        arNewForm[12]="Qarllandscapelogscotchpine01"
        
          n1 = 0
    while (n1 < 13)
 
            baseObject = getFormByEditorID(arOldForm[n1])
             baseToSub = getFormByEditorID(arNewForm[n1])

        cellUsage = GetCellUseList(baseObject)

        foreach instance <- cellUsage

            cell=instance
            arRefs = GetCellObjects(cell)
            
            formInt=GetCellWorldspace(cell)    ;Exteriors only
            
            if (formInt!=0)
                cellCoords=GetCellCoordinates(cell)
                cellX=cellCoords[0]
                cellY=cellCoords[1]

                forEach objectRef <- arRefs

                    if (GetRefBaseform(objectRef) == baseObject)

                        if (objectRef > 0x1000000 && GetRefDisabled(objectRef)==0)    ;Plug-in selection. Hex value is set to pick out 3rd (+) plug-in loaded.
                                
                                printC("("//$cellX//","//$cellY//") "//$objectRef//" - "//arOldForm[n1])
                            
                            ;OK, change this one.
                                  
                                  currX = getRefPosition(objectRef, "X")
                            currY = getRefPosition(objectRef, "Y")
                            currZ = getRefPosition(objectRef, "Z")

                            currRotX = getRefRotation(objectRef, "X")
                            currRotY = getRefRotation(objectRef, "Y")
                            currRotZ = getRefRotation(objectRef, "Z")

                            currScale = GetRefScale(objectRef)
                            
                            ;convert to radians

                            ;WARNING!!! From v8.0, CreateRef will take degrees, so delete the conversions and
                            ;replace the CreateRef line with:

                            newRef=CreateRef(baseToSub, currX, currY, currZ, currRotX, currRotY, currRotZ, cell, GetCellWorldSpace(cell))

                            SetRefScale(newRef, currScale)

                            ;newRotX=currRotX*0.0174532925         ;pre CSE v8.0
                            ;newRotY=currRotY*0.0174532925         ;pre CSE v8.0
                            ;newRotZ=currRotZ*0.0174532925         ;pre CSE v8.0

                            ;newRef=CreateRef(baseToSub, currX, currY, currZ, newRotX, newRotY, newRotZ, cell, GetCellWorldSpace(cell))    ;pre CSE v8.0

                            SetRefDisabled(objectRef,1)    ;Disable old ref
                            SetRefPosition(objectRef, "Z", currZ - 10000)    ;And sink it
                            markAsModified(objectRef, 1)

                            objCount+=1
                        endif
                    endif

                loop   

            endif

        loop
        n1+=1
    loop

       printC("")    
       printC("Object Count: "//$objCount//" logs have been altered. Bye bye.")    
   
 end

Edited by tegeusCromis
Replacing older, messier version of code. Hope I don't crash the server this time...

Share this post


Link to post
Share on other sites

I really needed it, cheers AB. Thing is, I was worrying because I thought I'd crashed the server. It seemed to go down just as I entered the edit I just made again now. Wondered if I'd accidentally achieved (using Coda, heh) the equivalent of an injected SQL attack...

Edited by tegeusCromis

Share this post


Link to post
Share on other sites

That was probably me. I've been working with IPS to sort the issues and they released a new version. I couldn't tell who was online at the time, so I went ahead with the upgrade. Sorry about that. :)

Share this post


Link to post
Share on other sites

Well, some things can get tedious.  If 20 minutes to write a script saves you an hour to do something manually, it's worth it to me.  Plus scripting is fun...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×