PDA

View Full Version : how to action damage, only to the players plane, when they trigger a passthrough



Sods
Dec-22-2013, 09:04
Please HELP!!!!

My aim... to do damage to an aircraft when that aircraft triggers the passthrough

I have Scrip to damage an airplane...


private void DamageAirplane(AiAircraft aircraft)
{
Timeout(5, () =>
{
if (aircraft != null)
{
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);

}
});
}


I have a trigger set to trigger the event using pass through in FMB.
The script starts with "if ("Damage".Equals(shortName) && active)" but the more I play with what follows these lines the further away I am in making it work. to give you some idea at the moment if I host and another player triggers the pass through, his aircraft does not get damaged but MINE DOES!!!!! lol. :)

so please any help would be greatly appreciated.

If its not possible using a passthrough as one of my team members suggested, could it be done via coordinates ?

thanks in advance!!!!!

PS love ATAG!!!! :D

Salmo
Dec-22-2013, 21:13
It's possible to damage an aircraft using a passthrough trigger. The problem is that the trigger method passes the mission number, trigger name & whether the trigger is active or not. It does not pass the AiActor (aircraft) that triggered the trigger, so we need to find a way to get that aircraft then damage it.

The pseudocode is something like this ...
1. Has the trigger gone off?
2. If yes, then cycle through all aircraft in the game & see if any are inside the trigger radius (get trigger x, y & radius from mission file text).
3. If inside the trigger radius then damage the aircraft.



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

if (shortName == "MyTrigger" && active)
{
foreach (int army in GamePlay.gpArmies())
{
foreach (AiAirGroup group in GamePlay.gpAirGroups(army))
{
foreach (AiAircraft aircraft in group.GetItems())
{
if (aircraft != null)
{
point3d trigger;
double radius = 123; // trigger radius
trigger.x = 123; // trigger x point
trigger.y = 123; // trigger y point
trigger.z = aircraft.Pos().z; // use aircraft alt
if (aircraft.Pos().distance(ref trigger) <= radius)
{
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);
}
}
}
}
}
}
}

Sods
Dec-23-2013, 03:56
Salmo you are a star, i am at work at the moment but i will try this later tonight. thx for your reply it's very much Appreciated.

SoW Reddog
Dec-23-2013, 14:11
Good in practice, however it's going to trigger for every plane in the trigger. You probably want to check only for the nearest to the centre if you want a single "victim" Sods.

Salmo
Dec-23-2013, 18:42
Good in practice, however it's going to trigger for every plane in the trigger.
Correct. I assume Sods wants to damage any aircraft that enters the trigger zone.


You probably want to check only for the nearest to the centre if you want a single "victim" Sods.
The trigger is activated the moment an aircraft enters the trigger zone, so the target aircraft would be the one that is closest to the trigger zone perimeter not the centre.

Sods
Dec-24-2013, 19:05
HI ALL MERRY CHRISTMASS!!!!!!

Hi Salmo you are correct...
Correct. I assume Sods wants to damage any aircraft that enters the trigger zone.

the only issue is... that for me this script does not work, so because I am having so much of an issue in getting this to work I must assume its to do with my server settings but not sure.
my original script, which is different to yours, had the same out come... only I get the damage if I trigger the event. then after much messing about and re-writing I eventually got
another player triggers the pass through, his aircraft does not get damaged but MINE DOES
so with your script last night I got some one to get into a game I was hosting with a slightly modified script just so that I could see what the issue was. to cut a long story short when another player triggered the event using the script below I could see the trigger message with the correct player name
aircraft.Player(0).Name() but no damage was done to their aircraft. But if I triggered it then my name appeared and damaged was done to my aircraft. Also, after the trigger zone was 1st activated then it no longer worked ie no matter who flew through the trigger zone I no longer had any messages.

So maybe its something to do with how my server works I am really not sure!

FYI the last time I tried it, these were the only lines in my cs file with no change to the outcome mentioned above.... IF THIS WORKS FOR ANY ONE ELSE PLEASE LET ME KNOW!




using System;
using System.Collections.Generic;
using System.Text;
using maddox.game;
using maddox.game.world;
using maddox.GP;
using System.Threading;
using System.IO;


