Sign in to follow this  
Qentinios

python Multiple environment system

10 posts in this topic

Hellow,

 

I want to share my work, I've created 2 year ago, for my old server (Resthea).

 

So, what is it exacly?

 

It's python libraries and code that allow us to have many environment (clouds, light settings, flare and so on) on one map.

 

By default, you can have only one environment for each map.

 

How does it work?

 

Well, once every 30 seconds (you can configure that time) checks our coordinates and compare it to jpg file, which size is the same as map size. Diffrent colors mean diffrent msenv file.

 

What this pack contains?

 

  • possibility to add up to 16777215 areas with diffrent environment on every map.
  • possibility to add diffrent music on these areas
  • possibility to add random snow on these areas
  • 28 ready skyboxes
  • possibility to choose skyboxes quality
  • possibility to configure the time script refreshes
  • possibility to add special xmas configuration
  • easy configuration via text file
  • code is easy to modify
  • bugfix for night and snow systems

 

Disadvantages:

 

  • not so optimal solution
  • .jpg format has indirect coloring between two colors, which sometimes could lead to problems
  • xmas song probably doesn't work (I haven't got time to fix it)
  • lots of redundant libraries, because i've uploaded whole Lib folder
  • descriptions how to add this are in polish, you can use google translate :P , if you wish i can translate it too.

 

Screens:

 

kfb0ws.jpg

 

lg9ld9.jpg

oaw548.jpg

 

dn446z.jpg

 

lvxx4p.jpg

 

Code sample:

    def __SpecialEnvironmentEnable(self, Env, Resthea, SnowEnable, NightEnable, ConfigTime, ConfigSkybox, XmasEvent):
        ### START OF ENVIRONMENT MODULE Resthea.eu, qentinios
        self.Env = Env
        self.Resthea = Resthea
        self.SnowEnable = SnowEnable
        self.NightEnable = NightEnable
        self.ConfigTime = ConfigTime
        self.ConfigSkybox = ConfigSkybox
        self.XmasEvent = XmasEvent
        czass = str(time.ctime())
        sekundy = czass[17:19]
        bg = background.GetCurrentMapName()
        if ConfigTime == 0:
            try:
                ConfigTime = int(linecache.getline("config.cfg", 2))
            except:
                chat.AppendChat(chat.CHAT_TYPE_INFO, "Error while changing environment")
                chat.AppendChat(chat.CHAT_TYPE_INFO, "Cannot open file: config.cfg")
        if ConfigTime == -1:
            return
        map = ( "metin2_map_4_wiatry",
                "metin2_map_krance_swiata",
                "metin2_map_srodziemie",
                "metin2_map_resthea", )
        if bg in map and sekundy != Env:
            if ConfigTime == 5 and int(sekundy) in (5,10,15,20,25,30,35,40,45,50,55,00):
                self.Env = sekundy
                pass
            elif ConfigTime == 15 and int(sekundy) in (15,30,45,00):
                self.Env = sekundy
                pass
            elif ConfigTime == 30 and int(sekundy) in (30,00):
                self.Env = sekundy
                pass
            elif ConfigTime == 60 and int(sekundy) == 30:
                pass
            else:
                if ConfigTime not in (-1,5,15,30,60) and int(sekundy) == 30:
                    chat.AppendChat(chat.CHAT_TYPE_INFO, "Error while changing environment")
                    chat.AppendChat(chat.CHAT_TYPE_INFO, "Wrong data: " + ConfigTime + ", config.cfg, line 2")
                    self.Env = sekundy
                return
        else:
            return
        minuty = czass[14:16]
        godziny = czass[11:13]
        czas = int(godziny + minuty)
        try:
            im = Image.open("msenv/" + bg + ".jpg")
        except:
            chat.AppendChat(chat.CHAT_TYPE_INFO, "Error while changing environment")
            chat.AppendChat(chat.CHAT_TYPE_INFO, "Cannot open file: " + "msenv/" + bg + ".jpg")
            return
        (x, y, z) = player.GetMainCharacterPosition() 
        x = int(x/100)
        y = int(y/100)
        try:
            color = str(im.getpixel((int(x),int(y))))
        except:
            chat.AppendChat(chat.CHAT_TYPE_INFO, "Error while changing environment")
            chat.AppendChat(chat.CHAT_TYPE_INFO, "Not exist pixel: " + str(x) + ", " + str(y) + "; " + "msenv/" + bg + ".jpg")
            return
        #Skybox config
        if ConfigSkybox == "0":
            try:
                ConfigSkybox = linecache.getline("config.cfg", 5)
            except:
                ConfigSkybox = "_1k"
            if ConfigSkybox in ("_512n","_1kn","_1.5kn"):
                ConfigSkybox = ConfigSkybox[:-1]
            if ConfigSkybox not in ("_512","_1k","_1.5k"):
                ConfigSkybox = "_1k"
        #End of skybox config
        #Xmas event
        if XmasEvent == -1:
            try:
                XmasEvent = int(linecache.getline("config.cfg", 8))
            except:
                XmasEvent = 0
        if XmasEvent == 1:
            ColorList={
                #Color (RGB)
                1 : ("(255, 255, 255)", "(241, 255, 158)", "(254, 0, 0)", "(0, 255, 127)", "(158, 255, 248)", "(253, 254, 62)", "(255, 176, 63)", "(222, 255, 0)", "(95, 255, 0)", "(50, 121, 19)", "(95, 192, 35)", "(214, 214, 214)", "(148, 0, 0)", "(142, 142, 142)", "(251, 165, 0)"),
                #Msenv
                2 : ("snowm02", "map_n_desert_01", "fire_low", "white_sky", "default", "rainy", "sand_mountain", "vanilia_white", "trent", "trent02", "vanilia", "snowm02", "fire_low", "default", "desert_cloud"),
                #Mp3
                3 : ("christmas/4w/xmas", "christmas/4w/xmas", "christmas/4w/xmas", "christmas/4w/xmas", "christmas/4w/xmas", "christmas/krance/xmas", "christmas/krance/xmas", "christmas/krance/xmas", "christmas/krance/xmas", "christmas/krance/xmas", "christmas/srodziemie/xmas", "christmas/srodziemie/xmas", "christmas/srodziemie/xmas", "christmas/resthea/xmas", "christmas/resthea/xmas_wyspa"),
                #Snow
                4 : (1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1)
                }
        #End of Xmas event
        else:
            ColorList={
                #Color (RGB)
                1 : ("(255, 255, 255)", "(241, 255, 158)", "(254, 0, 0)", "(0, 255, 127)", "(158, 255, 248)", "(253, 254, 62)", "(255, 176, 63)", "(222, 255, 0)", "(95, 255, 0)", "(50, 121, 19)", "(95, 192, 35)", "(214, 214, 214)", "(148, 0, 0)", "(142, 142, 142)", "(251, 165, 0)"),
                #Msenv
                2 : ("snowm02", "map_n_desert_01", "fire_low", "white_sky", "default", "rainy", "sand_mountain", "vanilia_white", "trent", "trent02", "vanilia", "snowm02", "fire_low", "default", "desert_cloud"),
                #Mp3
                3 : ("4w/lodowa", "4w/pustynia", "4w/ognista", "4w/orki", "4w/srodek", "krance/przeklete", "krance/pustynia", "krance/swiatynia", "krance/las", "krance/las2", "srodziemie/trawa", "srodziemie/lodowa", "srodziemie/ognista", "resthea/trawa", "resthea/wyspa"),
                #Snow
                4 : (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0)
                }
        i = 0
        Colors = ColorList[1]
        length = len(Colors)
        for ColorItem in xrange(length):
            if color == Colors[ColorItem]:
                #START OF SNOW EFFECT
                Snow = ColorList[4]
                if SnowEnable != 1:
                    if Snow[ColorItem] == 1 and int(minuty) in (2,7,12,17,22,27,32,37,42,47,52,57) and int(sekundy) in (00,01,30,31):
                        random = app.GetRandom(1,3)
                        if random == 1:
                            background.EnableSnow(1)
                        else:
                            background.EnableSnow(0)
                    if Snow[ColorItem] == 0:
                            background.EnableSnow(0)
                #END OF SNOW EFFECT
                if Resthea == color:
                    break
                #START OF MUSIC MODULE
                Music = ColorList[3]
                if app.IsExistFile("BGM/" + Music[ColorItem] + ".mp3")==1:
                    if musicInfo.fieldMusic != "":
                        snd.FadeOutMusic("BGM/" + musicInfo.fieldMusic)
                    musicInfo.fieldMusic = (Music[ColorItem] + ".mp3")
                    snd.FadeInMusic("BGM/" + musicInfo.fieldMusic)
                else:
                    if musicInfo.fieldMusic != "":
                        snd.FadeOutMusic("BGM/" + musicInfo.fieldMusic)
                    musicInfo.fieldMusic=musicInfo.METIN2THEMA
                    snd.FadeInMusic("BGM/" + musicInfo.fieldMusic)
                #END OF MUSIC MODULE
                Msenv = ColorList[2]
                if NightEnable == 1 and self.__IsXMasMap():
                    background.RegisterEnvironmentData(1, constInfo.ENVIRONMENT_NIGHT)
                    background.SetEnvironmentData(1)
                else:
                    background.RegisterEnvironmentData(1, "d:/ymir work/environment/" + Msenv[ColorItem] + ConfigSkybox + ".msenv")
                    background.SetEnvironmentData(1)
                self.Resthea = color
                break
            else:
                i = i+1
        if i == length:
            background.SetEnvironmentData(0)
            snd.FadeOutMusic("BGM/" + musicInfo.fieldMusic)
            musicInfo.fieldMusic=musicInfo.METIN2THEMA
            snd.FadeInMusic("BGM/" + musicInfo.fieldMusic)
            self.Resthea = color
    ### END OF ENVIRONMENT MODULE Resthea.eu, qentinios

Old video with system:

 

https://www.youtube.com/watch?v=sz1njy6sBqQ

 

Download:

 

Without skyboxes:

https://www.mediafire.com/?edtdz50gc4tzmqj

With skyboxes:

https://www.mediafire.com/?y14v0yir24tqbvv
  • Like 17

Share this post


Link to post
Share on other sites

Exacly, you can e.g. create map with snow and some winter music, and on the same map flame area where sky will become red and music terrifying.

Share this post


Link to post
Share on other sites

You can use it like that. Simply, it allows you to have multiple skyboxes/environments on sigle map

I love you.

I was wondering for a long time if this was possible, specially with music.

  • Like 1

Share this post


Link to post
Share on other sites

Sorry for revive old topic but how can I install this system? Which files of lib folder need to copy to my lib client folder? And what I have to do with the files of script folder? Thanks in advance.

Edited by homer24

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  

  • Recently Browsing   0 members

    No registered users viewing this page.