PDA

View Full Version : Script to Remove AI From Servers


TheEnlightenedFlorist
06-06-2011, 04:04 AM
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?option=com_kunena&func=view&catid=43&id=539&Itemid=54

Ataros
06-06-2011, 08:07 AM
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.

SYN_Flashman
06-06-2011, 01:49 PM
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.

TheEnlightenedFlorist
06-07-2011, 12:01 AM
I added code to the script to deal with aircraft with more than two engines. Courtesy of ZaltysZ.

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.

I swear I remember this bug, but I just went through every German aircraft with more than one position and couldn't reproduce it. The engine stuttered a little (could just be a sound bug), but the temperatures remained the same.

TheEnlightenedFlorist
06-07-2011, 12:17 AM
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.

To be honest, it can't get too much simpler than it is already. You are right that there needs to be at least one line of code in the methods and that's the way it is already. We have one line of code in the OnPlaceLeave() method and on the AircraftLanded() and AircraftCrashLanded() methods and of course the mission number listener.

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.

Ataros
06-07-2011, 07:44 AM
I swear I remember this bug, but I just went through every German aircraft with more than one position and couldn't reproduce it. The engine stuttered a little (could just be a sound bug), but the temperatures remained the same.

I think you have it solved with the following code. Did you check it on a dedicated server? I included it in my script too but did not check yet as struggling with ground attacks code atm.

//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;

Does aircraft.Player() return a player name located inside an AiAircraft?
Do you know when RemotePlayer has to be used instead of Player?

TheEnlightenedFlorist
06-07-2011, 08:32 AM
Does aircraft.Player() return a player name located inside an AiAircraft?
Do you know when RemotePlayer has to be used instead of Player?

It returns the player at a specific "place" in an aircraft. It looks like "places" is what the developers call different seats in aircraft. If there is no player in that seat, it returns null.

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.

SYN_Flashman
06-07-2011, 11:06 AM
I added code to the script to deal with aircraft with more than two engines. Courtesy of ZaltysZ.



I swear I remember this bug, but I just went through every German aircraft with more than one position and couldn't reproduce it. The engine stuttered a little (could just be a sound bug), but the temperatures remained the same.

AFAIK this only happens on dedicated servers when online hence the difficulty in tracking it down! It certainly happens on the Syndicate Server. I will have a look at some of the extra bits of code and do some testing on our server when I get the opportunity.

TheEnlightenedFlorist
06-08-2011, 02:11 AM
AFAIK this only happens on dedicated servers when online hence the difficulty in tracking it down! It certainly happens on the Syndicate Server. I will have a look at some of the extra bits of code and do some testing on our server when I get the opportunity.

Yep. Only happens on dedicated servers.

pirke
06-11-2011, 06:23 PM
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

TheEnlightenedFlorist
06-11-2011, 11:24 PM
Hi pirke, there are spaces in these lines that shouldn't be there.

aircraft.hitNamed(part.NamedDamageTypes.ControlsEl evatorDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsRu dderDisabled);
aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFa ilure);

If that doesn't work, can you post the script file that you are using? Copying and pasting things back and forth makes errors more likely. It would be easier to see the .cs file.

pirke
06-12-2011, 09:47 AM
here look how i do it and you have mission i made for 1vs1 duel.
when aircraft land or crash land script do right.
but when in air when a player abandons a plane script didnt work right :(
look and repair scrip to make it right :)
PLS ;)

TheEnlightenedFlorist
06-12-2011, 10:00 AM
here look how i do it and you have mission i made for 1vs1 duel.
when aircraft land or crash land script do right.
but when in air when a player abandons a plane script didnt work right :(
look and repair scrip to make it right :)
PLS ;)

OK. I see the problem. I fixed your code and re-uploaded it. Tomorrow, I will edit the first post to be more clear.

pirke
06-12-2011, 10:18 AM
thnks :)

TheEnlightenedFlorist
06-23-2011, 11:56 PM
Updated to allow players to take off again after landing.