Outdated: Project Living World

Discuss scripting for IceBlink Engine

Re: Project Living World

Postby youngneil1 » Wed Sep 18, 2013 2:50 pm

... and the last of the five scripts that are needed for moving actors on the world map:

5. gaGMEndCombatRound (placed on each encounter's onEndCombat script hook)
Code: Select all
//gaGMEndCombatRound (placed on each encounter's onEndCombat script hook)
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using IceBlinkCore;
using IceBlink;
using System.Drawing;

namespace IceBlink
{
    public class IceBlinkScript
    {
       


        public void Script(ScriptFunctions sf, string p1, string p2, string p3, string p4)
        {

            #region This is not needed for moving actors on worldmap - it's just code for my custmimzed flee system (you can ignore or delete this)
            //This part sets the global "Fledfrom" to value "Brave"- it causes the party heartbeat script that plays on every heartbeat to stop recalling the encounter
            //(in other words: this shuts off the loops that prevents fleeing from combat because now the combat has been won)
            int created100 = 0;
            foreach (GlobalString variable in sf.gm.module.ModuleGlobalStrings)
            {
                if (variable.Key == "FledFrom")
                {
                    variable.Value = "Brave";
                    created100 = 1;

                }
            }
            if (created100 == 0)
            {
                GlobalString FledFrom = new GlobalString();
                FledFrom.Key = "FledFrom";
                FledFrom.Value = "Brave";
                sf.gm.module.ModuleGlobalStrings.Add(FledFrom);
            }
#endregion

            #region Enters the defeated creature into the list of defeated cretaure (which will be used by gaSynchronizeActorsWithWorldTime.cs to remove the defetaed creature from all areas)
            //Prepare the defeated creature to be deleted on world map
            //IBMessageBox.Show(sf.gm, "EndCombat has stored in defeated");       
            List<Creature> templist = (List<Creature>)sf.GetGlobalObject("defeatedCreatureList");
            templist.Add((Creature)sf.GetGlobalObject("potentiallyDefeatedCreature"));
            sf.SetGlobalObject("defeatedCreatureList", templist);
            #endregion
        }
    }
}
User avatar
youngneil1
Backer
Backer
 
Posts: 4436
Joined: Sat Dec 08, 2012 7:51 am

Re: Project Living World

Postby youngneil1 » Wed Sep 18, 2013 4:09 pm

Integrated a quickfix to save world time (see bug reports) into the two scripts below as saving time is quite important for my current script development here (mayhaps the quick fix help to fix the bug? Likely the real fix will be easier though :-)):

1. worldTimeUIText.cs with quick fix for saving worldtime
Code: Select all
//worldTimeUIText.cs (no need for script hook, engine is calling this likely per tick, i.e. very, very often per second!)
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using IceBlinkCore;
using IceBlink;
using System.Drawing;
using System.IO;

namespace IceBlink
{
    public class IceBlinkScript
    {

        public string weekday;
        public string dayInMonth;
        public string monthInYear;
        public string season;
       
