Official Fulqrum Publishing forum

Official Fulqrum Publishing forum (http://forum.fulqrumpublishing.com/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.fulqrumpublishing.com/forumdisplay.php?f=203)
-   -   Error with Mission.OnAircraftDamaged (http://forum.fulqrumpublishing.com/showthread.php?t=33549)

hc_wolf 07-31-2012 11:07 PM

Error with Mission.OnAircraftDamaged
 
Hi guys,

Time to break open the code.

I am seeing an error on the server and I can not pinpoint what the issue is.
Below is the code I am using (the voice sounds work and get no error with that)

Any Idea?

Code:

    public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, part.NamedDamageTypes damageType)
    {
        base.OnAircraftDamaged(missionNumber, shortName, aircraft, initiator, damageType);

        // speech //  GetDamageVictims()
        AiAircraft initiator_aircraft = initiator.Actor as AiAircraft;
        if (speechTimer.Elapsed.Milliseconds > 1 && speechTimer.Elapsed.Seconds < 20)
        {  // timer is running & less than 20 seconds since last speech
            return;  // speech no more fequently than 20 secs apart.
        }
        else
        {
            speechTimer.Restart();
        }
        if (aircraft.Army() != initiator_aircraft.Army())
        {
            // shooting at enemy aircraft
            Timeout(3, () =>      // wait 3 seconds
            {
                switch (random.Next(1, 6 + 1))
                {
                    case 1:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Nice_shot");
                        break;
                    case 2:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Good_shot_sir");
                        break;
                    case 3:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Good_shooting");
                        break;
                    case 4:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Good_show");
                        break;
                    case 5:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Bullseye");
                        break;
                    case 6:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Good_hits");
                        break;
                    default:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Direct_hit");
                        break;
                }
            });
        }
        else
        {
            //  shooting at a friendly aircraft
            // first verse
            if (random.Next(1, 100 + 1) < 75) // 33% chance of first verse
            {
                switch (random.Next(1, 2 + 1))
                {
                    case 1:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Friendlies");
                        break;
                    case 2:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Damn_what_are_you_doing");
                        break;
                    default:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Damn1");
                        break;
                }
            }
            //second verse
            Timeout(2, () =>      // wait 2 seconds
            {
                switch (random.Next(1, 3 + 1))
                {
                    case 1:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Cease_fire_shooting_at_friendly");
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Return_to_base_immediately_or_you_will_be_shot_down_");
                        break;
                    case 2:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Watch_it_You_re_shooting_at_one_of_ours");
                        break;
                    case 3:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Stop_fire");
                        break;
                    default:
                        initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Oh_my_God_Stop_Please_stop_Ooooaaaaahhh");
                        break;
                }
            });
            // third verse
            Timeout(4, () =>      // wait 4 seconds
            {
                if (random.Next(1, 100 + 1) < 75) // 30% chance of third verse
                {
                    switch (random.Next(1, 2 + 1))
                    {
                        case 1:
                            initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "That_is_without_a_doubt_the_worst_flying_I_have_ever_seen");
                            break;
                        case 2:
                            initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Return_to_base_immediately_or_you_will_be_shot_down_");
                            break;
                        default:
                            initiator_aircraft.SayToGroup(initiator_aircraft.AirGroup(), "Cannot_do_anything_right_today_can_you");
                            break;
                    }
                }
            });
        }
    }

[23:01:42] =================================================
[23:01:42] System.NullReferenceException: Object reference not set to an instance of an object.
[23:01:42]
[23:01:42] Server stack trace:
[23:01:42] at Mission.OnAircraftDamaged(Int32 missionNumber, String shortName, AiAircraft aircraft, AiDamageInitiator initiator, NamedDamageTypes damageType)
[23:01:42] at maddox.game.ABattle.OnAircraftDamaged(Int32 missionNumber, String shortName, AiAircraft aircraft, AiDamageInitiator initiator, NamedDamageTypes damageType)
[23:01:42] at maddox.game.world.Strategy.OnAircraftDamaged(Int32 missionNumber, String shortName, AiAircraft aircraft, AiDamageInitiator initiator, NamedDamageTypes damageType)
[23:01:42] at maddox.game.ABattle.OnEventGame(GameEventId eventId, Object eventArg0, Object eventArg1, Int32 eventArgInt)
[23:01:42] at maddox.game.world.Strategy.OnEventGame(GameEventId eventId, Object eventArg0, Object eventArg1, Int32 eventArgInt)
[23:01:42] at System.Runtime.Remoting.Messaging.StackBuilderSink ._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
[23:01:42] at System.Runtime.Remoting.Messaging.StackBuilderSink .SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
[23:01:42]
[23:01:42] Exception rethrown at [0]:
[23:01:42] at System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage reqMsg, IMessage retMsg)
[23:01:42] at System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData& msgData, Int32 type)
[23:01:42] at maddox.game.IBattle.OnEventGame(GameEventId eventId, Object eventArg0, Object eventArg1, Int32 eventArgInt)
[23:01:42] at maddox.game.GameDef.eventGame(GameEventId eventId, Object eventArg0, Object eventArg1, Int32 eventArgInt)
[23:01:42] at WoroaxENpmii8VryBS1.l72U2qEZkgauhd5ThjE.naGW165wRS kRFDpn8qAt(Object , GameEventId , Object , Object , Int32 )
[23:01:42] at WoroaxENpmii8VryBS1.l72U2qEZkgauhd5ThjE.eventGame( GameEventId , Object , Object , Int32 )
[23:01:42] at QTJWCZav3I4dK5Rv9Zd.soVedrakcuHYXN8uYhv.V15uBXPplU M(GameEventId , Object , Object , Int32 )
[23:01:42] =================================================

