Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2012, 11:07 PM
hc_wolf hc_wolf is offline
Approved Member
 
Join Date: Jul 2010
Posts: 439
Question 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] =================================================
__________________
__________________
Win7, 64bit Ultra
Asus P8P67Pro MB
Intel i7-2600K
Coursair 16GB (4x 4GB), DDR3-1600MHz
Gainward Nvidia 580GTX 3GB DDR5
850-Watt Modular Power Supply
WIN7 and COD on Gskill SSD 240GB
40" Panasonic LCD
TrackIR5 +
Thrustmaster Warthog stick, throttle & pedals
Reply With Quote
  #2  
Old 08-01-2012, 04:29 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

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.

Last edited by FG28_Kodiak; 08-01-2012 at 04:32 AM.
Reply With Quote
  #3  
Old 08-01-2012, 04:46 AM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

Looks suspiciusly like some of my old code, ya bastard! 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))]);
                    }
                });
            }
        }
    }
__________________
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

Last edited by salmo; 08-01-2012 at 04:59 AM.
Reply With Quote
  #4  
Old 08-01-2012, 05:29 AM
hc_wolf hc_wolf is offline
Approved Member
 
Join Date: Jul 2010
Posts: 439
Default

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?

Below is in the Briefing of Mission.
"(Thanks also to SNAFU, KODIAK, Salmo & Bliss) "
__________________
__________________
Win7, 64bit Ultra
Asus P8P67Pro MB
Intel i7-2600K
Coursair 16GB (4x 4GB), DDR3-1600MHz
Gainward Nvidia 580GTX 3GB DDR5
850-Watt Modular Power Supply
WIN7 and COD on Gskill SSD 240GB
40" Panasonic LCD
TrackIR5 +
Thrustmaster Warthog stick, throttle & pedals
Reply With Quote
  #5  
Old 08-01-2012, 06:42 AM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

Quote:
Originally Posted by hc_wolf View Post
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?

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
__________________
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
Reply With Quote
  #6  
Old 08-01-2012, 07:12 AM
hc_wolf hc_wolf is offline
Approved Member
 
Join Date: Jul 2010
Posts: 439
Default

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
__________________
__________________
Win7, 64bit Ultra
Asus P8P67Pro MB
Intel i7-2600K
Coursair 16GB (4x 4GB), DDR3-1600MHz
Gainward Nvidia 580GTX 3GB DDR5
850-Watt Modular Power Supply
WIN7 and COD on Gskill SSD 240GB
40" Panasonic LCD
TrackIR5 +
Thrustmaster Warthog stick, throttle & pedals
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:17 AM.


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