• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS 1.4.2] Random color monster outfit

Trollheim

Well-Known Member
Joined
May 27, 2022
Messages
65
Reaction score
88
Hello!
Today I am presenting you really easy fun script for changing colors of monsters. Monsters like bandit or dwarf miner can have random (or almost random) colors of outfit.
1670429673914.png

In head section you have table of colors for hair (not to have green or pink hair, just normal hair colors)


Instalation:
1. create file named ChangeCreatureColors.lua and place it inside data>monster>scripts directory
2. Put this code inside
Lua:
local colors = {
    head = { 0, 1, 2, 3, 19, 20, 21, 22, 38, 39, 40, 41, 57, 58, 59, 60, 76, 77, 78, 79, 95, 96, 97, 98, 114, 115, 116, 117}
}

function onCreatureAppear(self, creature)
    local outfit = self:getOutfit()
    local monsterT = MonsterType(self:getName())
    if not monsterT then
        return
    end
    local monsterOutfit = monsterT:getOutfit()
    if outfit.lookHead == monsterOutfit.lookHead and outfit.lookBody == monsterOutfit.lookBody and  outfit.lookLegs == monsterOutfit.lookLegs and outfit.lookFeet == monsterOutfit.lookFeet then
        self:setOutfit({lookType = outfit.lookType, lookHead = colors.head[math.random(1, #colors.head)], lookBody = math.random(1, 132), lookLegs = math.random(1, 132), lookFeet = math.random(1, 132)})
    end
end
3. Edit monster you would like to use script on and add
XML:
script="ChangeCreatureColors.lua"
to it's main node
It should look like this
XML:
<monster name="Bandit" nameDescription="a bandit" race="blood" experience="65" speed="180" manacost="450" script="ChangeCreatureColors.lua">
4. Enjoy :)

There is also known bug. Monsters placed on map during loading server won't execute onCreatureApper event so they will have regular outfit colors. If you approach creature on same level, it color will not change, but if you relog or change floor near creature it outfit changes.
 
Lua:
if outfit.lookHead == monsterOutfit.lookHead then
        self:setOutfit({lookType = outfit.lookType, lookHead = colors.head[math.random(1, #colors.head)]})
    end
 
Most likely because the default color is 0 (white). You got to copy the value from the creature outfit.
Untested:

Lua:
self:setOutfit({lookType = outfit.lookType, lookHead = colors.head[math.random(1, #colors.head)], lookBody = outfit.lookBody, lookLegs = outfit.lookLegs, lookFeet = outfit.lookFeet})
 
Most likely because the default color is 0 (white). You got to copy the value from the creature outfit.
Untested:

Lua:
self:setOutfit({lookType = outfit.lookType, lookHead = colors.head[math.random(1, #colors.head)], lookBody = outfit.lookBody, lookLegs = outfit.lookLegs, lookFeet = outfit.lookFeet})

This works, thank you :)

1680532561390.png
 
I managed to configure this system on my nostalrius distribution and it worked like a charm:
tIeTIqp.png

I had to create an onSpawn event on the sources, not much complicated, and a dragon outfit with masks to apply the color variations.
Very nice feature to have, it helps to turn the world a bit more realistic.
 
Back
Top