FG28_Kodiak 08-01-2012 04:29 AM

Test initiator_aircraft for null value
Code:

if (initiator_aircraft == null) return;
The initiator actor can also be a Groundactor so in this case initiator_aircraft is null.

salmo 08-01-2012 04:46 AM

Looks suspiciusly like some of my old code, ya bastard! :grin: What Kodiak said, also below I've tidied up all those 'case' statements. You can add/remove speech lines by altering the appropriate speech string array in each section without having to change the sayToGroup code.

Code:

    public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, part.NamedDamageTypes damageType)
    {
        base.OnAircraftDamaged(missionNumber, shortName, aircraft, initiator, damageType);

        // speech //  GetDamageVictims()
        AiAircraft initiator_aircraft = initiator.Actor as AiAircraft;
        if (initiator_aircraft != null)
        {
            if (speechTimer.Elapsed.Milliseconds > 1 && speechTimer.Elapsed.Seconds < 20)
            {  // timer is running & less than 20 seconds since last speech
                return;  // speech no more fequently than 20 secs apart.
            }
            else
            {
                speechTimer.Restart();
            }
            if (aircraft.Army() != initiator_aircraft.Army())
            {
                // shooting at enemy aircraft
                Timeout(3, () =>      // wait 3 seconds
                {
                    // shooting at enemy aircraft speech
                    string[] HitEnemyACSpeech =
                    {
                        "Nice_shot",
                        "Good_shot_sir",
                        "Good_shooting",
                        "Good_show",
                        "Bullseye",
                        "Good_hits",
                        "Direct_hit"
                    };
                    sayToGroup(initiator_aircraft.AirGroup(), HitEnemyACSpeech[random.Next(HitEnemyACSpeech.GetLowerBound(0), HitEnemyACSpeech.GetUpperBound(0))]);
                });
            }
            else
            {
                //  shooting at a friendly aircraft
                // first verse
                if (random.Next(1, 100 + 1) < 75) // 25% chance of first verse
                {
                    // shooting at friendly aircraft speech
                    string[] HitFriendlyACSpeech =
                    {
                        "Friendlies",
                        "Damn_what_are_you_doing",
                        "Damn1"
                    };
                    sayToGroup(initiator_aircraft.AirGroup(), HitFriendlyACSpeech[random.Next(HitFriendlyACSpeech.GetLowerBound(0), HitEnemyACSpeech.GetUpperBound(0))]);
                }
                //second verse
                Timeout(2, () =>      // wait 2 seconds
                {
                    // shooting at friendly aircraft speech 2
                    string[] HitFriendlyACSpeech2 =
                    {
                        "Cease_fire_shooting_at_friendly",
                        "Return_to_base_immediately_or_you_will_be_shot_down_",
                        "Watch_it_You_re_shooting_at_one_of_ours",
                        "Stop_fire",
                        "Oh_my_God_Stop_Please_stop_Ooooaaaaahhh"
                    };
                    sayToGroup(initiator_aircraft.AirGroup(), HitFriendlyACSpeech2[random.Next(HitFriendlyACSpeech2.GetLowerBound(0), HitFriendlyACSpeech2.GetUpperBound(0))]);
                });
                // third verse
                Timeout(4, () =>      // wait 4 seconds
                {
                    if (random.Next(1, 100 + 1) < 75) // 25% chance of third verse
                    {
                        // shooting at friendly aircraft speech 3
                        string[] HitFriendlyACSpeech3 =
                    {
                        "That_is_without_a_doubt_the_worst_flying_I_have_ever_seen",
                        "Return_to_base_immediately_or_you_will_be_shot_down_",
                        "Cannot_do_anything_right_today_can_you"
                    };
                        sayToGroup(initiator_aircraft.AirGroup(), HitFriendlyACSpeech3[random.Next(HitFriendlyACSpeech3.GetLowerBound(0), HitFriendlyACSpeech3.GetUpperBound(0))]);
                    }
                });
            }
        }
    }


hc_wolf 08-01-2012 05:29 AM

Thanks Salmo!

Also, "Looks suspiciusly like some of my old code, ya bastard! "

That would explain why I have your name in my "Special Thanks" list next to Kodiak and others. Would you like your name further up the list? :-P

Below is in the Briefing of Mission.
"(Thanks also to SNAFU, KODIAK, Salmo & Bliss) "

salmo 08-01-2012 06:42 AM

Quote:

Originally Posted by hc_wolf (Post 449917)
Thanks Salmo!

Also, "Looks suspiciusly like some of my old code, ya bastard! "

That would explain why I have your name in my "Special Thanks" list next to Kodiak and others. Would you like your name further up the list? :-P

Below is in the Briefing of Mission.
"(Thanks also to SNAFU, KODIAK, Salmo & Bliss) "

It's all good mate, just an Aussie jibe :) Hope to catch you on TS soon. Keep up the good coding work :)

hc_wolf 08-01-2012 07:12 AM

Salmo,

Since you are reading here and not your email... Must take a while to travel from Melbourne to Tassie. You must be on the NBN...hahahaha

FYI I sent you the mission to your email ;)


All times are GMT. The time now is 12:32 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.