#3385237 - 09/08/11 03:47 AM
New API in the Beta
|
Joined: Jan 2009
Posts: 4,737
FearlessFrog
Senior Member
|
Senior Member
Joined: Jan 2009
Posts: 4,737
|
I saw here http://forum.1cpublishing.eu/showthread.php?p=332906 that there's some new toys to play with in terms of scripting in the beta (I really need to learn Russian, is there a manual?) so I thought I'd have a go. This is a very small script that allows you to damage bits of your aircraft plus view the damage you cause to other aircraft using a new extendable in-game menu system. This is FOR THE BETA VERSION ONLY and I've put some random thing under a new Mission menu, really just to try it out. Hopefully more sensible people will come along and do good with it, i.e. perhaps order a fuel truck once you've landed or perhaps re-arm during a MP battle. There are lots of possibilities now and it's not too tricky. Here's a screen-shot of the new menu things: You can either download this very dull mission or copy the following text into your 'Script' window in the Full Mission Builder and make a better mission yourself. It should work with any existing missions you have too. http://www.megaupload.com/?d=VL8RYN4BA useful reference is this post that deals with how to damage yourself using scripting: http://simhq.com/forum/ubbthreads.php/topics/3361279/Re_Incredible_Detail.htmlHere's the ugly script (apologies to any developers out there, bit of a rush): using System; using System.Collections; using maddox.game; using maddox.game.world;
//GamePlay.gpHUDLogCenter("Pressed: " + menuItemIndex);
public class Mission : AMission { bool dmgOn = false;
private void setMainMenu( Player player ) { GamePlay.gpSetOrderMissionMenu( player, false, 0, new string[] { "Damage & Diagnostics" }, new bool[] { true } ); }
private void setSubMenu( Player player ) { GamePlay.gpSetOrderMissionMenu( player, true, 1, new string[] { "Destroy Wings", "Destroy Engine", "Destroy Guns", "Report Damage On", "Report Damage Off"}, new bool[] { false, false, false, false, false } ); }
public override void OnOrderMissionMenuSelected( Player player, int ID, int menuItemIndex ) { if( ID == 0 ) { // main menu if( menuItemIndex == 1 ) { setSubMenu( player ); } } else if( ID == 1 ) { // sub menu if (menuItemIndex == 1) { Player[] all = { player };
AiActor where = player.Place(); AiAircraft aircraft = (GamePlay.gpPlayer().Place() as AiAircraft); GamePlay.gpLogServer(all, "POW!!", null); aircraft.cutLimb(part.LimbNames.WingR2); setMainMenu( player ); } else if (menuItemIndex == 2) { Player[] all = { player };
AiActor where = player.Place(); AiAircraft aircraft = (GamePlay.gpPlayer().Place() as AiAircraft); GamePlay.gpLogServer(all, "POW!!", null); aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalFailure); setMainMenu( player ); } else if (menuItemIndex == 3) { Player[] all = { player };
AiActor where = player.Place(); AiAircraft aircraft = (GamePlay.gpPlayer().Place() as AiAircraft); GamePlay.gpLogServer(all, "POW!!", null); aircraft.hitNamed(part.NamedDamageTypes.Machinegun00Failure); aircraft.hitNamed(part.NamedDamageTypes.Machinegun01Failure); aircraft.hitNamed(part.NamedDamageTypes.Machinegun02Failure); setMainMenu( player ); } else if (menuItemIndex == 4) { dmgOn = true; GamePlay.gpHUDLogCenter("Will show damage on all aircraft"); setMainMenu( player ); } else if (menuItemIndex == 5) { dmgOn = false; GamePlay.gpHUDLogCenter("Will not show damage on all aircraft"); setMainMenu( player ); } } }
public override void OnPlayerConnected( Player player ) { if( MissionNumber == 0 ) { setMainMenu( player ); } }
public override void Inited() { if( MissionNumber == 0 ) { setMainMenu(GamePlay.gpPlayer()); } }
public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft Aircraft, AiDamageInitiator DamageFrom, part.NamedDamageTypes WhatDamaged) { base.OnAircraftDamaged(missionNumber, shortName, Aircraft, DamageFrom, WhatDamaged); if (DamageFrom.Player != null ) { if (dmgOn == true) { GamePlay.gpLogServer (null, "{0} hits {1} : {2} \n", new object [] {DamageFrom.Player, shortName, WhatDamaged}); } } }
}
Last edited by FearlessFrog; 09/08/11 04:37 AM. Reason: Made an error in the wing falling off bit - fixed
|
|
#3385382 - 09/08/11 10:34 AM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Sep 2004
Posts: 10,618
Ming_EAF19
Babelfish Immune
|
Babelfish Immune
Veteran
Joined: Sep 2004
Posts: 10,618
London
|
order a fuel truck once you've landed Is there a list of FMB scripting commands, variables, constants and so on posted anywhere please? For example is dmgOn an internal variable and what's a fuel truck's label I'm imagining something like- Check for damaged aircraft inbound within 1km (I think scripts run in polling mode)(which must slow things down) Get the plane's ID, check for pilot's rank Display 'It's the squadron leader- he's in trouble!' message, SeekBrandy(double) Else GetTheKettleOn(muffins) If it appears to be landing get a fire engine warmed up, set a bell and a flare off If it's definitely landing send the fire engine to meet the damaged aircraft MeetAndGreet(foam) Ming
'You are either a hater or you are not' Roman Halter
|
|
#3385386 - 09/08/11 10:43 AM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Sep 2004
Posts: 10,618
Ming_EAF19
Babelfish Immune
|
Babelfish Immune
Veteran
Joined: Sep 2004
Posts: 10,618
London
|
Thats not script it's C# codeYes and it appears that RoF has a rival in the interesting department. RoF has (among other juiciness) that fabulous mission editor with the 3D viewport, quite a breakthrough CoD has hooks into C# from within a mission and labels are planes and boats and er, quite possibly trains And now with a feathered coastline- we don't know we're born Ming
'You are either a hater or you are not' Roman Halter
|
|
#3385608 - 09/08/11 05:23 PM
Re: New API in the Beta
[Re: Ming_EAF19]
|
Joined: Feb 2005
Posts: 330
steeldelete
Member
|
Member
Joined: Feb 2005
Posts: 330
Switzerland
|
[b] And now with a feathered coastline- we don't know we're born Ming Ha!At least there is something minglish about this. Welcome back! Not that I understand anything about the rest. This seems a lot too much for me. I guess in a few years time all will be more clear.
cogito, ergo zoom
|
|
#3385640 - 09/08/11 06:23 PM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Sep 2004
Posts: 10,618
Ming_EAF19
Babelfish Immune
|
Babelfish Immune
Veteran
Joined: Sep 2004
Posts: 10,618
London
|
too muchNot at all, but it's unfamiliar right now as we have no manual (that I'm aware of) so it looks all-Greek with Latin extensions OnAircraftDamaged(int missionNumber, string shortName, AiAircraft Aircraft, AiDamageInitiator DamageFrom, part.NamedDamageTypes WhatDamaged) This is a piece of code with some parameters that we can work out missionNumber is an integer (whole number) variable (one that can be changed by the programmer), maybe it's mission 2 we are looking at shortName is the label given to a group of keyboard characters, maybe FearlessFrogsFirebell I say a 'group of keyboard characters' because it took me a while back in the 24 hour cycle to work out what a 'string' may be, it seemed to be an annoying obfuscation as string already had a meaning. But not a length yes. On the other hand it helped with vocabulary. It's just meaning some letters and numbers strung together in a string of (keyboard-type, some label one types in) characters... part.NamedDamageTypes is interesting because it looks like object-oriented programming. Which is when I woke up Check for an aircraft within the airfield's AlertRadius Is it damaged? If it is damaged then send out the fire engine If NotDamaged go to the next plane within the radius until you've checked the whole radius area for potential fireballs-in-the-making And then later in the checking-loop- if the landing-damaged plane is now landed and not on fire, return the fire engine to its parking-place Scripts loop around automatically (apparently, if I'm understanding things correctly) while the mission is running so the code looks to be a simple task given a few tips and the FMB localised manual Ming
'You are either a hater or you are not' Roman Halter
|
|
#3385652 - 09/08/11 06:36 PM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Jan 2009
Posts: 4,737
FearlessFrog
Senior Member
|
Senior Member
Joined: Jan 2009
Posts: 4,737
|
You are on exactly the right track Ming. dmgOn was a 'boolean' (an on / off) that I set up to remember what was pressed in the menu before displaying the aircraft damage messages. I think a Fire Truck would be something like this: - In the FMB set up a trigger area put around and airport (the Fire Truck's operating remit, union rules despite wartime) or listen in on the OnAircraftLanded (or perhaps more pertinently) the OnAircraftCrashLanded event. - When something has crashed and is in the range of the Fire Truck then assign the truck to a movement path directly to your location. A few of the campaign missions have good example of ground units moving now, plus it might be something that could be defined in the FMB as a series of points and then just triggered in code? - When Fireman Sam is on station then run an animation or change the state of the aircraft. Until we get docs via a SDK then it's all cave diving / spelunking at the moment. .NET is handy as you can examine all the various API's but that just gives you the parameters of the calls and not really the intent (plus although they are generally excellent, these are English API's written by Russians, so just guessing by name is very trial and error). Here's a good collection of things found by reverse-engineering so far: http://forum.1cpublishing.eu/showthread.php?t=23959
|
|
#3385854 - 09/08/11 11:19 PM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Sep 2004
Posts: 10,618
Ming_EAF19
Babelfish Immune
|
Babelfish Immune
Veteran
Joined: Sep 2004
Posts: 10,618
London
|
In the cave of Socrates then, with the shadow puppets Kodiak over there is another marvel like yourself Frog and he/she's posted up info on the freebie Microsoft Visual C# 2010 Express software. I strongly suggest that everyone has a play with that - to see what they've been working on for all those years, they are visionaries: but without communicating much about their complex-coding campaign ideas unfortunately. I still think Napoleon deserves a few points for having a go at Moscow in the winter <g> In a main dll I've found four what shall we call them routines that we could use to get small code-stubs working... easy to test if things are working maddox.game.AMission.OnAircraftCrashLanded(int, string, maddox.game.world.AiAircraft)
maddox.game.AMission.OnAircraftDamaged(int, string, maddox.game.world.AiAircraft, maddox.game.world.AiDamageInitiator, part.NamedDamageTypes)
maddox.game.AMission.OnAircraftLanded(int, string, maddox.game.world.AiAircraft)
maddox.game.AMission.OnAircraftTookOff(int, string, maddox.game.world.AiAircraft) The OnAircraftDamaged routine will return a Boolean perhaps and that would be the trigger to start the fire engine's routine that takes it out to near the apron to meet the landing-damaged plane Anyway for our toe-in-the-water porpoises- the idea is to have a plane ready to take off and a fire engine/tender/truck parked up waiting for its CertainToCrash trigger Pranging your plane on takeoff triggers the fire engine which (eventually, midnight oil) can move close to your coordinates Take off and blow the engine or get shot up, land and there's the fire crew thank goodness with a fuel tank. Us not them Take off and land with no problems and the fire engine stays at NoBell readiness That's the theory but who among us doesn't enjoy reverse-engineering stuff. Legally Btw I copied in the damage script to an EAF training mission and got the 'Excellent!' message on landing successfully. So now I know how to insert a script into a mission (from within the FMB) and this stuff looks truly awesome as the Americans say maddox.game.AMission.OnCarter(maddox.game.world.AiActor, int) On Carter get ready to rumble maybe, Michael Caine reference Ming
'You are either a hater or you are not' Roman Halter
|
|
#3386081 - 09/09/11 06:31 AM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Jan 2001
Posts: 2,260
Tiger27
Member
|
Member
Joined: Jan 2001
Posts: 2,260
Perth, Western Australia
|
Some of this stuff (programming and scripting are not part of my repertoire)looks awesome for the future, this could be the most immersive FS ever if someone can get their heads around all these little features, the future looks bright!
III/JG11_Tiger
|
|
#3386228 - 09/09/11 11:36 AM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Sep 2004
Posts: 10,618
Ming_EAF19
Babelfish Immune
|
Babelfish Immune
Veteran
Joined: Sep 2004
Posts: 10,618
London
|
Fire engine's a vehicle, it'll need an ID and start/path/finish positions, digging around Then the real world intrudes. So unfair maddox.game.world.AiGroundGroupTypepublic const maddox.game.world.AiGroundGroupType Artillery = 4 public const maddox.game.world.AiGroundGroupType Ship = 3 public const maddox.game.world.AiGroundGroupType Town = 5 public const maddox.game.world.AiGroundGroupType Train = 2 public const maddox.game.world.AiGroundGroupType Vehicle = 1 maddox.game.world.AiGroundGroupvoid GetPos(out maddox.GP.Point3d pos) maddox.game.world.AiGroundGroupType GroupType() string ID() Ming
'You are either a hater or you are not' Roman Halter
|
|
#3386477 - 09/09/11 04:56 PM
Re: New API in the Beta
[Re: f15sim]
|
Joined: Jan 2009
Posts: 4,737
FearlessFrog
Senior Member
|
Senior Member
Joined: Jan 2009
Posts: 4,737
|
Now this would just kick ass if you can use that C# engine to pull systems data out of the sim and shove it out the door via a tcp/ip connection....
g. It does seem relatively easy to do this, as in communicate out of the process and give CoD internal details to outside things (i.e. scoreboards, USB instruments, 2nd display windows etc). Some of the API to extract aircraft info was here: http://simhq.com/forum/ubbthreads.php/topics/3347984/Re_Is_it_possible_to_make_airs.html#Post3347984One of my longer term CoD aspirations (i.e. I won't really do it, too busy, but my subconscious fools me into thinking I will one day) is to do a glorious BoB Bunker Battle Overview map, i.e. be able to issue commands in MP via an external map view, with those long sticks to push planes, and I could sit back while minions issued radio commands to squadrons. Would be cool, plus with this level of API not too challenging, from a technical level at least..
|
|
#3386481 - 09/09/11 04:57 PM
Re: New API in the Beta
[Re: Ming_EAF19]
|
Joined: Jan 2009
Posts: 4,737
FearlessFrog
Senior Member
|
Senior Member
Joined: Jan 2009
Posts: 4,737
|
Fire engine's a vehicle, it'll need an ID and start/path/finish positions, digging around Then the real world intrudes. So unfair maddox.game.world.AiGroundGroupTypepublic const maddox.game.world.AiGroundGroupType Artillery = 4 public const maddox.game.world.AiGroundGroupType Ship = 3 public const maddox.game.world.AiGroundGroupType Town = 5 public const maddox.game.world.AiGroundGroupType Train = 2 public const maddox.game.world.AiGroundGroupType Vehicle = 1 maddox.game.world.AiGroundGroupvoid GetPos(out maddox.GP.Point3d pos) maddox.game.world.AiGroundGroupType GroupType() string ID() Ming I think from my end the bit I miss out is really on using the FMB. Has anyone used it to move vehicles, and if so how? If we had routes and paths mapped out then the script would just do the start/stop bit, plus perhaps change one of the travel points. Any FMB Vehicle experts out there?
|
|
#3386502 - 09/09/11 05:15 PM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Sep 2004
Posts: 10,618
Ming_EAF19
Babelfish Immune
|
Babelfish Immune
Veteran
Joined: Sep 2004
Posts: 10,618
London
|
It's trivial to move vehicles around. I imagine but I haven't got that far yet, having been driven mad for a bit by road construction. Diversions yes. Place the vehicle down on a road in the CoD FMB and give it some waypoints, Play Mission to see it move around or not Scripts will move the vehicles around dynamically, perhaps on triggers, which is what this is about coincidentally Vehicles are called Chiefs in the Il-2 FMB and there are references to Vehicles/Chiefs in the Maddox dlls, some examples below- we'll need to explore AiGroundWayPoint is an obvious candidate for Chief/vehicle movement (BuildPath looks interesting) Point3d might be a table for XYZ floating point positions
No Fire Tender in the list of vehicles so improvisation, the bell would be an audio file perhapspublic interface AiAIChief Member of maddox.game.world public static class AiAIChiefType Member of maddox.game.world double FieldR() Member of maddox.game.world.AiAIChief public const int GROUND = 1 Member of maddox.game.world.AiAIChiefType public const maddox.game.world.AiGroundActorType LightTruck = 10 Member of maddox.game.world.AiGroundActorType public const maddox.game.world.AiGroundActorType Truck = 11 Member of maddox.game.world.AiGroundActorType public const maddox.game.world.AiGroundActorType Car = 5 Member of maddox.game.world.AiGroundActorType public AiGroundWayPoint(ref maddox.GP.Point3d p, double speed, double wait_time, double road_width) Member of maddox.game.world.AiGroundWayPoint protected static float[ ] BuildPath(int indx, float posX, float posY) Member of maddox.core.pathfind.WPathFind Next job: to scour the forums for scripting clues to implementation. Simple mission with one plane and one fire truck. Crash on takeoff and pray that a fire truck appears what with full tanks and 10 Woodbines and everything This is my link to scripting tips http://forum.1cpublishing.eu/forumdisplay.php?f=203Ming
'You are either a hater or you are not' Roman Halter
|
|
#3386529 - 09/09/11 05:56 PM
Re: New API in the Beta
[Re: Ming_EAF19]
|
Joined: Jan 2009
Posts: 2,474
Biggles07
Member
|
Member
Joined: Jan 2009
Posts: 2,474
Newcastle Upon Tyne, England.
|
In the cave of Socrates then, with the shadow puppetsThat's Plato's cave ming me aul China. That'll be a Plato' chips with mushy peas for that indiscretion and you're paying, next time its your dinner money you have been warned. Some of us are (Fox's) Classicists, you know. *munch munch* This is a really interesting thread. It's like a great voyage of self discovery, in which one comes to the Earth shattering, epiphanic realisation that one is thick as pigs sh*t and has no idea what anyone on this thread is talking about. But is this not in itself a form of knowledge, hmmmm? Javelin thrower, impale thyself! (or was it heal, I'm getting confused again.) *Rocks back and forth in fetal position, mumbling 'boleeans, all around....integers within the Enchilada! cats with 7 paws, the horror, the horror.....' See what you've done now? I've went fecking mental. Wheres Ajay, he knows what I'm on about. Carry on.
"I am fond of pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals".
Sir Winston Churchill
|
|
#3386562 - 09/09/11 06:44 PM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Sep 2004
Posts: 10,618
Ming_EAF19
Babelfish Immune
|
Babelfish Immune
Veteran
Joined: Sep 2004
Posts: 10,618
London
|
Plato had shadow puppets too? Bit of a coincidence but on you go Ming
'You are either a hater or you are not' Roman Halter
|
|
#3386593 - 09/09/11 07:13 PM
Re: New API in the Beta
[Re: Ming_EAF19]
|
Joined: Jan 2009
Posts: 2,474
Biggles07
Member
|
Member
Joined: Jan 2009
Posts: 2,474
Newcastle Upon Tyne, England.
|
Plato had shadow puppets too? Bit of a coincidence but on you go Ming Aye, but Animatronic ones Ming. Jurassic Punch n' Judy, way ahead of his time.
"I am fond of pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals".
Sir Winston Churchill
|
|
#3386626 - 09/09/11 07:51 PM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: May 2011
Posts: 588
Bokononist
Currently using: Occams Electric Shaver
|
Currently using: Occams Electric Shaver
Member
Joined: May 2011
Posts: 588
Liverpool, UK (Cornish exile)
|
Now this would just kick ass if you can use that C# engine to pull systems data out of the sim and shove it out the door via a tcp/ip connection....
g. It does seem relatively easy to do this, as in communicate out of the process and give CoD internal details to outside things (i.e. scoreboards, USB instruments, 2nd display windows etc). Some of the API to extract aircraft info was here: http://simhq.com/forum/ubbthreads.php/topics/3347984/Re_Is_it_possible_to_make_airs.html#Post3347984One of my longer term CoD aspirations (i.e. I won't really do it, too busy, but my subconscious fools me into thinking I will one day) is to do a glorious BoB Bunker Battle Overview map, i.e. be able to issue commands in MP via an external map view, with those long sticks to push planes, and I could sit back while minions issued radio commands to squadrons. Would be cool, plus with this level of API not too challenging, from a technical level at least.. That sounds cool Fearless, get on it straight away! Imagine the immersion levels with real people organising the tactical situation. P.S. is that you in that photo? Is that some kind of crazy mock-up in your loft? I can't think of any other reason that the 'lady' in the picture would be alone in the room in such an important situation, unless there was an emergency teabreak of course..............
"Tiger got to hunt, bird got to fly; Man got to sit and wonder, 'Why, why, why?' Tiger got to sleep, bird got to land; Man got to tell himself he understand." - A calypso.
i5 2500K@4.5Ghz | MSI P67A-GD53 | 8G DDR3 Corsair@1600 | Gainward GLH 460x2 SLI oc | Seagate Barracuda 1TB HDD | Antec Truepower New 750W PSU | Win 7 64bit | Black Widow HOTAS | Freetrack 2.2/PS3 eyetoy
|
|
#3386710 - 09/09/11 09:34 PM
Re: New API in the Beta
[Re: FearlessFrog]
|
Joined: Jul 2010
Posts: 638
ATAG_Bliss
Member
|
Member
Joined: Jul 2010
Posts: 638
|
Pretty cool stuff Frog! ---------------------------- Speaking of the joy of C+#+#+#+#+#+#+# stuff, Could one of you gurus show me a script that would limit a human controlled aircraft to a certain amount of units available. Say I only want 3 109E4's available at all times, any chance of a script to do that? With FBDj, it was super easy. Now not so much. But it would be nice to have a limited amount of certain planes, for balance etc.. In old IL2 with FBDj if you have 2 (262's) available. You could spawn 2 of them, and only when one of those 2 planes crashed/landed etc.(only after the refly button was hit) would the selection to be able to spawn another one open. Sorry for the hijack, but I need something like this badly
|
|
|
|