Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 04-02-2012, 11:45 AM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default Execute code from string?

I know the code below fails, but can anyone provide a solution to concatonate the eDamage string & execute the randomly selected aircraft.hitNamed(part.NamedDamageTypes. line?

Code:
string[] eDamage = 
        {
            "ElecBatteryFailure",
            "ElecGeneratorFailure",
            "ElecIlluminationFailure",
            "ElecMasterCompassFailure",
            "ElecPrimaryFailure",
            "ElecPriNavigationFailure",
            "ElecSecNavigationFailure",
            "ElecSecondaryFailure",
            "ElecTransceiverFailure",
            "ElecWeaponryFailure"
	    };

            // ---- Electrics failures ----=
            string e = "aircraft.hitNamed(part.NamedDamageTypes." + eDamage[random.Next(eDamage.GetLowerBound(0), eDamage.GetUpperBound(0) + 1)] + ");";
            //Console.WriteLine(e);
            //Process.Start(e);
            // string e conatins the c# code, now how to 'execute' the string as a command?
        }
__________________
When one engine fails on a two engine bomber, you will always have enough power left to get to the scene of the crash.

Get the latest COD Team Fusion patch info HERE

Last edited by salmo; 04-02-2012 at 11:48 AM.
Reply With Quote
  #2  
Old 04-02-2012, 02:29 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Prozess.Start is for starting external programms for example:
Process.Start("http://google.com/search?q= Help me");
would start your browser with a google search for "Help me".

Its not for execute little c# snippets .
Reply With Quote
  #3  
Old 04-02-2012, 02:39 PM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

Quote:
Originally Posted by FG28_Kodiak View Post
Prozess.Start is for starting external programms for example:
Process.Start("http://google.com/search?q= Help me");
would start your browser with a google search for "Help me".

Its not for execute little c# snippets .
Yeah, I know Kodiak. I've seen somewhere on the forums a code snippet demonstrating what I'm looking for, but I can't find it again (damn)
__________________
When one engine fails on a two engine bomber, you will always have enough power left to get to the scene of the crash.

Get the latest COD Team Fusion patch info HERE

Last edited by salmo; 04-02-2012 at 02:43 PM.
Reply With Quote
  #4  
Old 04-02-2012, 03:05 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

These?:
Code:
 private void damageAiControlledPlane(AiActor actorMain)
    {
        foreach (AiActor actor in actorMain.Group().GetItems())
        {
            if (actor == null || !(actor is AiAircraft))
                return;

            AiAircraft aircraft = (actor as AiAircraft);

            if (!isAiControlledPlane(aircraft))
                return;

            if (aircraft == null)
                return;

            aircraft.hitNamed(part.NamedDamageTypes.ControlsElevatorDisabled);
            aircraft.hitNamed(part.NamedDamageTypes.ControlsAileronsDisabled);
            aircraft.hitNamed(part.NamedDamageTypes.ControlsRudderDisabled);
            aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFailure);

            int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
            for (int i = 0; i < iNumOfEngines; i++)
            {
                aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
            }


            Timeout(300, () =>
            { destroyPlane(aircraft); }
                );
        }
    }
Reply With Quote
  #5  
Old 04-04-2012, 01:53 AM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

I think you might have to list the items in a list then random select an item(line by number) to use. This may however have a parse problem where you are transfering built in code to string types(listing) and back again.(am I sick of parsing problems yes I am)

might have some syntax errors in the following, but something like, (yes this came from Kodiak )


Code:
List<Damage> DamageList = new List<Damage>
{
    new Damage ("ElecBatteryFailure"),
    new Damage ("ElecGeneratorFailure")
// add each damage type(note add comma on preceeding line)

};

    internal class Damage 
   {
        public string EDamageType { get; set; }
        public Damage(string eDamageType)
       {
            this.EDamageType = eDamageType;
       }
   }


//random selection
Random rand = new Random();          

int i = 0;
if (DamageList.Count > 0)
i = rand.Next(0, DamageList.Count);
aircraft.hitNamed(part.NamedDamageTypes.DamageList[i].EDamageType);
});

Last edited by Smokeynz; 04-04-2012 at 02:29 AM.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:40 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.