        public void Script(ScriptFunctions sf, string p1, string p2, string p3, string p4)
        {
            #region Read the current time in seconds, convert to a date and store in a globalint (quick fix to be able to safe it)
            //interprets the counter as seconds
            //note that you can choose the mopdule's starting date (in seconds) in the toolset  under module properties, WorldTime property
            TimeSpan t = TimeSpan.FromSeconds(sf.gm.module.WorldTime);
            //transform the  ever up-piling-seconds into a date
            DateTime mydate = new DateTime(t.Ticks);
            //Quickfix to enable saving time (other part of the quick fix can be found in onModuleLoad.cs)
            sf.SetGlobalInt("timePassed", sf.gm.module.WorldTime);

            #endregion

            #region Show time directly on the UI button/clock icon
            // below is for UI button itself
            string text = mydate.ToString(("HH:mm:ss"));
            sf.returnScriptObject = text;
            #endregion

            #region Define custom names for names of weekdays, numbers of days in a month, names of months and names for seasons
            //let's convert the ususal names of weekday, day numbers and months to a little fantasy variation

            //weekdays
            text = mydate.ToString(("dddd"));
            if (text == "Monday" || text == "Montag")
            {
                weekday = "Mondas";
            }
            if (text == "Tuesday" || text == "Dienstag")
            {
                weekday = "Tuedar";
            }
            if (text == "Wednesday" || text == "Mittwoch")
            {
                weekday = "Weddnir";
            }
            if (text == "Thursday" || text == "Donnerstag")
            {
                weekday = "Thurdas";
            }
            if (text == "Fryday" || text == "Freitag")
            {
                weekday = "Friddr";
            }
            if (text == "Saturday" || text == "Samstag")
            {
                weekday = "Saturnir";
            }
            if (text == "Sunday" || text == "Sonntag")
            {
                weekday = "Soldas";
            }

            //daynumbers
            string text2 = mydate.ToString(("dd"));
            if (text2 == "01")
            {
                dayInMonth = "1st";
            }
            if (text2 == "02")
            {
                dayInMonth = "2nd";
            }
            if (text2 == "03")
            {
                dayInMonth = "3rd";
            }
            if (text2 == "04")
            {
                dayInMonth = "4th";
            }
            if (text2 == "05")
            {
                dayInMonth = "5th";
            }
            if (text2 == "06")
            {
                dayInMonth = "6th";
            }
            if (text2 == "07")
            {
                dayInMonth = "7th";
            }
            if (text2 == "08")
            {
                dayInMonth = "8th";
            }
            if (text2 == "09")
            {
                dayInMonth = "9th";
            }
            if (text2 == "10")
            {
                dayInMonth = "10th";
            }
            if (text2 == "11")
            {
                dayInMonth = "11th";
            }
            if (text2 == "12")
            {
                dayInMonth = "12th";
            }
            if (text2 == "13")
            {
                dayInMonth = "13th";
            }
            if (text2 == "14")
            {
                dayInMonth = "14th";
            }
            if (text2 == "15")
            {
                dayInMonth = "15th";
            }
            if (text2 == "16")
            {
                dayInMonth = "16th";
            }
            if (text2 == "17")
            {
                dayInMonth = "17th";
            }
            if (text2 == "18")
            {
                dayInMonth = "18th";
            }
            if (text2 == "19")
            {
                dayInMonth = "19th";
            }
            if (text2 == "20")
            {
                dayInMonth = "20th";
            }
            if (text2 == "21")
            {
                dayInMonth = "21st";
            }
            if (text2 == "22")
            {
                dayInMonth = "22nd";
            }
            if (text2 == "23")
            {
                dayInMonth = "23rd";
            }
            if (text2 == "24")
            {
                dayInMonth = "24th";
            }
            if (text2 == "25")
            {
                dayInMonth = "25th";
            }
            if (text2 == "26")
            {
                dayInMonth = "26th";
            }
            if (text2 == "27")
            {
                dayInMonth = "27th";
            }
            if (text2 == "28")
            {
                dayInMonth = "28th";
            }
            if (text2 == "29")
            {
                dayInMonth = "29th";
            }
            if (text2 == "30")
            {
                dayInMonth = "30th";
            }
            if (text2 == "31")
            {
                dayInMonth = "31st";
            }


            //Months
            text = mydate.ToString(("MM"));
            if (text == "01")
            {
                monthInYear = "Jantur";
                season = "Winter";
            }
            if (text == "02")
            {
                monthInYear = "Februn";
                season = "Winter";
            }
            if (text == "03")
            {
                monthInYear = "Markaras";
                season = "Winter";
            }
            if (text == "04")
            {
                monthInYear = "Aprun";
                season = "Spring";
            }
            if (text == "05")
            {
                monthInYear = "Maiye";
                season = "Spring";
            }
            if (text == "06")
            {
                monthInYear = "Jun";
                season = "Summer";
            }
            if (text == "07")
            {
                monthInYear = "Julnur";
                season = "Summer";
            }
            if (text == "08")
            {
                monthInYear = "Augurun";
                season = "Summer";
            }
            if (text == "09")
            {
                monthInYear = "Septur";
                season = "Summer";
            }
            if (text == "10")
            {
                monthInYear = "Oktoye";
                season = "Autumn";
            }
            if (text == "11")
            {
                monthInYear = "Novaras";
                season = "Autumn";
            }
            if (text == "12")
            {
                monthInYear = "Dezz";
                season = "Winter";
            }
            #endregion

            #region Show customized names on the tooltip UI (for the UI button/clock icon)
            //and now let's display our conversions as tooltip... nice, our journey to a different time and a different place just made a huge step forward :-)
            text = (weekday + ", the " + dayInMonth + " of " + monthInYear + ", in the " + season + " of the year 6" + mydate.ToString(("yy")) + " after Landing");
            sf.frm.toolTip1.SetToolTip(sf.frm.pnlWorldTime, text);
            #endregion

            #region Calculate the time in seconds passed in the different intervalls daily, weekly, four weekly and yearly and store these values in global ints
            int actualSecondsInThisDailyCycle = (int)(t.TotalSeconds % 86400);
            int actualSecondsInThisWeeklyCycle = (int)(t.TotalSeconds % 604800);
            int actualSecondsInThisFourWeeklyCycle = (int)(t.TotalSeconds % 2419200);
            int actualSecondsInThisYearlyCycle = (int)(t.TotalSeconds % 31536000);

            sf.SetGlobalInt("actualSecondsInThisDailyCycleGlobal", actualSecondsInThisDailyCycle);
            sf.SetGlobalInt("actualSecondsInThisWeeklyCycleGlobal", actualSecondsInThisWeeklyCycle);
            sf.SetGlobalInt("actualSecondsInThisFourWeeklyCycleGlobal", actualSecondsInThisFourWeeklyCycle);
            sf.SetGlobalInt("actualSecondsInThisYearlyCycleGlobal", actualSecondsInThisYearlyCycle);
            #endregion
        }
    }
}


and

2. onModuleLoad.cs with second part of the quickfix for saving worldtime
Code: Select all
//onModuleLoad.cs
//note: this script is called automatically by the engine, no scripthook needed
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using IceBlinkCore;
using IceBlink;
using System.Drawing;
using System.IO;

namespace IceBlink
{
    public class IceBlinkScript
    {
        public void Script(ScriptFunctions sf, string p1, string p2, string p3, string p4)
        {
            // C# code goes here

            #region Initialize the DefeatedCreatureList once only at the very beginning of the module (not on every reload)
            //Initialize the DefeatedCreatureList once only at the very beginning of the module
            int SkipInitializingDefeatedCreatureList = 0;

            foreach (GlobalInt variable in sf.gm.module.ModuleGlobalInts)
            {
                if (variable.Key == "DefeatedCreatureListExists")
                {
                   SkipInitializingDefeatedCreatureList = 1;
                }
            }

            if (SkipInitializingDefeatedCreatureList == 0)
            {
            List<Creature> defeatedCreatures = new List<Creature>();
            sf.SetGlobalObject("defeatedCreatureList", defeatedCreatures);
            sf.SetGlobalInt("DefeatedCreatureListExists", 1);
            }
            #endregion

            #region Prevents that snychronization for worldtime-dependent actors takes place on every step in their starting area
            sf.SetGlobalObject("lastArea", "ForceToSnychronizeOnStartAndLoad");
            #endregion

            #region Load background image for clock icon (eventually I will add code to module's onHeartBeat script to hook exchange the image depending on the time of day)
            try
            {
                sf.frm.pnlWorldTime.BackgroundImage = new Bitmap(sf.gm.mainDirectory + "\\modules\\" + sf.gm.module.ModuleFolderName + "\\graphics\\clock.png");
            }
            catch { }
#endregion

            #region Initialize time counters for the different intervalls
            sf.SetGlobalInt("actualSecondsInThisDailyCycleGlobal", 0);
            sf.SetGlobalInt("actualSecondsInThisWeeklyCycleGlobal", 0);
            sf.SetGlobalInt("actualSecondsInThisFourWeeklyCycleGlobal", 0);
            sf.SetGlobalInt("actualSecondsInThisYearlyCycleGlobal", 0);
            #endregion

            #region Quickfix to enable saving time (other part of the quick fix can be found in worldTimeUIText.cs)
            foreach (GlobalInt variable in sf.gm.module.ModuleGlobalInts)
            {
                if (variable.Key == "timePassed")
                {
                    if (variable.Value > 0)
                    {
                        sf.gm.module.WorldTime += variable.Value;
                    }
                }
            }
#endregion
                       
             
        }
    }
}
User avatar
youngneil1
Backer
Backer
 
Posts: 4436
Joined: Sat Dec 08, 2012 7:51 am

Re: Project Living World

Postby youngneil1 » Sun Sep 22, 2013 10:10 am

Looks like the execution order of some calls has changed with my latest IB version, worldTimeUIText.cs is now called before onModuleLoad.cs. Therefore Iahad to amend the quick fix in the worldTimeUIText.cs part a little:

Code: Select all
if (sf.gm.module.WorldTime > 0)
            {
                sf.SetGlobalInt("timePassed", sf.gm.module.WorldTime);
            }
User avatar
youngneil1
Backer
Backer
 
Posts: 4436
Joined: Sat Dec 08, 2012 7:51 am

Re: Project Living World

Postby youngneil1 » Thu Sep 26, 2013 12:11 pm

___

Please go to this thread which has tutorial, documentation and newest version:

viewtopic.php?p=2802#p2802
___
User avatar
youngneil1
Backer
Backer
 
Posts: 4436
Joined: Sat Dec 08, 2012 7:51 am

Previous

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron