Log in

View Full Version : Investigation into multi Spawn of same chief naming???


hc_wolf
03-12-2012, 05:22 AM
Hi,

I have a curly one.

I have a script that works fine on individual triggers. But I want to bundle two triggers together.

1) So the first thing is a group spawn 11_Chief
2) Then it triggers an action "action1 ASpawnGroup 0 11_Chief"

3) Since 11_Chief already exists it spawns IN GAME a 1:11_Chief when you right click on the screen and view vheicles you see this.

4) The issue is when you look below I have named trigger Target1_1 1:Chief but it does not recognise that as the valid name in game to set the trigger off.

Anyone know what naming the 1:11_Chief should be in the below trigger area???


I know i can just hard code a second chief called 12_Chief but that is not what I want. Anyone know what the TRIGGER 1:11_Chief should be in .mis file. I have tried these and they don't seem to work

below do't work.:confused:
Target1_1 TGroupDestroyed 1:11_Chief 100
Target1_1 TGroupDestroyed _11_Chief 100
Target1_1 TGroupDestroyed 1_11_Chief 100
Target1_1 TGroupDestroyed 11_1_Chief 100




[Trigger]
Target1 TGroupDestroyed 11_Chief 100
Target1_1 TGroupDestroyed 1:11_Chief 100

[Action]
action1 ASpawnGroup 0 11_Chief


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


if (("Target1".Equals(shortName) && active) && ("Target1_1".Equals(shortName) && active))

{
GamePlay.gpHUDLogCenter("Column destroyed!!!");
GamePlay.gpGetTrigger(shortName).Enable = false;

}

FG28_Kodiak
03-12-2012, 05:50 AM
When you spawn a Group via action its the same as you load a submission. The 1: is the number of this submission (you can get the next Missionnumber with GamePlay.gpNextMissionNumber()). So the first Question is do you have MissionNumberListener = -1?

Smokeynz
03-12-2012, 05:54 AM
good point Kodiak

From my limited experience each occurance of an object, no matter what it is has an internal identifer related to mission number, shortname and active.

Anyway your code may be asking the wrong question, && is adding both objects together" object and object", using | is syntax for "or" so you would then be "object or object"

I might also add read this thread refering to trigger spawning, I see a few differences to your current script which may be helpful.
http://forum.1cpublishing.eu/showthread.php?t=26515

hc_wolf
03-12-2012, 06:40 AM
Hi guys, hope you would be on reading this.

Yes I forgot to add MissionNumberListener = -1 to this smaller script for testing but it is in the larger one.

I do not import a new mission on trigger it is all run from the one mission and .cs file.


Also I want the syntax for 'AND' not 'OR' cause I want it to say that objective is complete if Target 1 & Target 2 are triggered. So the Syntax for 'AND' is && or something else?

So it registers that both triggers destroy and so both triggers are active as i changed
Target1_1 TGroupDestroyed 11_Chief 100

But this is not correct also. So I think I wil have go to with two separate Chiefs and not a respawn of the first as both Trigger 1 and two refer to the same group and the groups are dont individually designed like 10Cheif and 11_Cheif


will read the link now.

Thanks guys

FG28_Kodiak
03-12-2012, 07:00 AM
Ah ok a little misinterpretion


first
if (("Target1".Equals(shortName) && active) && ("Target1_1".Equals(shortName) && active))

couldnt work there is only one shortName it could be Target1 or Target1_1 but never both.

So you can create a global bool variable.
Example
bool Target1triggered = false;
bool Target1_1triggered = false;


then in Ontrigger you can set
if ("Target1".Equals(shortName) && active)
{
Target1triggered = true;
}

if ("Target1_1".Equals(shortName) && active)
{
Target1_1triggered = true;
}

if (Target1triggered && Target1_1triggered)
{
// Your code
}

Or you check if the Trigger is enabled, normaly the trigger will be disabled (not the PassThru-Trigger) after activation.
if (GamePlay.gpGetTrigger("Trigger1").Enable == false && GamePlay.gpGetTrigger("Target1_1").Enable == false)
should became true

hc_wolf
03-12-2012, 07:05 AM
You Wizzards of Code! Ok will put this together and test. let you know in a little while

Smokeynz
03-12-2012, 08:51 AM
Isnt he sneaky :)

wildwillie
03-14-2012, 05:29 PM
When you spawn a Group via action its the same as you load a submission. The 1: is the number of this submission (you can get the next Missionnumber with GamePlay.gpNextMissionNumber())

From my testing, the 1: occurs when there are duplicate Objects created with the same name. If you spawn in your plane name will be something like:

0:BoB_LW_StG77_Stab.000

after you land/crash/etc and create a new plane this one will be named:

1:BoB_LW_StG77_Stab.000
then next time
2:BoB_LW_StG77_Stab.000
etc.


This also occurs with AI planes created using sub missions.

WildWillie

Smokeynz
03-14-2012, 08:29 PM
I thought about this a bit more, I think you can solve this by creating a separate void

The trick is keep the 2 triggers separate, but instead of calling the action or text from the trigger call a void
You need a bool or interger count in the trigger to act as a reference that the condition has been met then call the void

within the void have conditional if statement or switch, in the case of each bool or interger count being this state or value then call the result if it hasnt had both triggers call yet nothing happens, or you could call a text message "half the column destroyed" .

the following might work, it is something I use for other things, but no real reason this wont work here for this.
code itself may require tweaking a little, but you get the idea





private int column;

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

if ("Target1".Equals(shortName) && active)
{
column = column + 1;
callcolumn();
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if ("Target1_1".Equals(shortName) && active)
{
column = column + 1;
callcolumn();
GamePlay.gpGetTrigger(shortName).Enable = false;
}

}

private void callcolumn()
{

switch (column)
{
case 1
GamePlay.gpHUDLogCenter(" Half the Column destroyed!!!");

break;
case 2
column = 0;
GamePlay.gpHUDLogCenter("Column destroyed!!!");

break;
}

}



updated with minor corrections

hc_wolf
03-14-2012, 09:14 PM
Hey Smokeynz,

I got the full script working based on Kodiak's script above with a little tweaking, but was only working if the chiefs spawned from the beginning of the battle. If the Chiefs were flagged to 'spawn on sctipt' the triggers would not activate.

So I have it all working great with the "bool Target1_1triggered = false;" script above.

Kodiak came back to me with a possible fix to make the triggers activate if chiefs 'Spawn from script'. I gave it a quick go this morning before work but did not activate triggers, will test properly tonight.

I will also give yours a shot as it is a different approach and would be interesting to see if "on the whole" it is a neater script or not. Will keep you both informed and send you the test mission tonight if I am stuck.

Smokeynz
03-14-2012, 09:57 PM
yes both work, the difference notwithstanding a little more complex with a void and switch, is it catches the half completed case for your outcome, and also you could add more triggers, like switch(column) for cases of 3, 4, 5, 6 and so on then do different things at different levels.

In this way you can also have other trigger results interact with main counter.
Case selection can be more useful when you want it more flexible for different outcomes.

A bool is true or false, so you really have only 2 states or maybe an elseif as a third. bool true and falses can end up in sequential if statements and you can trap yourself

hc_wolf
03-14-2012, 10:03 PM
Awesome I understand, I am keen to put your code together and see how it works. Will try tonight :D thanks Smokeynz

FG28_Kodiak
03-15-2012, 08:43 AM
Made some test with the TGroupDestroyed trigger
Found a additional problem with the TGroupDestroyed trigger, the trigger is only active before the group reached the endpoint. On the endpoint the trigger is automaticaly disabled. Seems to be a feature and not a bug, but i think its good to know.

One of my test the 0_Chief had the shortest way (few meters), i don't destroy any target, only fly around. After the trigger is disabled automatically it no longer possible to activate the trigger.
Server: Des_1 Trigger: True
Server: Des_2 Trigger: True
Server: Des_3 Trigger: True
Server: --------------------------
Server: Des_1 Trigger: True
Server: Des_2 Trigger: True
Server: Des_3 Trigger: True
Server: --------------------------
Server: Des_1 Trigger: True
Server: Des_2 Trigger: True
Server: Des_3 Trigger: True
Server: --------------------------
Server: Des_1 Trigger: True
Server: Des_2 Trigger: True
Server: Des_3 Trigger: True
Server: --------------------------
Server: Des_1 Trigger: False
Server: Des_2 Trigger: True
Server: Des_3 Trigger: True
Server: --------------------------
Server: Die Schlacht ist beendet.


My testscript and mission, the script shows the state of trigger every 10sec. :


