Results 1 to 6 of 6

Thread: Randomizing tint on a custom model.

  1. #1

    Randomizing tint on a custom model.

    Is there a way to randomize the tint of an object when it is removed from a bag? I'm interested in doing this with a custom model of a shirt button, because the color of the button really doesn't matter, but I don't want to set individual colors for 15 different buttons (there's a finite amount in the mod I'm playing around with). Plus I think it would be a nice effect never knowing what color you'll get. ^_^
    "Do not meddle in the affairs of dragons, for you are crunchy and good with ketchup."
    My TTS Mods

  2. #2
    function onObjectLeaveContainer(container, obj)
        if container == getObjectFromGUID('BAG_GUID') then
            local randTint = {math.random(), math.random(), math.random()}
    Keep in mind that random tint as in every RGB component random from 0-1 like in the snippet usually doesn't really look good. You'll probably want to tweak the generation for more vibrant colors. Or just make a predefined list of couple dozens and pick randomly from it.

  3. #3
    I'd would randomly choose from the pre-defined colour sets in TTS listed in the PLAYER COLOURS section of the knowledgebase.

    function onObjectLeaveContainer(container, obj)
        if container == getObjectFromGUID('4100b2') then
            local colour = {'White','Brown','Red', 'Orange','Yellow','Green','Teal','Blue', 'Purple', 'Pink', 'Grey', 'Black'}
    This will show dups.. but I think you would get the idea.

    It should be noted as far as I know, the "onObjectLeaveContainer()" function is global and works anywhere in your script.. it just has to be in the file "somewhere". I tend to put all my onObject.... stuff either in global or into a dummy object called "CollisionTests"... or something.. that way all the various detection code can be in a single nice and easy to edit place. Essentially what it is doing is EVERYTIIME anything exist a container, it tests the container guid.. if it matches one of the If statements you have used.. then it will do something.

    If you want to add all the enter and exit code directly into the bags.. as in attach the scripts TO the bags you want the tests done.. (another way to orginise yourself) use this code...

    function onObjectLeaveContainer(container, obj)
        if container == getObjectFromGUID(self.getGUID()) then
            do stuff
    It doesn't matter as far as I know how many of these functions you add to many objects.. I just like to put it all in one file or in global as it is easyer for my brain. Even so the above code will test the "leave" event for itself.. so you can just paste it into the bags you want it to happen on.

    As for the other method dzikakulka talks about... that is using the actual RPG codes.. My understanding that they need to be three values from 0-1... so obj.setColorTint({1,1,1})... "math.random()" with no parameters produced a value between 0-1.. so his code is a true random colour (do not forget randomseed in onload) BUT... you can use your own RBG values that you find in any paint app colour pickers (like the one in TTS itself.. but using some simple math... just divide the rgb colour values by 255

    So the above colour is written as.... obj.setColorTint({52/255, 149/255, 88/255})

    So with the above code I posted that randoms from the pre-defined colour lists, you can make your own easy enough using that code from RBG values.. like say you want to random form a set list of shades of green....

    local colour = { {52/255, 149/255, 88/255}, {12/255, 84/255, 39/255}, {81/255, 255/255, 146/255}, {21/255, 158/255, 21/255} }

    The last part is more complex.. .the "not using a same colour twice" thing.

    I would have to try a few things to test it but basically I would store the random colour in a table and then test it .. if it is the same as anything stored random again.. or as with the "list" method, after the colour is used, remove it from the table. Though this would need a table stored outside of the function itself.
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

  4. #4
    This is awesome! Thanks! I'm not too worried about color duplication, as the color of the buttons doesn't really matter. I just wanted something a bit more interesting to add a bit of flare to the piece. This is a great starting point for me to play with. Thanks again!
    "Do not meddle in the affairs of dragons, for you are crunchy and good with ketchup."
    My TTS Mods

  5. #5
    I once wrote a random color system for something else in javascript. Something I did to help with that was instead of using RGB components to randomize I actually used HSL (Hue, Saturation, Lightness). I also rounded the random input for each component to a given increment. That it so say, for example: I first randomized the hue from 0 to 360 degrees in incremements of 10 degrees. I then randomized Saturation between 35% and 100% in increments of 15%.
    Lightness I did in a slightly more complex way: I didn't use a linear random curve to generate that one but rather a power-curved random distrubution. This was so that it would be weighted towards darker colors more often (our eyes pick up variations in darker colors more easily than lighter colors). I also rounded to incremements, but the distribution of those increments was also determined by that same power curve. So, for example, towards black, the value would be rounded to the nearest 5%, but towards light it would be rounded to the nearest 15% increment.
    You're still going to need to check for duplicates, of course.

  6. #6
    Tragic's first code worked out just perfectly for it. I'm not worried about duplicates as the color of the button isn't a factor of the gameplay. Thanks for all the help everyone!
    "Do not meddle in the affairs of dragons, for you are crunchy and good with ketchup."
    My TTS Mods

Similar Threads

  1. [SOLVED] Randomize Zones not Randomizing
    By decumanusmaximus in forum Bug Reports
    Replies: 1
    Last Post: 11-21-2017, 01:49 PM
  2. Replies: 6
    Last Post: 09-19-2016, 08:33 PM
  3. Replies: 2
    Last Post: 09-16-2016, 10:25 PM
  4. Custom Models, Color Tint, etc.
    By VzioNARY in forum General Discussion
    Replies: 6
    Last Post: 12-13-2015, 01:19 PM
  5. Custom model color tint error - red background
    By Einherj in forum General Discussion
    Replies: 0
    Last Post: 01-03-2015, 05:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts