Results 1 to 5 of 5

Thread: Script headache

  1. #1
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Script headache

    I'n in the process of stopping the pass though spawn triger/actions from firing more than once and can do that, except I don't understand how to let any that I don't want to limit, fire multiple times

    My current script looks like as attached but I get an error message when I try to compile it. If I remove the last Ai Action ....... return; then I do get the HUD message firing as I enter and leav ethe trigger area, and repeatedly. My trigger1 works fine, firing once only.

    The compile error I see is 'A local variable named action cannot be declared in this scope because it would give a different meaning to Action which is already used in child scope to denote something else.'

    Can anyone hlep please?
    Attached Images Attached Images
    I am Yo-Yo not YoYo (that's someone else)

  2. #2
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script headache

    You are declaring two AIAction objects with the same name. Change the name of one of them.

  3. Likes Yo-Yo liked this post
  4. #3
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Script headache

    Ah, I see. thanks, will give it a try.
    I am Yo-Yo not YoYo (that's someone else)

  5. #4
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Script headache

    Thanks I got it working by changing it, massive head ache cleared. Thanks.

    I have one more quesiton on this though if I could please?

    I've got my trigger 1 limited nicely, and, all others are firing repeatedly, but they are also firing as I enter and leave their trigger area. Is it possible to have it so the action occurs just once for each in & out, but that will then repeat the process when going back in?
    I am Yo-Yo not YoYo (that's someone else)

  6. #5
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Script headache

    You-Yo

    this script are from one of Piper-Kiev campaigns, that use a template made by someone (I think Geniok) early in CloD history.

    What have different is, if mission is successfully, player receive a bonus in points, and this points is updated in a file (Score.dat) in Documents a is show in the next mission briefing (BriefingParser parser), so give the player an idea of heir performance.

    private static string mydocpath = Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments);
    private static string FILE_NAME = mydocpath + @"\1C SoftClub\il-2 sturmovik cliffs of dover\mission\campaign\campaign_KG.53.Legion_Kondo r\Score.data";
    Code:
    Данный файл является частью кампании "campaign_KG.53.Legion_Kondor".
    Автор: Вихарев Евгений aka Geniok.
    Дата: 06.01.2012
    */
    
    
    //$reference Campaign.dll
    //-$debug
    
    using System;
    using System.IO;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class BriefingParser
    {
        private struct SectionPair
        {
            public String Section;
            public String Title;
            public String Key;
        }
    
        private Dictionary<SectionPair, string> keyPairs = new Dictionary<SectionPair, string>();
        private String briefingFilePath;
    
        public BriefingParser(String briefingPath)
        {
            TextReader briefingFile = null;
            String strLine = null;
            String currentRoot = null;
            String currentTitle = null;
            String[] keyPair = null;
    
            briefingFilePath = briefingPath;
    
            try
            {
                briefingFile = new StreamReader(briefingPath);
    
                strLine = briefingFile.ReadLine();
    
                while (strLine != null)
                {
                    if (strLine != "")
                    {
                        if (strLine.StartsWith("[") && strLine.EndsWith("]"))
                        {
                            currentRoot = strLine.Substring(1, strLine.Length - 2);
                        }
                        else if (strLine.StartsWith("<") && strLine.EndsWith(">"))
                        {
                            currentTitle = strLine.Substring(1, strLine.Length - 2);
                        }
                        else
                        {
                            keyPair = strLine.Split(new char[] { '=' }, 2);
    
                            SectionPair sectionPair;
                            String value = null;
    
                            if (currentRoot == null)
                            {
                                currentRoot = "[1]";
                            }
                            if (currentTitle == null)
                            {
                                currentTitle = "<Name>";
                            }
    
                            sectionPair.Section = currentRoot;
                            sectionPair.Title = currentTitle;
                            sectionPair.Key = keyPair[0];
    
                            if (keyPair.Length > 1)
                            {
                                value = keyPair[1];
                            }
    
                            keyPairs.Add(sectionPair, value);
                        }
                    }
                    strLine = briefingFile.ReadLine();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (briefingFile != null)
                {
                    briefingFile.Close();
                }
            }
        }
    
        public void AddSetting(String sectionName, String titleName, String settingName, String settingValue)
        {
            SectionPair sectionPair;
            sectionPair.Section = sectionName;
            sectionPair.Title = titleName;
            sectionPair.Key = settingName;
    
            if (keyPairs.ContainsKey(sectionPair))
            {
                keyPairs.Remove(sectionPair);
            }
    
            keyPairs.Add(sectionPair, settingValue);
    
            SaveSettings();
        }
    
        public void AddSetting(String sectionName, String titleName, String settingName)
        {
            AddSetting(sectionName, titleName, settingName, null);
        }
    
        private void SaveSettings()
        {
            ArrayList sections = new ArrayList();
            ArrayList titles = new ArrayList();
            String tmpValue = "";
            String strToSave = "";
    
            foreach (SectionPair sectionPair in keyPairs.Keys)
            {
                if (!sections.Contains(sectionPair.Section))
                {
                    sections.Add(sectionPair.Section);
                }
                if (!titles.Contains(sectionPair.Title))
                {
                    titles.Add(sectionPair.Title);
                }
            }
    
            foreach (String section in sections)
            {
                strToSave += ("[" + section + "]\r\n");
    
                foreach (String title in titles)
                {
                    strToSave += ("<" + title + ">\r\n");
    
                    foreach (SectionPair sectionPair in keyPairs.Keys)
                    {
                        if (sectionPair.Section == section)
                        {
                            if (sectionPair.Title == title)
                            {
                                tmpValue = (String)keyPairs[sectionPair];
    
                                strToSave += (sectionPair.Key + tmpValue + "\r\n");
                            }
                        }
                    }
                }
                strToSave += "\r\n";
            }
    
            try
            {
                TextWriter tw = new StreamWriter(briefingFilePath);
                tw.Write(strToSave);
                tw.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
    
    public class Mission : maddox.game.campaign.Mission
    {
        AiActor a1 = null;
        AiAircraft airc1 = null;
        int countPlayerWins = 0;
        int countDead = 0;
        bool isComplete = false;
        int score = 0;
    
        private static string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        private static string FILE_NAME = mydocpath + @"\1C SoftClub\il-2 sturmovik cliffs of dover\mission\campaign\campaign_KG.53.Legion_Kondor\Score.data";
    
        private static void writeScore(int scr)
        {
            using (FileStream fs = new FileStream(FILE_NAME, FileMode.Create))
            {
                using (BinaryWriter w = new BinaryWriter(fs))
                {
                    w.Write(scr);
                }
            }
        }
    
        private static int readScore()
        {
            using (FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader r = new BinaryReader(fs))
                {
                    return (r.ReadInt32());
                }
            }
        }
    
        private void serverMessage(string msg)
        {
            Player pl = GamePlay.gpPlayer();
            Player[] players = { pl };
            object[] args = { msg };
            GamePlay.gpLogServer(players, msg, args);
        }
    
        private void HUDMessgeTo(string message)
        {
            Player pl = GamePlay.gpPlayer();
            String namePlayer = pl.Name();
            GamePlay.gpHUDLogCenter(namePlayer + ": " + message);
        }
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
        }
    
        private void checkLanded(AiAircraft aircraft)
        {
            if (GamePlay.gpPlayer().Place() == aircraft)
            {
                Campaign.battleSuccess = true;
    
                isComplete = true;
                score += 100;
    
                HUDMessgeTo("Герр Лейтенант вы выполнили основное задание!");
                Timeout(10.0, () =>
                {
                    GamePlay.gpHUDLogCenter("Для выхода из миссии нажмите ESC!");
                });
            }
        }
    
        public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
        {
            checkLanded(aircraft);
        }
    
        public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
        {
            checkLanded(aircraft);
        }
    
        public override void OnBattleStoped()
        {
            base.OnBattleStoped();
    
            if (isComplete)
            {
                writeScore(score);
    
                BriefingParser parser = new BriefingParser(@"..\il-2 sturmovik cliffs of dover\parts\bob\mission\campaign\campaign_KG.53.Legion_Kondor\KG53_02.BRIEFING");
                parser.AddSetting("2", "Description", "Ваши очки:", readScore().ToString());
            }
        }
    }
    The bad news is, after some patches this scrip stop to work.

  7. Likes danperin liked this post

Bookmarks

Posting Permissions

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