[PARTS]
core.100
bob.100
[MAIN]
MAP Land$English_Channel_1940
BattleArea 251703 183294 91819 60561 10000
TIME 12
WeatherIndex 0
CloudsHeight 1000
BreezeActivity 10
ThermalActivity 10
player BoB_LW_LG2_I.000
[GlobalWind_0]
Power 3.000 0.000 0.000
BottomBound 0.00
TopBound 1500.00
GustPower 5
GustAngle 45
[splines]
[AirGroups]
BoB_LW_LG2_I.01
[BoB_LW_LG2_I.01]
Flight0 1
Class Aircraft.Bf-109E-4
Formation FINGERFOUR
CallSign 26
Fuel 100
Weapons 1
Skill 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
[BoB_LW_LG2_I.01_Way]
NORMFLY 288810.19 211014.55 500.00 300.00
NORMFLY 290995.02 216329.47 500.00 300.00
[CustomChiefs]
[Chiefs]
0_Chief Vehicle.AEC_Matador gb
2_Chief Vehicle.AEC_Matador gb
1_Chief Vehicle.AEC_Matador gb
[0_Chief_Road]
291352.13 215913.05 38.40 0 2 4.17
291328.78 215953.20 38.40
[2_Chief_Road]
291173.38 215887.72 38.40 0 5 2.08
S 2563 0 0.80 40.00 P 291185.31 215916.13
S 2563 0 0.62 20.00 P 291263.63 216119.81
S 2563 0 0.24 20.00 P 291455.81 216619.78
291470.13 216668.56 38.40
[1_Chief_Road]
291638.69 216413.20 38.40 0 7 4.17
S 2564 0 0.25 20.00 P 291552.34 216412.75
S 2564 0 0.32 20.00 P 291449.75 216409.33
S 2564 0 0.50 20.00 P 291139.50 216399.00
S 2562 0 0.58 20.00 P 291026.44 216393.27
S 2562 0 0.84 40.00 P 290816.22 216703.83
290805.72 216727.70 38.40
[Stationary]
[Buildings]
[BuildingsLinks]
[Trigger]
Des_1 TGroupDestroyed 0_Chief 50
Des_2 TGroupDestroyed 1_Chief 50
Des_3 TGroupDestroyed 2_Chief 50



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

public class Mission : AMission
{
Stopwatch MessageTimer = new Stopwatch();

public override void OnBattleStarted()
{
base.OnBattleStarted();

MessageTimer.Start();
MissionNumberListener = -1;
}


public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
{
base.OnActorDead(missionNumber, shortName, actor, damages);
GamePlay.gpLogServer(null, "Actor: {0}", new object[] { actor.Name() });
}


public override void OnTickGame()
{
base.OnTickGame();

if (MessageTimer.Elapsed.TotalSeconds >= 10)
{
GamePlay.gpLogServer(null, "Des_1 Trigger: {0}", new object[] { GamePlay.gpGetTrigger("Des_1").Enable.ToString() });
GamePlay.gpLogServer(null, "Des_2 Trigger: {0}", new object[] { GamePlay.gpGetTrigger("Des_2").Enable.ToString() });
GamePlay.gpLogServer(null, "Des_3 Trigger: {0}", new object[] { GamePlay.gpGetTrigger("Des_3").Enable.ToString() });
GamePlay.gpLogServer(null, "--------------------------", null);
MessageTimer.Restart();
}
}


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

GamePlay.gpLogServer(null, "Trigger: {0}", new object[] { shortName });
GamePlay.gpHUDLogCenter(null, "Trigger: {0}", new object[] { shortName });

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

}

Smokeynz
03-15-2012, 07:10 PM
Interesting, although not unexpected considering the detroyed trigger task is to activate on object destroyed, I mean how many times must it be kaput!

Probably a worth while exercise to look at all triggers in a similar way to see what "features" they have.

For example, for the pass through trigger, from what I've seen it can be handled in a number of ways.

if (shortName.Equals(shortName) && active)
{
//do somthing
GamePlay.gpGetTrigger(shortName).Enable = false;
}

if you use only the following ,You can use the trigger in both true and false and it is always live.

if (shortName.Equals(shortName))
{
//do somthing
}


if you use only the following , it appears to only activate on true
if (shortName.Equals(shortName) && active)
{
//do somthing
}

if you use only the following , it appears to only activate on true and disabled after use

if (shortName.Equals(shortName) && active)
{
//do somthing
GamePlay.gpGetTrigger(shortName).Enable = false;
}

So with that in mind, maybe leaving the following out of the destroy trigger it will stay live.
GamePlay.gpGetTrigger(shortName).Enable = false;

hc_wolf
03-16-2012, 04:06 AM
That is a very good point. I have completed the scripting and have it working for the moment, and is now uploaded on the ATAG test system (Destroy or defend the convoys).

But this find up here could tidy up the script a little or make for easier implementation.



I think i have to read the above or draw some diagrams to get my head around it hehehe. Will run your test tonight