![]() |
|
#1
|
||||
|
||||
![]() Quote:
|
#2
|
||||
|
||||
![]()
ok tested again, with different numbers of available planes for each spawnpoint, and you are correct, its indeed showing the message that only 5planes are available....so this is good enough for me for now, as i have no glue again how and where to implement the Timeout section, without messing up the whole script....
but thinking again about the possibility, that if planes come back to base, are included again in the pool of the spawnpoint, is really attracting me...again, if you could write that for me, i would be REALLY REALLY HAPPY(maybe with the timeout section included already) one thing that came to my mind, is that one has to be careful with the messages then, as now, the script gives out a message, as one spawns in a plane...if the feature of returning planes is included, the messages should pop up, when a plane gets destroyed, as otherwise, the warnings/messages could be wrong.......but who i am telling this....if you really decide to write such a script for me, you are certainly aware of that... again and again and again Kodiak, during the last months, i had sooo much fun, because of your scripts you wrote for me....a BIG THANK YOU PS:if that all is possible, i really wonder, why this havent been included on servers such like atag already???...in my view, this is a great way of having a dynamic war....besides, with the script i already have, one could for example get rid of the "self destroying" E4s on atag, which suddenly after a few seconds lose their ailerons and elevators on ground, while you are still able to spawn in them....??? Last edited by David198502; 06-21-2012 at 01:24 PM. |
#3
|
|||
|
|||
![]()
in your code change:
Code:
if (numberOfAllAvailablePlanes == 5) { if(actor.Army() == 1) GamePlay.gpHUDLogCenter(null, "Attention Reds only {0} Planes are left", new object[] { numberOfAllAvailablePlanes }); if(actor.Army() == 2) GamePlay.gpHUDLogCenter(null, "Attention Blues only {0} Planes are left", new object[] { numberOfAllAvailablePlanes }); } if (place.NumberOfPlanes == 5 ) { Timeout(5, () => { GamePlay.gpHUDLogCenter(null, "Attention only {0} Planes are left on {1}", new object[] { place.NumberOfPlanes, place.BirthPlace }); }); } |
#4
|
||||
|
||||
![]()
doesnt seem to work for me....all the messages are gone(also available/in use -messages)
and i seem to be able to respawn infinitely... |
#5
|
|||
|
|||
![]()
then there must be a error in code can you show me your changes, may be there is a missing ";" or something else.
|
#6
|
||||
|
||||
![]()
here is the complete code:
HTML Code:
using System; using System.Collections; using System.Collections.Generic; using maddox.GP; using maddox.game; using maddox.game.world; using part; public class Mission : AMission { private bool battleEnded = false; class BirthPlacePlanes { public string BirthPlace { get; set; } public int NumberOfPlanes { get; set; } public BirthPlacePlanes(string birthPlaceName, int maxNumber) { BirthPlace = birthPlaceName; NumberOfPlanes = maxNumber; } } List<BirthPlacePlanes> AvailablePlanes = new List<BirthPlacePlanes> { new BirthPlacePlanes("RAF-5k", 10), new BirthPlacePlanes("RAF-3k", 10), new BirthPlacePlanes("RAF-500m", 10), new BirthPlacePlanes("JG26-5k", 1), new BirthPlacePlanes("JG26-3k", 1), new BirthPlacePlanes("JG26-500m", 5) }; public bool IsActorDown(AiActor actor) { AiAircraft aircraft = actor as AiAircraft; if (aircraft != null && (aircraft.getParameter(ParameterTypes.Z_AltitudeAGL, -1) <= 2.0 && aircraft.getParameter(ParameterTypes.Z_VelocityTAS, -1) <= 1.0)) return true; return false; } public int CountPlayerUsedPlanes(int army) { int count = 0; foreach (Player pl in AllPlayers()) { if (pl.Place() != null && pl.Army() == army && pl.PlacePrimary() == 0) count++; } return count; } public int CountAvailablePlanes(int army) { int count = 0; foreach (BirthPlacePlanes bpp in AvailablePlanes) { AiBirthPlace birthPlace = GetBirthPlaceByName(bpp.BirthPlace); if (birthPlace != null) if (birthPlace.Army() == army) count += bpp.NumberOfPlanes; } return count; } public AiBirthPlace GetBirthPlaceByName(string birthPlaceName) { foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces()) { if (bp.Name() == birthPlaceName) return bp; } return null; } public AiBirthPlace GetBirthplace(AiActor actor) { AiBirthPlace nearestBirthplace = null; AiBirthPlace[] birthPlaces = GamePlay.gpBirthPlaces(); Point3d pos = actor.Pos(); if (birthPlaces != null) { foreach (AiBirthPlace airport in birthPlaces) { if (nearestBirthplace != null) { if (nearestBirthplace.Pos().distance(ref pos) > airport.Pos().distance(ref pos)) nearestBirthplace = airport; } else nearestBirthplace = airport; } } return nearestBirthplace; } public override void OnBattleStarted() { base.OnBattleStarted(); MissionNumberListener = -1; } public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex) { base.OnPlaceEnter(player, actor, placeIndex); AiBirthPlace birthPlace = GetBirthplace(actor); AiCart cart = actor as AiCart; if(cart != null) AvailablePlanes.ForEach(place => { if (place.BirthPlace == birthPlace.Name()) { place.NumberOfPlanes--; int numberOfAllAvailablePlanes = CountAvailablePlanes(actor.Army()); if (numberOfAllAvailablePlanes == 5) { if(actor.Army() == 1) GamePlay.gpHUDLogCenter(null, "Attention Reds only {0} Planes are left", new object[] { numberOfAllAvailablePlanes }); if(actor.Army() == 2) GamePlay.gpHUDLogCenter(null, "Attention Blues only {0} Planes are left", new object[] { numberOfAllAvailablePlanes }); } if (place.NumberOfPlanes == 3 ) { Timeout(5, () => { GamePlay.gpHUDLogCenter(null, "Attention only {0} Planes are left on {1}", new object[] { place.NumberOfPlanes, place.BirthPlace }); } if (place.NumberOfPlanes == 0) { GamePlay.gpHUDLogCenter(null, "Attention {0} is no longer available", new object[]{place.BirthPlace}); birthPlace.destroy(); } } }); } public List<Player> AllPlayers() { List<Player> allPlayers = new List<Player>(); if(GamePlay.gpPlayer() != null) allPlayers.Add(GamePlay.gpPlayer()); if(GamePlay.gpRemotePlayers() != null) allPlayers.AddRange(GamePlay.gpRemotePlayers()); return allPlayers; } public override void OnTickGame() { base.OnTickGame(); if (Time.tickCounter() % 300 == 0) { // check if Player is grounded AllPlayers().ForEach(item => { if (item.Place() != null) if (IsActorDown(item.Place())) { AiCart cart = item.Place() as AiCart; if (cart != null) cart.Destroy(); } }); //TestMessages remove if no longer needed GamePlay.gpLogServer(null, "Army: RED, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(1), CountPlayerUsedPlanes(1) }); GamePlay.gpLogServer(null, "Army: BLUE, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(2), CountPlayerUsedPlanes(2) }); } } public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor) { base.OnActorDestroyed(missionNumber, shortName, actor); AiCart cart = actor as AiCart; if (cart != null) { if (actor.Army() == 1 && CountAvailablePlanes(1) == 0 && CountPlayerUsedPlanes(1) == 0 && !battleEnded) { battleEnded = true; GamePlay.gpHUDLogCenter(null, "JG26 kicked your butts"); } else if (actor.Army() == 2 && CountAvailablePlanes(2) == 0 && CountPlayerUsedPlanes(2) == 0 && !battleEnded) { battleEnded = true; GamePlay.gpHUDLogCenter(null, "Micky Mouse Team won"); } } } } |
#7
|
|||
|
|||
![]()
Ok some bracket mismatch, corrected version:
Code:
using System; using System.Collections; using System.Collections.Generic; using maddox.GP; using maddox.game; using maddox.game.world; using part; public class Mission : AMission { private bool battleEnded = false; class BirthPlacePlanes { public string BirthPlace { get; set; } public int NumberOfPlanes { get; set; } public BirthPlacePlanes(string birthPlaceName, int maxNumber) { BirthPlace = birthPlaceName; NumberOfPlanes = maxNumber; } } List<BirthPlacePlanes> AvailablePlanes = new List<BirthPlacePlanes> { new BirthPlacePlanes("RAF-5k", 10), new BirthPlacePlanes("RAF-3k", 10), new BirthPlacePlanes("RAF-500m", 10), new BirthPlacePlanes("JG26-5k", 1), new BirthPlacePlanes("JG26-3k", 1), new BirthPlacePlanes("JG26-500m", 5) }; public bool IsActorDown(AiActor actor) { AiAircraft aircraft = actor as AiAircraft; if (aircraft != null && (aircraft.getParameter(ParameterTypes.Z_AltitudeAGL, -1) <= 2.0 && aircraft.getParameter(ParameterTypes.Z_VelocityTAS, -1) <= 1.0)) return true; return false; } public int CountPlayerUsedPlanes(int army) { int count = 0; foreach (Player pl in AllPlayers()) { if (pl.Place() != null && pl.Army() == army && pl.PlacePrimary() == 0) count++; } return count; } public int CountAvailablePlanes(int army) { int count = 0; foreach (BirthPlacePlanes bpp in AvailablePlanes) { AiBirthPlace birthPlace = GetBirthPlaceByName(bpp.BirthPlace); if (birthPlace != null) if (birthPlace.Army() == army) count += bpp.NumberOfPlanes; } return count; } public AiBirthPlace GetBirthPlaceByName(string birthPlaceName) { foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces()) { if (bp.Name() == birthPlaceName) return bp; } return null; } public AiBirthPlace GetBirthplace(AiActor actor) { AiBirthPlace nearestBirthplace = null; AiBirthPlace[] birthPlaces = GamePlay.gpBirthPlaces(); Point3d pos = actor.Pos(); if (birthPlaces != null) { foreach (AiBirthPlace airport in birthPlaces) { if (nearestBirthplace != null) { if (nearestBirthplace.Pos().distance(ref pos) > airport.Pos().distance(ref pos)) nearestBirthplace = airport; } else nearestBirthplace = airport; } } return nearestBirthplace; } public override void OnBattleStarted() { base.OnBattleStarted(); MissionNumberListener = -1; } public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex) { base.OnPlaceEnter(player, actor, placeIndex); AiBirthPlace birthPlace = GetBirthplace(actor); AiCart cart = actor as AiCart; if (cart != null) AvailablePlanes.ForEach(place => { if (place.BirthPlace == birthPlace.Name()) { place.NumberOfPlanes--; int numberOfAllAvailablePlanes = CountAvailablePlanes(actor.Army()); if (numberOfAllAvailablePlanes == 5) { if (actor.Army() == 1) GamePlay.gpHUDLogCenter(null, "Attention Reds only {0} Planes are left", new object[] {numberOfAllAvailablePlanes}); if (actor.Army() == 2) GamePlay.gpHUDLogCenter(null, "Attention Blues only {0} Planes are left", new object[] {numberOfAllAvailablePlanes}); } if (place.NumberOfPlanes == 3) { Timeout(5, () =>{ GamePlay.gpHUDLogCenter(null, "Attention only {0} Planes are left on {1}", new object[] { place.NumberOfPlanes, place.BirthPlace}); }); } if (place.NumberOfPlanes == 0) { GamePlay.gpHUDLogCenter(null, "Attention {0} is no longer available", new object[] {place.BirthPlace}); birthPlace.destroy(); } } }); } public List<Player> AllPlayers() { List<Player> allPlayers = new List<Player>(); if(GamePlay.gpPlayer() != null) allPlayers.Add(GamePlay.gpPlayer()); if(GamePlay.gpRemotePlayers() != null) allPlayers.AddRange(GamePlay.gpRemotePlayers()); return allPlayers; } public override void OnTickGame() { base.OnTickGame(); if (Time.tickCounter() % 300 == 0) { // check if Player is grounded AllPlayers().ForEach(item => { if (item.Place() != null) if (IsActorDown(item.Place())) { AiCart cart = item.Place() as AiCart; if (cart != null) cart.Destroy(); } }); //TestMessages remove if no longer needed GamePlay.gpLogServer(null, "Army: RED, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(1), CountPlayerUsedPlanes(1) }); GamePlay.gpLogServer(null, "Army: BLUE, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(2), CountPlayerUsedPlanes(2) }); } } public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor) { base.OnActorDestroyed(missionNumber, shortName, actor); AiCart cart = actor as AiCart; if (cart != null) { if (actor.Army() == 1 && CountAvailablePlanes(1) == 0 && CountPlayerUsedPlanes(1) == 0 && !battleEnded) { battleEnded = true; GamePlay.gpHUDLogCenter(null, "JG26 kicked your butts"); } else if (actor.Army() == 2 && CountAvailablePlanes(2) == 0 && CountPlayerUsedPlanes(2) == 0 && !battleEnded) { battleEnded = true; GamePlay.gpHUDLogCenter(null, "Micky Mouse Team won"); } } } } |
![]() |
|
|