Skip to content

Change placeable appearance

ForSeriousForSerious Member Posts: 466
edited April 2022 in Builders - Scripting
I know it can be done with the JSON functions… I have not wondered into those lands yet.
Has anyone else done this yet?

For clarity: There are trees that can be interacted with to get crafting material. These trees spawn at locations of waypoints. The waypoint just signifies where the tree should spawn, but not the type of tree. That is random.
If I remember right, I can't create the JSON from the pallet. I have to copy an existing object, or read it in from the database.
The steps I'm thinking right now are:
Create default tree.
Copy it to JSON.
Change appearance.
Delete default tree.
Create tree from JSON.

Any help or ideas would be nice.

Comments

  • DazDaz Member Posts: 127
    There's a "TemplateToJson" function which lets you grab the json of any template object without having to create the actual object
  • ForSeriousForSerious Member Posts: 466
    I totally ignored that. That sounds like a better way than what I came up with so far.
  • ForSeriousForSerious Member Posts: 466
    For anyone that wants to do something similar, here's what I came up with for my tree example.
    object oTree;
    int iRand = Random(7);
    //45      Wood_Cedar
    //44      Wood_Pine
    //41      Wood_Ash
    //43      Wood_Oak
    //42      Wood_Yew
    //38      Wood_Ironwood
    //39      Wood_Duskwood
    //40      Wood_Darkwood_Zalantar
    int iOffset = 38 + iRand;
    json jTree = TemplateToJson("tree", RESTYPE_UTP);
    json jApp = JsonObjectGet(jTree, "Appearance");
    int iApp;
    switch(iRand)
    {
        case 1: iApp = 557; break;
        case 2: iApp = 101; break;
        case 3: iApp = 539; break;
        case 4: iApp = 554; break;
        case 5: iApp = 563; break;
        case 6: iApp = 259; break;
        case 7: iApp = 560; break;
        default: iApp = 566; break;
    }
    jApp = JsonObjectSet(jApp, "value", JsonInt(iApp));
    jTree = JsonObjectSet(jTree, "Appearance", jApp);
    oTree = JsonToObject(jTree, lWay);
    

    Works better than a charm. The hardest part was finding what to set iApp to. (The Wood type constants are listed out because I give the trees names based on those later. They're also used to set the material obtained from the tree.)
    Yay, now the pine tree is one of the three standard models of pine trees included in the game!
  • ForSeriousForSerious Member Posts: 466
    This JSON stuff gives me the feeling of power! (Though sooooo much harder to work with than actual JavaScript)
    Each kind of tree gives its own kind of stick. To make sure they did not stack and overwrite their local variables and item properties, I had to give them new tags on creation. That stops the game from auto stacking the them. Pretty annoying.
    Now with the JSON functions, I can define the item properties and local variables before I create the object.
    They stack perfectly.
  • ZephiriusZephirius Member Posts: 419
    ForSerious wrote: »
    This JSON stuff gives me the feeling of power!

    Oh no. Look out! Serious is getting drunk on a JSON fuled power grab... :p

  • TarotRedhandTarotRedhand Member Posts: 1,481
    JSON is OK, it's the Argonauts you have to look out for... [dad joke number 5479]

    TR
Sign In or Register to comment.