|
CoD Multiplayer Everything about multiplayer in IL-2 CoD |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Script to Remove AI From Servers
From now on, all my guides will be hosted on Airwarfare.com. This way I only have to edit one document. You may still post suggestions and corrections in this thread.
http://airwarfare.com/sow/index.php?...=539&Itemid=54 Last edited by TheEnlightenedFlorist; 07-01-2011 at 11:21 PM. |
#2
|
|||
|
|||
Is there a way to include all the above code parts into just one method like clearAircraft(general timeout, optional aircraft landing timeout, optional aircraft abandoned timeout, optional aircraft crashlended timeout) and call it in just 1 line from existing game methods? The code would then automatically understand which method it is called from and act accordingly. I assume new code can not call the existing game methods itself and we have to put at least one line in existing game methods (onTrigger, ontickgame, etc.)
It would make life of server owners much easier. I am just starting to learn C# and is interested to learn how to make code more readable and usable as encapsulated building blocks. It would be perfect to have just one code block per function. |
#3
|
|||
|
|||
Hi enlightened,
I pretty much use that script for despawning on my missions over at Syndicate including listen to mission events. I just adjusted the time for plane removal downwards (to 1 minute) It appears to work fine, we just have the problem with multicrew aircraft turning the engine temps to zero when switching seats. I have tried the server without the script (since the last patch included aircraft removal on landing) but the problem is that if a player leaves a plane before takeoff AI takes over, takes off and then loiters around the field for hours! Anyhow, hopefully the next patch will address the crew change issue. |
#4
|
|||
|
|||
I added code to the script to deal with aircraft with more than two engines. Courtesy of ZaltysZ.
Quote:
|
#5
|
|||
|
|||
Quote:
I'm not an expert in software development, but I was taught that you don't want to cram too much code into one method. It's better to separate it out into parts so it's easier to read and modify. |
#6
|
|||
|
|||
Quote:
Code:
//check if a player is in any of the "places" for (int i = 0; i < aircraft.Places(); i++) if (aircraft.Player(i) != null) return false; Do you know when RemotePlayer has to be used instead of Player? |
#7
|
|||
|
|||
Quote:
gpRemotePlayers() would be used to get all of the players connected to the server. From there, you could get the aircraft that they are in. aircraft.Player() would be used when you already have an aircraft and want to get the player (if any) that occupies that aircraft. It's a subtle but very important difference. |
#8
|
|||
|
|||
Quote:
|
#9
|
|||
|
|||
Quote:
|
#10
|
|||
|
|||
public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
{ base.OnPlaceLeave(player, actor, placeIndex); Timeout(1, () => { damageAiControlledPlane(actor); } ); } public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft) { base.OnAircraftCrashLanded(missionNumber, shortName, aircraft); Timeout(300, () => { destroyPlane(aircraft); } ); } public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft) { base.OnAircraftLanded(missionNumber, shortName, aircraft); Timeout(300, () => { destroyPlane(aircraft); } ); } private bool isAiControlledPlane(AiAircraft aircraft) { if (aircraft == null) return false; //check if a player is in any of the "places" for (int i = 0; i < aircraft.Places(); i++) if (aircraft.Player(i) != null) return false; return true; } private void destroyPlane(AiAircraft aircraft) { if (aircraft != null) aircraft.Destroy(); } 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.ControlsEl evatorDisabled); aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled); aircraft.hitNamed(part.NamedDamageTypes.ControlsRu dderDisabled); aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFa ilure); int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum(); for (int i = 0; i < iNumOfEngines; i++) { aircraft.hitNamed((part.NamedDamageTypes)Enum.Pars e(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure")); } Timeout(300, () => { destroyPlane(aircraft); } ); } } all is good but ...... When a player abandons a plane, script will disable controls and engines and remove the plane after 300 seconds. this not working AI continue to fly with no restriction pls some help with this part only THNKS |
|
|