![]() |
|
#1
|
|||
|
|||
![]()
Just a guess: gpPlayer() returns null if you are hosting it on a dedicated server and gpPlayer().Place() returns null if the player is not within an vehicle.
Code:
private void DoDamage() { // Script that triggered an accidental damage to the player plane // Author: FG28_Kodiak Modified by: Salmo // Ref: http://forum.1cpublishing.eu/showthread.php?t=22184 if(GamePlay.gpPlayer() != null && GamePlay.gpPlayer().Place() != null && GamePlay.gpPlayer().Place() is AiAircraft) { PlayerPlane = (AiAircraft)GamePlay.gpPlayer().Place(); ... } } |
#2
|
|||
|
|||
![]()
Thanks Banks, I thought the same, so I've played with removing the Dodamage() call etc but it did not fix the error. So while your code suggestion is more elegant (& I've implimented it), it doesnt fix the NullReferenceException error
![]()
__________________
When one engine fails on a two engine bomber, you will always have enough power left to get to the scene of the crash. Get the latest COD Team Fusion patch info HERE |
#3
|
|||
|
|||
![]()
Hi Salmo,
I've been seeing this error through the dedi box since the game was released (scripts or not). There's still a huge disconnect between running missions through the in-game GUI and running them through the -server. Nice stuff you've done with scripting btw! |
#4
|
|||
|
|||
![]()
@salmo:
Modified: Code:
public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft) { if (m_random.Next(1, 200 + 1) != 67) // 0.5% chance of takeoff failure { DoDamage(aircraft); } } private void DoDamage(AiAircraft aircraft) { // Script that triggered an accidental damage to the player plane // Author: FG28_Kodiak Modified by: Salmo // Ref: http://forum.1cpublishing.eu/showthread.php?t=22184 if (aircraft.Player(0) == null) return; // If no human pilot leave switch (m_random.Next(1, 7 + 1)) { // =================================== // ---- Engine(s) failures ---- // =================================== case 1: aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalFailure); //sendScreenMessageToPilot(PlayerPlane, "Engine Failure", null); //GamePlay.gpHUDLogCenter("Engine Failure"); break; case 2: aircraft.hitNamed(part.NamedDamageTypes.Eng0OilSecondariesFire); //sendScreenMessageToPilot(aircraft, "Oil is on fire"); GamePlay.gpHUDLogCenter("Oil is on fire"); break; // =================================== // ---- Hydrolicss & cables failures ---- // =================================== case 3: if (m_random.Next(1, 2) == 1) { aircraft.hitNamed(part.NamedDamageTypes.UndercarriageUpLockFailureL); //sendScreenMessageToPilot(aircraft, "Undercarriage failure"); GamePlay.gpHUDLogCenter("Undercarriage failure"); } else { aircraft.hitNamed(part.NamedDamageTypes.UndercarriageUpLockFailureR); //sendScreenMessageToPilot(aircraft, "Undercarriage failure"); GamePlay.gpHUDLogCenter("Undercarriage failure"); } break; case 4: aircraft.hitNamed(part.NamedDamageTypes.Eng0ThrottleControlBroken); //sendScreenMessageToPilot(aircraft, "Broken throttle cable"); GamePlay.gpHUDLogCenter("Broken throttle cable"); break; // =================================== // ---- Flight surfaces failures ---- // =================================== case 5: aircraft.hitNamed(part.NamedDamageTypes.ControlsElevatorDisabled); //sendScreenMessageToPilot(aircraft, "Elevator jammed"); GamePlay.gpHUDLogCenter("Elevator jammed"); break; case 6: aircraft.hitNamed(part.NamedDamageTypes.ControlsAileronsDisabled); //sendScreenMessageToPilot(aircraft, "Ailerons jammed"); GamePlay.gpHUDLogCenter("Ailerons jammed"); break; case 7: aircraft.hitNamed(part.NamedDamageTypes.ControlsRudderDisabled); //sendScreenMessageToPilot(aircraft, "Rudder jammed"); GamePlay.gpHUDLogCenter("Rudder jammed"); break; default: aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalFailure); //sendScreenMessageToPilot(aircraft, "Engine Failure"); GamePlay.gpHUDLogCenter("Engine Failure"); break; } } |
#5
|
|||
|
|||
![]()
Cool. Simple modification, to add a random delay before failure:
Code:
public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft) { if (m_random.Next(1, 200 + 1) != 67) // 0.5% chance of takeoff failure { Timeout(m_random.Next(1, 60), ()=> DoDamage(aircraft)); } } Last edited by Octocat; 12-16-2011 at 05:21 AM. |
![]() |
Thread Tools | |
Display Modes | |
|
|