Log in

View Full Version : scrpt no work well


melasuda
03-19-2012, 04:16 PM
Hello, sorry for my English and my ignorance in c # programming.

I've already started a course to learn to program, but until it is mastered ...

I added the following scrip.



base.OnTrigger(missionNumber, shortName, active);

AiAction Action = GamePlay.gpGetAction(shortName);

if (Action != null)
Action.Do();

GamePlay.gpGetTrigger(shortName).Enable = true;


The AI ​​if you activate the triggers, but I can not be activated by humans.

What else would you add?

there is the complete scrip

{


base.OnTrigger(missionNumber, shortName, active);

AiAction Action = GamePlay.gpGetAction(shortName);

if (Action != null)
Action.Do();

GamePlay.gpGetTrigger(shortName).Enable = true;

}

// Base Scripts for Missions
private bool isAiControlledPlane (AiAircraft aircraft)
{
if (aircraft == null)
{
return false;
}

Player [] players = GamePlay.gpRemotePlayers ();
foreach (Player p in players)
{
if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)
{
return false;
}
}

return false;
}

private void destroyPlane (AiAircraft aircraft) {
if (aircraft != null) {
aircraft.Destroy ();
}
}

private void explodeFuelTank (AiAircraft aircraft)
{
if (aircraft != null)
{
aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);
}
}

private void destroyAiControlledPlane (AiAircraft aircraft) {
if (isAiControlledPlane (aircraft)) {
destroyPlane (aircraft);
}
}

private void damageAiControlledPlane (AiActor actor) {
if (actor == null || !(actor is AiAircraft)) {
return;
}

AiAircraft aircraft = (actor as AiAircraft);

if (!isAiControlledPlane (aircraft)) {
return;
}

if (aircraft == null) {
return;
}

aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);
aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);
aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);
aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
for (int i = 0; i < iNumOfEngines; i++)
{
aircraft.hitNamed((part.NamedDamageTypes)Enum.Pars e(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
}

/***Timeout (240, () =>
{explodeFuelTank (aircraft);}
);
* ***/

Timeout (300, () =>
{destroyPlane (aircraft);}
);
}

public override void Init(maddox.game.ABattle battle, int missionNumber)
{
base.Init(battle, missionNumber);
MissionNumberListener = -1; //Listen to events of every mission
}

Thx all

Smokeynz
03-19-2012, 07:03 PM
Ai will interfere with player detection, players are actors aswell.

However I believe actions are for ai actions, for players you need another piece

This bit enables resetting of a trigger , true to keep alive, false to turn off
People use the false to stop double activation

GamePlay.gpGetTrigger(shortName).Enable = false;


However asking this if("trigger".Equals(shortName)) also looks for the trigger in both true and false states.
Listing as if("trigger".Equals(shortName) && Active) will look for true trigger in true only.


Because you are basically always using the trigger to activate the code you might find you also need a reference to the trigger, so may have to combine the 2 methods following

Re quote from Kodiak


using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{

public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);

AiAction Action = GamePlay.gpGetAction(shortName);

if (Action != null)
Action.Do();

GamePlay.gpGetTrigger(shortName).Enable = false;
}
}



Try this



using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;

public class Mission : AMission
{
public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);


if("trigger".Equals(shortName) && Active)
{

GamePlay.gpPostMissionLoad("missions/etc/etc/MissionName.mis"); // load sub mission as result of player

AiAction Action = GamePlay.gpGetAction(shortName); // note this shortname is action shortname and ai response
if (Action != null)
Action.Do();

}

}

}

melasuda
03-19-2012, 10:55 PM
OK, but if I understand.
The flights activated by human need put in a submission

or it is not necessary?

because all tiggres, Ia and human i have put on same mision.

thx

Smokeynz
03-19-2012, 11:26 PM
Yeah, bare in mind there is no documention regarding what each function is actually intended for, so many experiement to find out by trial and error to see what happens.

As noted before the action function seems to work(best) with ai actors.
(I could be wrong aswell, just haven't found reason why yet)
Generally it is used to create repeating ai cycles, the ai airgroup reaches trigger point and new group spawns and repeats.

Don't be afraid of using many small sub missions to do spawning, add in objects etc. In fact using sub missions has many advantages over using the main master mission for everything.

By utilising the trigger reponse to activate other cs code you can hijack the trigger to do far more operations in general.

Also note there are also bugs in source, and we find some things work in player server hosted then they don't work in dedicated hosting.

In general, the trigger/actions are simple setup operations for fairly simple mission design. (although it can be part of a larger set of missions).

There is a legacy hangover with old il246 mission design, many are trying to do everything in one mission. The basic problem with this is one mission can get large and very complex. By breaking aspects into sub missions, loaded by timers or triggers you lower the individual mission design difficulty.

Back to trigger and action, check you are using the correct trigger event.
You can trigger by army, passthrough, player etc.
Noting there is limits to this, for example you can't set to player and army, so army will allow ai aswell as players, also in army setup, if the ai get to the trigger first they interfere with player detection.

This is to do with the trigger, not the action.

I have a method of cs code where I bypass the trigger. The trigger is alive always and I reference the same location, but I treat ai and players separately in the cs code. In this way interferance is limited.

sorry if some of this is confusing(language as well)

melasuda
03-20-2012, 01:15 PM
thanks for the reply, it's all very clear.

Now I'm editing the mission, to put all activated human flight in sub missions.