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)
-   -   GamePlay.gpGetAction Question (http://forum.fulqrumpublishing.com/showthread.php?t=33767)

frantic69 08-09-2012 12:10 PM

GamePlay.gpGetAction Question
 
Hello All,

First of all, thank you for this great forum and all the information we can find. As it is my first post, I take the occasion to say hello to all the COD fan.

My question is regarding this script :

AiAction action = GamePlay.gpGetAction("XXXXXXX");
if (action != null)
{
action.Do();
}

My goal is to constantly test the flight level of an aircraft (I have the flight level thanks to a OnTickGame function and it works fine).

As I don't know the name of the aircraft (the XXXX in the script above), I use the following script :

AiAction action = GamePlay.gpGetAction(ActorName.Full(missionNumber, shortName));

It works fine for a OnTrigger() function but it doesn't for a OnTickGame function because missionNumber and shortName do not exist in the OnTickGame context.

So, either I use the exact name XXXXX used by COD mission but I can't find it in the mission file (I tried many name indicated in this file but nothing seems to work) or I use the script above with missionNumber and shortName but it doesn't work in the OnTickGame function.

Have you any Idea of How I can manage this ?

I must say the I search a long time on internet and I tried many thing but nothing works. I am not a specialist of C# and script and I problably make a mistake but I can't see where.

So the full script is something like this :

using System;
using maddox.game;
using maddox.game.world;

public class Mission : maddox.game.AMission
{
double I_Altitude;

public override void OnTickGame()
{

base.OnTickGame();

if (Time.tickCounter() % 30 == 1)
{

AiAircraft curPlane = GamePlay.gpPlayer().Place() as AiAircraft;

if (curPlane != null)
{

I_Altitude = curPlane.getParameter(part.ParameterTypes.I_Altitu de, -1);

double dtime = Time.current();

GamePlay.gpHUDLogCenter(" ALT: " + I_Altitude.ToString("0.00"));

if (I_Altitude > 400)
{
GamePlay.gpHUDLogCenter("above 400");
AiAction action = GamePlay.gpGetAction(maddox.game.ActorName.Full(mi ssionNumber, shortName));
if (action != null)
{
action.Do();
}
}

}


}

}

}


Last point, I would like to thank all the people that post script on internet. As mentioned, I am not a great script maker and I try to understand and reuse existing code. The code above is a made of different script that I found on internet. Thanks to all the guy that made them.

Frantic

hc_wolf 08-09-2012 01:04 PM

You want exact plane names??

extract the names from the below lists.

Dictionary<string, int> LWAvailableAirplanes = new Dictionary<string, int>()
{
//Internaltypename, Startcount
{"bob:Aircraft.Bf-109E-3",60},
{"bob:Aircraft.Bf-109E-3B",24},
{"bob:Aircraft.Bf-109E-1",40},
{"bob:Aircraft.Bf-109E-4",10},
{"bob:Aircraft.Bf-109E-4B",24},
{"bob:Aircraft.Bf-110C-4",24},
{"bob:Aircraft.Bf-110C-7",24},
{"bob:Aircraft.Ju-87B-2",60},
{"bob:Aircraft.Ju-88A-1",10},
{"bob:Aircraft.He-111H-2",60},
{"bob:Aircraft.He-111P-2",20},
};
Dictionary<string, int> RAFAvailableAirplanes = new Dictionary<string, int>()
{
//Internaltypename, Startcount
{"bob:Aircraft.SpitfireMkIa",30},
{"bob:Aircraft.SpitfireMkI",60},
{"bob:Aircraft.HurricaneMkI",50},
{"bob:Aircraft.HurricaneMkI_dH5-20",50},
{"bob:Aircraft.BlenheimMkIV",40},
{"bob:Aircraft.SpitfireMkIIa",10},
{"bob:Aircraft.SpitfireMkIa_oct",10},
{"bob:Aircraft.HurricaneMkI_100oct",10},
};

frantic69 08-09-2012 01:29 PM

Hello Hc_wolf,

Thank for your help. In fact, in the GamePlay.gpGetAction() we must put the shortname of the unit. As far as I understand, the name can be entered directly thanks to the quote. Here is an example of what can be found on some script on internet :

action = GamePlay.gpGetAction("a9");
AiAction action = GamePlay.gpGetAction("0_Chief");

I read that we can find the shortname in the mission file. I found some information and tried them but nothing seems to work.

It is for that reason that I tried the AiAction action = GamePlay.gpGetAction(ActorName.Full(missionNumber, shortName)); method but it doesn't work in the ontickgame function.

Frantic

FG28_Kodiak 08-09-2012 02:32 PM

Not of the unit, of an Action definded in your mission. The only available action at the moment is the spawn of an AiGroup (AiAirGroup or AiGroundGroup). You define them at the second tab (by Scripts) in the FMB.
http://img40.imageshack.us/img40/900/2012080900001.jpg

In this case the name of the action is MyAction. So you can get access to it via GamePlay.gpGetAction("MyAction");

In the mis file you will find it in the Action Section
[Action]
MyAction ASpawnGroup 1 BoB_LW_LG2_I.01

frantic69 08-09-2012 03:06 PM

hello Kodiak,

Thank you. I saw that there is only few possibilities in the standard action. My goal was to spawn some aircraft when the player altitude goes over 400 ft.

I am able to have the altitude of the player. The variable is I_Altitude. I can easily show this altitude on the screen thanks to the GamePlay.gpHUDLogCenter(" ALT: " + I_Altitude.ToString("0.00")); line.

All this altitude stuff are done in the ontickgame function.

So, tell me if I am wrong but I tried to spawn the enemy aircraft thanks to following script :

if (I_Altitude > 400)
{
GamePlay.gpHUDLogCenter("above 400");
AiAction action = GamePlay.gpGetAction(maddox.game.ActorName.Full(mi ssionNumber, shortName));
if (action != null)
{
action.Do();
}

Could you confirm that we can spawn an aircraft thank to the line above ?

If yes, how can I manage to use it in the ontickgame function ?

Basically, I don't want to spawn an aircraft after a given time or when someone enter a specific area. I just want to spawn an aircraft when the player altitude is over 400 ft.

Sorry for my dumb question.

FG28_Kodiak 08-09-2012 03:43 PM

There are different ways to spawn a new aircraft. Via action is the simplest ;).

To do so, create a new mission, place the Airgroup on the map, enable only script spawn in the Object Options (if you don't do that your Airgroup spawns at beginning of the mission and than again if you call it via action.Do()). Create an action for it in the script -> action tab, give a simple name for example SpawnEnemyPlane, select the airgroup to spawn. Then save and save the mission.


Add a flag to the cs file, to avoid multiple spawning of the airgroup
Code:

    bool Spawned = false;

Then in your OnTickGame
Code:

if (I_Altitude > 400 && !Spawned)
{
    Spawned = true;
    GamePlay.gpHUDLogCenter("above 400");
    AiAction action = GamePlay.gpGetAction("SpawnEnemyPlane"));
    if (action != null)
    {
        action.Do();
    }
}


frantic69 08-09-2012 05:20 PM

Thank you so much Kodiak. That works fine. Before posting I wanted to search and find by myself. I think this is the only way to progress but I was not good enough.
I think it should looks so easy for you but thank you again because was very helpful.

thanks to your script I understood manything and I understand now my mistakes.

The most important was this part : gpGetAction("SpawnEnemyPlane")
I was wrong when I was thinking that the name to put inside the cotes have to be the name found in the mission file. It was simply the name of the trigger you created in the script action box.

Thank you, you are a code king.

I will probably have some another new questions in the futur and I am happy to think that there is, here on this forum, some very skilled guys like you.

Thanks,

Frantic


All times are GMT. The time now is 10:32 PM.

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