public class Mission : maddox.game.AMission
{

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

if (shortName == "Damage" && active)
{
//GamePlay.gpHUDLogCenter("Damage 1.");
foreach (int army in GamePlay.gpArmies())
{
foreach (AiAirGroup group in GamePlay.gpAirGroups(army))
{
foreach (AiAircraft aircraft in group.GetItems())
{
if (aircraft.Player(0) != null)
{
Point3d trigger;
double radius = 4100; // trigger radius
trigger.x = 60746; // trigger x point
trigger.y = 228251; // trigger y point
trigger.z = aircraft.Pos().z; // use aircraft alt
if (aircraft.Pos().distance(ref trigger) <= radius)
{
GamePlay.gpHUDLogCenter(aircraft.Player(0).Name() + " Triggered the event.");
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);
}
}
}
}
}
}
}
}


Merry Christmas guys!!!

Sods
Dec-24-2013, 19:10
aa

Salmo
Dec-24-2013, 19:22
HI ALL MERRY CHRISTMASS!!!!!!

Hi Salmo you are correct...

the only issue is... that for me this script does not work, so because I am having so much of an issue in getting this to work I must assume its to do with my server settings but not sure.
my original script, which is different to yours, had the same out come... only I get the damage if I trigger the event. then after much messing about and re-writing I eventually got
so with your script last night I got some one to get into a game I was hosting with a slightly modified script just so that I could see what the issue was. to cut a long story short when another player triggered the event using the script below I could see the trigger message with the correct player name
aircraft.Player(0).Name() but no damage was done to their aircraft. But if I triggered it then my name appeared and damaged was done to my aircraft. Also, after the trigger zone was 1st activated then it no longer worked ie no matter who flew through the trigger zone I no longer had any messages.

So maybe its something to do with how my server works I am really not sure!

FYI the last time I tried it, these were the only lines in my cs file with no change to the outcome mentioned above.... IF THIS WORKS FOR ANY ONE ELSE PLEASE LET ME KNOW!




using System;
using System.Collections.Generic;
using System.Text;
using maddox.game;
using maddox.game.world;
using maddox.GP;
using System.Threading;
using System.IO;


public class Mission : maddox.game.AMission
{

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

if (shortName == "Damage" && active)
{
//GamePlay.gpHUDLogCenter("Damage 1.");
foreach (int army in GamePlay.gpArmies())
{
foreach (AiAirGroup group in GamePlay.gpAirGroups(army))
{
foreach (AiAircraft aircraft in group.GetItems())
{
if (aircraft.Player(0) != null)
{
Point3d trigger;
double radius = 4100; // trigger radius
trigger.x = 60746; // trigger x point
trigger.y = 228251; // trigger y point
trigger.z = aircraft.Pos().z; // use aircraft alt
if (aircraft.Pos().distance(ref trigger) <= radius)
{
GamePlay.gpHUDLogCenter(aircraft.Player(0).Name() + " Triggered the event.");
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);
}
}
}
}
}
}
}
}


Merry Christmas guys!!!

Now that's really odd? Your saying that the trigger correctly identifies the plane setting it off but that the hitnamedpart command does not work for anyone other than the host. Wonder if this is a hitherto unknown game bug?

You can overcome the trigger works once-only issue by adding this line after the hitnamedpart command ...


GamePlay.gpGetTrigger("damage").Enable = true;

Sods
Dec-24-2013, 19:58
Hi Salmo I hope you are having a good Xmass.


Now that's really odd? Your saying that the trigger correctly identifies the plane setting it off but that the hitnamedpart command does not work for anyone other than the host. Wonder if this is a hitherto unknown game bug? I am thinking that it has something to do with my server setting but yes I am thinking the same. for sure its only me that that's getting damage because the script I wrote with this out come...
if I host and another player triggers the pass through, his aircraft does not get damaged but MINE DOES! every players plane on the server should receive damage. but this was not the case.
When I get time and I can get some one to test ill try the aircraft.cutLimb method

Sods
Dec-24-2013, 22:13
When I get time and I can get some one to test ill try the aircraft.cutLimb method
I have been lucky! a team member just came on comms and I was able to try this method IT WORKS!!!!!!!!!!!!!!!:D

thx Salmo I guess that you would need to report this as I am sure its a bug now.

for others that need the script...


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

if (shortName == "MyTrigger" && active)
{
foreach (int army in GamePlay.gpArmies())
{
foreach (AiAirGroup group in GamePlay.gpAirGroups(army))
{
foreach (AiAircraft aircraft in group.GetItems())
{
if (aircraft != null)
{
point3d trigger;
double radius = 123; // trigger radius
trigger.x = 123; // trigger x point
trigger.y = 123; // trigger y point
trigger.z = aircraft.Pos().z; // use aircraft alt
if (aircraft.Pos().distance(ref trigger) <= radius)
{
aircraft.cutLimb(part.LimbNames.AileronL0);
aircraft.cutLimb(part.LimbNames.AileronR0);
}
}
}
}
}
}
}