Official Fulqrum Publishing forum

Official Fulqrum Publishing forum (http://forum.fulqrumpublishing.com/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.fulqrumpublishing.com/forumdisplay.php?f=203)
-   -   Script assistance needed (http://forum.fulqrumpublishing.com/showthread.php?t=26036)

Ataros 09-24-2011 08:32 AM

Quote:

Originally Posted by Mington (Post 340221)

How can I detect that a damaged plane in an RTB-ing four-flight is inbound to the airfield to possibly make a crash landing?

Detect the plane passing some distance-radius from the runway let's focus on that

Here is list of methods published here before which are quite self-explanatory (more methods were added in recent beta patch)

Code:

  protected AMission ()
 public virtual void Init (maddox.game.ABattle battle, int missionNumber)
 public virtual void Inited ()
 public virtual bool IsMissionListener (int missionNumber)
 public virtual void OnActorCreated (int missionNumber, string shortName, maddox.game.world.AiActor actor)
 public virtual void OnActorDamaged (int missionNumber, string shortName, maddox.game.world.AiActor actor, maddox.game.world.AiDamageInitiator initiator, part.NamedDamageTypes damageType)
 public virtual void OnActorDead (int missionNumber, string shortName, maddox.game.world.AiActor actor, System.Collections.Generic.List <DamagerScore> damages)
 public virtual void OnActorDestroyed (int missionNumber, string shortName, maddox.game.world.AiActor actor)
 public virtual void OnActorTaskCompleted (int missionNumber, string shortName, maddox.game.world.AiActor actor)
 public virtual void OnAiAirNewEnemy (maddox.game.world.AiAirEnemyElement element, int army)
 public virtual void OnAircraftCrashLanded (int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft)
 public virtual void OnAircraftCutLimb (int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft, maddox.game.world.AiDamageInitiator initiator, part.LimbNames limbName)
 public virtual void OnAircraftDamaged (int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft, maddox.game.world.AiDamageInitiator initiator, part.NamedDamageTypes damageType)
 public virtual void OnAircraftKilled (int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft)
 public virtual void OnAircraftLanded (int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft)
 public virtual void OnAircraftLimbDamaged (int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft, maddox.game.world.AiLimbDamage limbDamage)
 public virtual void OnAircraftTookOff (int missionNumber, string shortName, maddox.game.world.AiAircraft aircraft)
 public virtual void OnAutopilotOff (maddox.game.world.AiActor actor, int placeIndex)
 public virtual void OnAutopilotOn (maddox.game.world.AiActor actor, int placeIndex)
 public virtual void OnBattleInit ()
 public virtual void OnBattleStarted ()
 public virtual void OnBattleStoped ()
 public virtual void OnCarter (maddox.game.world.AiActor actor, int placeIndex)
 public virtual void OnMissionLoaded (int missionNumber)
 public virtual void OnPersonHealth (maddox.game.world.AiPerson person, maddox.game.world.AiDamageInitiator initiator, float deltaHealth)
 public virtual void OnPersonMoved (maddox.game.world.AiPerson person, maddox.game.world.AiActor fromCart, int fromPlaceIndex)
 public virtual void OnPersonParachuteFailed (maddox.game.world.AiPerson person)
 public virtual void OnPersonParachuteLanded (maddox.game.world.AiPerson person)
 public virtual void OnPlaceEnter (maddox.game.Player player, maddox.game.world.AiActor actor, int placeIndex)
 public virtual void OnPlaceLeave (maddox.game.Player player, maddox.game.world.AiActor actor, int placeIndex)
 public virtual void OnPlayerArmy (maddox.game.Player player, int army)
 public virtual void OnPlayerConnected (maddox.game.Player player)
 public virtual void OnPlayerDisconnected (maddox.game.Player player, string diagnostic)
 public virtual void OnSingleBattleSuccess (bool success)
 public virtual void OnTickGame ()
 public virtual void OnTickReal ()
 public virtual void OnTrigger (int missionNumber, string shortName, bool active)
 public virtual void Timeout (double sec, maddox.game.DoTimeout doTimeout)

 public maddox.game.ABattle Battle {get;}
 public maddox.game.IGamePlay GamePlay {get;}
 public int MissionNumber {get;}
 public int MissionNumberListener {set; get;}
 public maddox.game.world.ITime Time {get;}

Not being a C# expert but just having read 80% of samples posted here I guess you can use OnAircraftDamaged and OnAircraftLimbDamaged and OnAircraftCutLimb to start calculating distance from the damaged aircraft to the closest airfield. Then you can generate a new landing waypoint for the damaged group at this airfield. There is a "distance" function used in naryv examples and in vetochka campaign. Waypoint generation is also used in naryv examples. When the distance is appropriate you let an ambulance to start its way to a runway.

Another way is to use onTrigger method with really big trigger radius around an airfield and check what aircraft parts are damaged. There was a sample script posted in the main section that prints out damaged parts to a chat window. Therefore I guess it is possible to do this.

The 3rd alternative could be to combine both of the above ways and flag a damaged group OnAircraftDamaged and then onTrigger check if the incoming group is flagged as damaged. Again I do not know C# and can be wrong. It is better to start a new thread with these particular questions where real experts will offer their solutions.

hc_wolf combined several naryv examples and others' scripts into one mission. You can have a look at how he did this and do the same if you know C#. If no one can answer questions on this forums you can ask naryv directly as adonys did in this thread http://www.sukhoi.ru/forum/showthrea...=1#post1647624
Sometimes naryv does not answer if the functionality requested is not ready yet or does not work properly or is changing at the moment. All script methods are WIP I think ATM.

We will not see the manual till engine functionality and script methods are 90% finalized imho because there is no point to spend time on a manual that will not be valid in 2 months. I expect it to come with Battle for Moscow at the earliest. But again if you know C# you can find all necessary information on this forums in naryv, adonys, Kodiak, Wolf, TheEnlightenedFlorist, vetochka, stillborn, etc. examples.

Scripting discussion was started 5 months ago in this thread (Yes, I know it is hard for the first 6-8 weeks till you learn some basics :) ) http://forum.1cpublishing.eu/showthread.php?t=21518
Many of my noob's questions were answered there by С# programmers. Again this forum section has more then enough information to start programming for CloD if you know C# basics at least. Guys and a lady mentioned above have proved it many times already. This forum section is only 9 pages long not too much to look though to get all the information needed to be able do the same imho.

ps. Of cause I would be more than happy if Kodiak or other C# programmers agree to publish some tutorials but for me it is not clear if the tutorials should be about C# basics or about CloD methods and functions.

klem 09-24-2011 09:12 AM

Quote:

Originally Posted by Blackdog_kt (Post 340143)
Ataros is right on the money.

C# is a programming language that many people use to earn a living, it's not a gaming tool. There's no way around it, until someone codes a graphical front-end for the most basic stuff(and even that would be limited to the most commonly used functions) it's going to take investment of personal time and learning how to code to do things.

Blackdog_kt, I think Ming's post that follows yours sums it up quite well.

I am familiar with the basic principles of coding even though it is from years of Visual Basic and VBS not C#.

We can see from the .cs files that they are fundamentally modular leading to the possibility of module examples in response to requests and other examples simply posted by people who have already developed them. Yes, that calls for the patience and good will of the knowledgeable guys who would essentially be filling a void left in the game application. What I had hoped for was a bank of these modules with a basic very brief explanation of their purpose so that we could interpret, learn to understand and use. Studying existing modules is one way but is long and laborious as you first have find one that may contain what you want, understand what the script module is trying to do and you still may not find what you are looking for.

There are many methods and objects etc created in the Maddox game that are unknown to many of us. Some are confusing such as 'Actor' meaning Aircraft (as far as I can make out) not 'Player'. Some of our 1C friends know these and are in a position to help and advise. I spent a lot of time in my career teaching people various subjects at various levels from electronic maintenance to business management. One of the dangers of those doing the teaching, or presenting examples/guides, is that they see things from 'the inside looking out' instead of where their pupils are, 'on the outside looking in' and often into a dark black box of a world they just don't know about yet. We tend to assume that if we are familiar with a concept or a detail which is so basic to us, we take it for granted that our 'pupils' will already have that knowledge. So jargon, assumed knowledge etc lead to a gulf between what is being presented and what is being received. Some my my maintenance pupils didn't need to be electronics experts to understand and fault find modular equipment on an oil rig in the middle of the Gulf, they just needed to know how to piece information and blocks together to fix and get something working. We don't all need to be top-level C# programmers for CoD, we do need to understand basic principles (which can be read up or learned) and then have the support of those around us on the Maddox game-specific aspects and how they are used.

My hope was to open up the Maddox coding world to semi-laymen like myself. It may not reach all players but I think it would open up mission coding for quite a few.

Of course I could study C# in great depth, then find and study all the aspects of the Maddox game but frankly I'm not willing to spend that much time on it. If the FMB didn't give us a graphical means of creating very basic missions I wouldn't be bothering with making them as I'd no doubt have to study even more. Its not that I want an easy path, just an easier path than we have at the moment. No, wait, I do want an easy path, I didn't buy this game to have to study programming in order to use it! I wonder what level the SDK will be pitched at, whether there will be graphical interfaces and whether it will be for maps, for aircraft or even mission building. Lets face it, these things will fall on a very few shoulders if its all bare coding and will deny the rest of us those opportunities which I see as a fundamental part of what I have bought.

Anyway, a 1C-forum coding library isn't going to happen. Getting people to agree on a single solution is harder than learning C#. I guess I am just over-optimistic, after all if I wasn't I'd have dumped CoD and followed the majority of my Squadmates who have given up on CoD and bogged off into RoF.

Ataros 09-24-2011 09:36 AM

Quote:

Originally Posted by klem (Post 340334)
What I had hoped for was a bank of these modules with a basic very brief explanation of their purpose so that we could interpret, learn to understand and use. Studying existing modules is one way but is long and laborious as you first have find one that may contain what you want, understand what the script module is trying to do and you still may not find what you are looking for.

I was as frustrated as you are when I tried to make a mission for Repka #1 back in April. It was even worse because there were no examples available.

Now there are plenty of examples and missions posted in this section. Of cause it is not easy to find them if you did not follow the discussion from April. It takes time, weeks and months, to learn something new.

If you tell what modules you would like to use in your mission I will try to tell you in which threads/examples they are available.

It is better to start a new thread for each new module you need. Kodiak and other people knowing C# are very helpful and helped me a lot even back in April not having any manual (they just looked up lists of methods, etc. from .dll files in Visual Studio):
Quote:

Visual Studio will let you see all of the methods in roundabout way. Try this:

1. File >> New >> Project Type in a name and solution name at the bottom. Don't worry about what kind of project you create.

2. On the right side under "Solution Explorer", right click on "References", "Add Reference..."

3. Click on the "Browse" tab, navigate to "Steam/steamapps/common/il-2 sturmovik cliffs of dover/parts/core"

4. Go through each .dll file in that list and try to add it. Some will give you an error, just skip those.

After you've added all the .dll files, right click on the name of your project and do "Add Existing Item". Find one of your script files and add it. Now Visual Studio will show you all the possible methods as you're typing your code. You can also go to View >> Object Browser and have a look in there.

Important: When you import an existing item, Visual Studio makes a copy of the file so any changes you make won't be reflected in the original file, you'll have to copy the new one over it. If anybody knows how to change this, I'd be quite grateful.
Sorry, do not remember who posted this :( This shows that for people who know C# it is really easy to learn everything needed from game dll-s themselves.

Ataros 09-24-2011 09:59 AM

1 Attachment(s)
Please find my script library attached. It includes script collections from this forum section sorted by topic as well as some mission examples.

Please feel free to ask questions on particular scripts but it is better to start new threads for each topic.

Not all scripts are working and 100% correct. I am not a C# expert and will not be able to answer all questions but others who helped me with writing scripts will help I am sure.

Mington 09-24-2011 11:42 AM

Lovely to see things looking up :)

How to construct an AirfieldEmergency script from first principles while explaining the steps, that's what I'd like to see. A concrete example with commentary that's fairly simple (if the detecting of the damaged plane crossing the AlarmRadius can be done)

There's almost 800 references to Maddox functions, classes, methods and wotnot so I'm imagining that it's on

There's the introductory part to a script, where databases of functions, subroutines (BASIC/Visual Basic) we will need access to in the running script, these might be-

using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;

The script then begins and it's at this point that we pupils need statements commented please. We can figure out what each line of code means but it's like examining atoms without knowing about the Table of Elements. We can see that they're all different and they all must mean something, there must be some rhyme to it, we are not idiots :)

'We need this line to see if any planes are already in the mission' (the mission designer created an unknown number of planes)

'We need this line to step through each plane to see if it is damaged' (all planes in all running missions can be checked)

'This line instantiates/spawns a plane/vehicle at this XYZ position' (if the position is clear)

This scripter's commentary gives us a chance to ask the scriptwriter a sensible question... it's very difficult to ask sensible questions without a handle to hang the question on. For example how can you tell if a possible spawning position is clear of obstructions. But that's another story probably :)

Ming

Mington 09-24-2011 12:07 PM

Wow thanks very much for your collection Ataros!

It is better to start a new thread for each new module you need

Wiil do, thanks

they just looked [FMB stuff] up

Kodiak works/worked for Maddox perhaps - this is a compliment btw. He/she definitely knows his stuff. Let's face it somebody has to :)

onTrigger method with really big trigger radius around an airfield

A trigger radius hmm - thanks :) (I'll see if I can trigger a message 'We see your plane incoming, it looks damaged...' to 'Crossed the airfield EmergencyAlertRadius')

Thinking out loud then- two airfields say Croydon and Biggin Hill and my single plane taking off at one airfield. Testing the other airfield's EmergencyAlert (procedure) - with a simple onscreen message if my plane trips the second airfield's trigger. Baby steps.

Adding the trigger in a script rather than via the FMB, to make it universal. Does the FMB write trigger code into the dot cs I wonder. I know that airfields have one radius and then another radius

Ming

Ataros 09-24-2011 12:24 PM

Quote:

Originally Posted by Mington (Post 340399)

Adding the trigger in a script rather than via the FMB, to make it universal. Does the FMB write trigger code into the dot cs I wonder. I know that airfields have one radius and then another radius

Trigger has its own radius. It is set in FMB and is stored in a mission file, not in script file.

According to the devs to make FMB triggers work together with any script you can add this code to script. Action and trigger must have the same name in this case.
Code:


public override void OnTrigger(int missionNumber, string shortName, bool active)
    {
        base.OnTrigger(missionNumber, shortName, active);       
        AiAction action = GamePlay.gpGetAction(ActorName.Full(missionNumber, shortName));
        if (action != null)
            action.Do();
    }

There are other more advanced and complex possibilities. Check out the _Triggers and actions folder in my archive or search forums for trigger script.

ps. BTW are you one of simhq admins by chance? I have trouble registering at simhq forums somehow. Same nickname.

Mington 09-25-2011 11:39 AM

Very nice thanks Ataros!

Trigger has its own radius. It is set in FMB and is stored in a mission file, not in script file

I am trying to think universally, where scripts are independent of missions, so setting the radius in the FMB (while working perfectly yes) is not what I'm after

An airfield built by construction engineers (looking forward to D-Day) would not have a radius but it would be an Airfield object and a script could (hopefully) read and return the AirfieldEmergency distance. That could be a constant couple of miles perhaps and would apply to all airfields, permanent or temporary. We often create small airfields fairly close together for multiplayer dogfights - created in Il-2 I mean

Thanks for that info mate, no I'm not an admin over there but I will advise admin Dart that you're having problems and get back to you

Ming

Ataros 09-25-2011 08:51 PM

In this example naryv creates a mission file by script. http://forum.1cpublishing.eu/showthread.php?t=23493

The file is called triggersFile. Actually it is a "section" file, i.e. a segment of a mission file.
Code:

    public ISectionFile triggersFile
Then script writes triggers into this file at the locations of frontline markers placed in the original mission manually.

Code:

                    keyTr = "changeArmy" + i.ToString()+"_1";                                // попутно на маркере делаем два триггера - для каждой стороны 
                    valueTr = " TPassThrough 3 1 " + strs[0] + " " + strs[1] + " 500";      // "TPassThrough 3" - триггер сработает при заезде в него наземки, "1" красной, strs[0] + " " + strs[1] координаты, "500"- радиус триггера
                    triggersFile.add(sectionTr, keyTr, valueTr);                            // сохраняем триггер в файле триггерной миссии
                    keyTr = "changeArmy" + i.ToString() + "_2";                              // то же самое для синей стороны
                    valueTr = " TPassThrough 3 2 " + strs[0] + " " + strs[1] + " 500";     
                    triggersFile.add(sectionTr, keyTr, valueTr);                            // сохраняем триггер в файле триггерной миссии

500 - is radius of the trigger

Mington 09-26-2011 12:00 PM

Thanks Ataros, hugely interesting

The clue that 500 is the radius no wait it's a radius- is that an airfield radius I wonder?

There are two radii for each airfield

This is a command to assemble a string, can you decode the string please? Something like-

TPassThrough

Ahah :) pass through, passes through, crosses a radius...

Decoding, building a string-

TPassThrough 3 1

strs[0] (red or blue maybe, 'red' from Babelfish)

strs[1] appears to be a 'coordinate' from Babelfish

-it gets quite complicated eg-

double y; double.TryParse( strs[1], out y);

500

Maybe the whole assembled string is a coordinate somewhere on the map, with a radius around the coordinate of 500m

Yes that sounds reasonable, if we can now work out a test value for the cryptic strs[1]

valueTr = " TPassThrough 3 1 " + strs[0] + " " + strs[1] + " 500";

Maybe the TPassThrough trigger is documented somewhere, I'll see what I can find, the mysterious (without C# string-operation knowledge) coordinate bit is interesting

'TPassThrough: gets active' - does this mean that some Boolean variable is set to True or False? How to link to the emergency ambulance method I wonder, If NoBellsAreRinging CarryOn = True :)

Working left for inspection :)

Ming

Quote:

TPassThrough: gets active after a GroundGroup or Airgroup or Player entering the Area
http://forum.1cpublishing.eu/showthr...413#post339413


All times are GMT. The time now is 01:23 AM.

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