Jump to content
Sign in to follow this  
puzzola

Teamswitch and tasks

Recommended Posts

Hi, I read a lot of topics but non solved yet.

I have a SP mission with team switch possible.

The briefing works fine but when I switch player, tasks don't show up anymore.

How I set again tasks for the player, whatever role he takes?

Maybe something in the init.sqf?

Thank you ;)

Here's my briefing.sqf

player createDiaryRecord["Diary", ["Info", "<br/>Author - Puzzola<br/>Version 2.0<br/>"]];

player createDiaryRecord["Diary", ["Forze nemiche", "<br/>Alcune unita' di fanteria e blindati dell' SLA col supporto di alcuni agenti OMON russi."]];

player createDiaryRecord["Diary", ["Forze amiche", "<br/>A capo di una unita' mista di para' della Folgore e incursori del Col Moschin."]];

player createDiaryRecord["Diary", ["Missione", "<br/>Parti a bordo di un C-27 Spartan dell'aereonautica italiana. Una volta raggiunta la LZ a NE di Bagango, paracadutati e distruggi lo Shilka che assicura protezione antiaerea alla citta' e dai il via libera all'assalto elitrasportato dei bersaglieri. Resisti e aspetta che le unita' alleate prendano posizione. A questo punto incursori o bersaglieri devono distruggere l'antenna radar che e' protetta da regolari dell'SLA. Una volta distrutta saranno disponibili i comandi radio per richiedere l'esfiltrazione degli incursori a nord e delle unita' di bersaglieri, nel frattempo riunite in una unica unita', a Ovest-sud-ovest. Una volta rientrati alla base fare rapporto agli ufficiali in attesa."]];

player createDiaryRecord["Diary", ["Situazione", "<br/>Quattro AB212 con a bordo altrettante squadre aspettano il nostro ok via radio per iniziare l'assalto."]];

player createDiaryRecord["Diary", ["Suggerimenti", "<br/>Utilizza il tempo sul C-27 per scegliere il tuo equipaggiamento. Controlla ogni tanto la radio 0-0."]];

// Finale

tskWestObj6 = player createSimpleTask ["Finale: Bisboccia"];

tskWestObj6 setSimpleTaskDescription ["Raggiungi le ragazze sul bus"];

// Conclusione missione

tskWestObj5 = player createSimpleTask ["Conclusione: Fare rapporto"];

tskWestObj5 setSimpleTaskDescription ["Raggiungi gli ufficiali agli hangar per fare rapporto"];

tskWestObj5 setSimpleTaskDestination (getMarkerPos "Rapporto");

// Obiettivo secondario Incursori

tskWestObj4 = player createSimpleTask ["#2 Inc.: Rimanere in vita ed esfiltrare"];

tskWestObj4 setSimpleTaskDescription ["Una volta certi che la postazione radar sia distrutta e che i bersaglieri siano in rotta verso la base, portarsi in zona di esfiltrazione e chiamare il recupero. "];

tskWestObj4 setSimpleTaskDestination (getMarkerPos "Esfiltrare_inc");

// Obiettivo secondario Bersaglieri

tskWestObj3 = player createSimpleTask ["#2 Bers.: Congiungere le squadre"];

tskWestObj3 setSimpleTaskDescription ["Prendi sotto il tuo comando tutte le squadre di Bersaglieri"];

tskWestObj3 setSimpleTaskDestination (getMarkerPos "raggruppamento");

// Obiettivo principale Bersaglieri

tskWestObj2 = player createSimpleTask ["#1 Bersaglieri: Distruggere il radar"];

tskWestObj2 setSimpleTaskDescription ["Distruggi l'antenna radar nell'atrio del municipio"];

tskWestObj2 setSimpleTaskDestination (getMarkerPos "Radar");

// Obiettivo principale Incursori

tskWestObj1 = player createSimpleTask ["#1 Incursori: Distruggere lo Shilka"];

tskWestObj1 setSimpleTaskDescription ["Elimina lo Shilka e dai il via libera all'eliassalto"];

tskWestObj1 setSimpleTaskDestination (getMarkerPos "Shilka");

//>---------------------------------------------------------<

Edited by puzzola

Share this post


Link to post
Share on other sites

Kylania has probably had a lot more experience dealing with team switch than me so I will default to his assessment, but you might want to try using onTeamSwitch.

This is what you would need to do:

1) Put your task code in a separate script (not in briefing.sqf), for this example let's call it tasks.sqf.

2) In your init.sqf, execute your briefing.sqf AND tasks.sqf.

3) In your init.sqf, place the following line of code:

onTeamSwitch {execVM "tasks.sqf";};

The above code will cause tasks.sqf to execute every time a player team switches (it is like an event handler for team switching). I have not use onTeamSwitch with tasks, but I have used it with other code I need ensure is run when a player team switches.

The only thing I do not see in your code, is how you setTaskState "SUCCEEDED". You will need to be careful with that so that completed tasks are not overridden every time you team switch. Hope this helps...good luck!

Share this post


Link to post
Share on other sites
Kylania has probably had a lot more experience dealing with team switch than me so I will default to his assessment, but you might want to try using onTeamSwitch.

This is what you would need to do:

1) Put your task code in a separate script (not in briefing.sqf), for this example let's call it tasks.sqf.

2) In your init.sqf, execute your briefing.sqf AND tasks.sqf.

3) In your init.sqf, place the following line of code:

onTeamSwitch {execVM "tasks.sqf";};

The above code will cause tasks.sqf to execute every time a player team switches (it is like an event handler for team switching). I have not use onTeamSwitch with tasks, but I have used it with other code I need ensure is run when a player team switches.

The only thing I do not see in your code, is how you setTaskState "SUCCEEDED". You will need to be careful with that so that completed tasks are not overridden every time you team switch. Hope this helps...good luck!

It's worth a try. Thank you very much.

About tasks status, I forget it. Thank you again for remembering.

Share this post


Link to post
Share on other sites

Another option would be to maintain your tasks for _all_ playable/switchable units simulatiously and from the beginning, instead of maintaining only the current players character.

This approach might be more robust or less complicated in the end, than simply execVM'ing tasks.sqf onTeamSwitch. What happens if you switch back to a unit?

On the otherhand, you can't simply add new units to this list - or, you again end up with the need to run some special onTeamSwitch init script to catch up with all your stuff... and then you eventually need to keep track of all diary/task stuff by yourself, building your own diary/task-layer ontop of the existing commands.

Share this post


Link to post
Share on other sites
Another option would be to maintain your tasks for _all_ playable/switchable units simulatiously and from the beginning, instead of maintaining only the current players character.

This approach might be more robust or less complicated in the end, than simply execVM'ing tasks.sqf onTeamSwitch. What happens if you switch back to a unit?

On the otherhand, you can't simply add new units to this list - or, you again end up with the need to run some special onTeamSwitch init script to catch up with all your stuff... and then you eventually need to keep track of all diary/task stuff by yourself, building your own diary/task-layer ontop of the existing commands.

I can try this too.

I wouldn't that assigning the tasks to the playable units makes them invisible to player.

Edited by puzzola

Share this post


Link to post
Share on other sites

Ok, we are on the right path.

I made a tasks.sqf where I put the tasks; and added in the init.sqf onTeamSwitch {execVM "tasks.sqf";};

Now when I switch unit the tasks are still in display.

But...If I delete the tasks from my briefing.sqf, they don't show for the first unit (default player) till I don't switch to another and go back to it.

If I leave the tasks in the briefing.sqf, it starts ok, I have them if I switch but if I go back to the first unit, they are doubled :p

Now I'm tinking about a command to set the tasks once at start and then onteamswitch.

Suggestions?

Share this post


Link to post
Share on other sites
Try adding this to init.sqf BEFORE executing tasks.sqf

waitUntil {!isNull player};

Thank you. I'll try.

In the meanwhile i made some tests.

With the onswitch command everytime i return on a unit the task adds, and adds and adds :p

I have the taskstatus "succeeded" on the activation field of some triggers and they work, don't know if they are mantained on teamswitch.

I'll see

Share this post


Link to post
Share on other sites

This is probably why Kylania said to give up! LOL. I have a few ideas. Let me think for a bit.

EDIT:

OK, try this...it is untested and adds more code but perhaps it will work. Put a line like this (but changing the variable name) before each one of your createSimpleTask lines in tasks.sqf:

 if (!isnil ("tskWestObj1")) then {player removeSimpleTask tskWestObj1};

This will check if the task handle is nil...if it is NOT (which means the task has been created already) it removes the task from the player before creating a new new one. Don't forget to change the variable name in both places.

Edited by Loyalguard
removeSimpleTask option added.

Share this post


Link to post
Share on other sites

I'm also trying to get this sorted for a SP mission. I thought it would be quite easy.

I update the task with task1 setTaskState "SUCCEEDED" which works.

I was then trying to use taskstate but no matter how I use it nothing works.

I've tested the following and none of them do anything, even the hint does nothing.

if (taskState Task1) == "Succeeded" then {hint "working"};

waitUntil {(taskState Task1) == "Succeeded"};

Hint format ["%1",taskState Task1];

Share this post


Link to post
Share on other sites

I have some idea...how i set a name for a group?

Example the player is named inc1, I would like to set a task for inc1 group

Share this post


Link to post
Share on other sites

createSimpleTask takes an object, not a group, as the argument so you'd have to loop through the group.

Share this post


Link to post
Share on other sites

@F2K: I am not sure why the hint is not working. For the other tests, on a whim, try the uppercase version "SUCCEEDED".

The other thing you may want to try is to use a global variable to determine/track task state instead of the task state itself.

Share this post


Link to post
Share on other sites
@F2K: I am not sure why the hint is not working. For the other tests, on a whim, try the uppercase version "SUCCEEDED".

The other thing you may want to try is to use a global variable to determine/track task state instead of the task state itself.

yea I just worked it out, it won't work after a teamswitch, I guess it's local to the original player unit..

Share this post


Link to post
Share on other sites
createSimpleTask takes an object, not a group, as the argument so you'd have to loop through the group.

Today I read a way to moveincargo a group named by its leader.

I don't find it anymore.

Can you please find it for me?

Upgrade:

Now I have:

Init.sqf:

//begin init.sqf

//Add briefing
execVM "briefing.sqf";

//Add tasks
onTeamSwitch {execVM "tasks.sqf";};

Briefing.sqf:

player createDiaryRecord["Diary", ["Info", "<br/>Author - Puzzola<br/>Version 2.0<br/>"]];
player createDiaryRecord["Diary", ["Forze nemiche", "<br/>Alcune unita' di fanteria e blindati dell' SLA col supporto di alcuni agenti OMON russi."]];
player createDiaryRecord["Diary", ["Forze amiche", "<br/>A capo di una unita' mista di para' della Folgore e incursori del Col Moschin."]];
player createDiaryRecord["Diary", ["Missione", "<br/>Parti a bordo di un C-27 Spartan dell'aereonautica italiana. Una volta raggiunta la LZ a NE di Bagango, paracadutati e distruggi lo Shilka che assicura protezione antiaerea alla citta' e dai il via libera all'assalto elitrasportato dei bersaglieri. Resisti e aspetta che le unita' alleate prendano posizione. A questo punto incursori o bersaglieri devono distruggere l'antenna radar che e' protetta da regolari dell'SLA. Una volta distrutta saranno disponibili i comandi radio per richiedere l'esfiltrazione degli incursori a nord e delle unita' di bersaglieri, nel frattempo riunite in una unica unita', a Ovest-sud-ovest. Una volta rientrati alla base fare rapporto agli ufficiali in attesa."]];
player createDiaryRecord["Diary", ["Situazione", "<br/>Quattro AB212 con a bordo altrettante squadre aspettano il nostro ok via radio per iniziare l'assalto."]];
player createDiaryRecord["Diary", ["Suggerimenti", "<br/>Utilizza il tempo sul C-27 per scegliere il tuo equipaggiamento. Controlla ogni tanto la radio 0-0."]];

// Finale
tskWestObj6 = player createSimpleTask ["Finale: Bisboccia"]; 
tskWestObj6 setSimpleTaskDescription ["Raggiungi le ragazze sul bus"];
// Conclusione missione
tskWestObj5 = player createSimpleTask ["Conclusione: Fare rapporto"]; 
tskWestObj5 setSimpleTaskDescription ["Raggiungi gli ufficiali agli hangar per fare rapporto"];
tskWestObj5 setSimpleTaskDestination (getMarkerPos "Rapporto");
// Obiettivo secondario Incursori
tskWestObj4 = player createSimpleTask ["#2 Inc.: Rimanere in vita ed esfiltrare"]; 
tskWestObj4 setSimpleTaskDescription ["Una volta certi che la postazione radar sia distrutta e che i bersaglieri siano in rotta verso la base, portarsi in zona di esfiltrazione e chiamare il recupero. "];
tskWestObj4 setSimpleTaskDestination (getMarkerPos "Esfiltrare_inc");
// Obiettivo secondario Bersaglieri
tskWestObj3 = player createSimpleTask ["#2 Bers.: Congiungere le squadre"]; 
tskWestObj3 setSimpleTaskDescription ["Prendi sotto il tuo comando tutte le squadre di Bersaglieri"];
tskWestObj3 setSimpleTaskDestination (getMarkerPos "raggruppamento");
// Obiettivo principale Bersaglieri
tskWestObj2 = player createSimpleTask ["Distruggere il radar"]; 
tskWestObj2 setSimpleTaskDescription ["Distruggi l'antenna radar nell'atrio del municipio"];
tskWestObj2 setSimpleTaskDestination (getMarkerPos "Radar");
// Obiettivo principale Incursori
tskWestObj1 = player createSimpleTask ["#1 Incursori: Distruggere lo Shilka"]; 
tskWestObj1 setSimpleTaskDescription ["Elimina lo Shilka e dai il via libera all'eliassalto"];
tskWestObj1 setSimpleTaskDestination (getMarkerPos "Shilka");
//>---------------------------------------------------------<

tasks.sqf

// Finale
if (!isnil ("tskWestObj6")) then {player removeSimpleTask tskWestObj6};
tskWestObj6 = player createSimpleTask ["Finale: Bisboccia"]; 
tskWestObj6 setSimpleTaskDescription ["Raggiungi le ragazze sul bus"];
// Conclusione missione
if (!isnil ("tskWestObj5")) then {player removeSimpleTask tskWestObj5};
tskWestObj5 = player createSimpleTask ["Conclusione: Fare rapporto"]; 
tskWestObj5 setSimpleTaskDescription ["Raggiungi gli ufficiali agli hangar per fare rapporto"];
tskWestObj5 setSimpleTaskDestination (getMarkerPos "Rapporto");
// Obiettivo secondario Incursori
if (!isnil ("tskWestObj4")) then {player removeSimpleTask tskWestObj4};
tskWestObj4 = player createSimpleTask ["#2 Inc.: Rimanere in vita ed esfiltrare"]; 
tskWestObj4 setSimpleTaskDescription ["Una volta certi che la postazione radar sia distrutta e che i bersaglieri siano in rotta verso la base, portarsi in zona di esfiltrazione e chiamare il recupero. "];
tskWestObj4 setSimpleTaskDestination (getMarkerPos "Esfiltrare_inc");
// Obiettivo secondario Bersaglieri
if (!isnil ("tskWestObj3")) then {player removeSimpleTask tskWestObj3};
tskWestObj3 = player createSimpleTask ["Bers.: Congiungere le squadre"]; 
tskWestObj3 setSimpleTaskDescription ["Prendi sotto il tuo comando tutte le squadre di Bersaglieri"];
tskWestObj3 setSimpleTaskDestination (getMarkerPos "raggruppamento");
// Obiettivo principale Bersaglieri
if (!isnil ("tskWestObj2")) then {player removeSimpleTask tskWestObj2};
tskWestObj2 = player createSimpleTask ["Distruggere il radar"]; 
tskWestObj2 setSimpleTaskDescription ["Distruggi l'antenna radar nell'atrio del municipio"];
tskWestObj2 setSimpleTaskDestination (getMarkerPos "Radar");
// Obiettivo principale Incursori
if (!isnil ("tskWestObj1")) then {player removeSimpleTask tskWestObj1};
tskWestObj1 = player createSimpleTask ["#1 Incursori: Distruggere lo Shilka"]; 
tskWestObj1 setSimpleTaskDescription ["Elimina lo Shilka e dai il via libera all'eliassalto"];
tskWestObj1 setSimpleTaskDestination (getMarkerPos "Shilka");
//>---------------------------------------------------------<

Mission status as "succedeed" in the OnAct field of opportune triggers and waypoints.

At present status:

All Tasks show on briefing and for the first unit in game.

When I switch team I see tasks yet.

If I go back to a unit I see tasks doubled over and over.

If I complete a task, I have a message on HUD and the task becomes green.

If they were doubled, only the new created are status updated.

I can't show some task for a group and some for another.

---------- Post added at 03:28 AM ---------- Previous post was at 03:12 AM ----------

i'm going to sleep.

Here are 3:00 AM

See you tomorrow

Share this post


Link to post
Share on other sites

The moveInCargo thing is this:

{_x moveInCargo vehicle} forEach units group this;

Share this post


Link to post
Share on other sites
The moveInCargo thing is this:

{_x moveInCargo vehicle} forEach units group this;

Thank you Kylania.

Is it not possible make something similar for the task?

tskWestObj1 = {name createSimpleTask ["#1 Incursori: Distruggere lo Shilka"];} forEach units group this;

---------- Post added at 11:35 AM ---------- Previous post was at 11:31 AM ----------

ruebe already gave you the answer. Add and maintain tasks for all playable/switchable units. Taskmaster does that, so no need to reinvent the wheel.

Example: http://derfel.org/arma2/_puzzola_taskteamswitch.utes.rar

Whats the correct syntax? _all_ playable/switchable

I'll study taskmaster but it is a little bit more complicated than a wheel :p

Thank you very much for the demo mission.

Share this post


Link to post
Share on other sites

For the moment I solved so:

Briefing.sqf

player createDiaryRecord["Diary", ["Info", "<br/>Author - Puzzola<br/>Version 2.0<br/>"]];
player createDiaryRecord["Diary", ["Forze nemiche", "<br/>Alcune unita' di fanteria e blindati dell' SLA col supporto di alcuni agenti OMON russi."]];
player createDiaryRecord["Diary", ["Forze amiche", "<br/>A capo di una unita' mista di para' della Folgore e incursori del Col Moschin."]];
player createDiaryRecord["Diary", ["Missione", "<br/>Parti a bordo di un C-27 Spartan dell'aereonautica italiana. Una volta raggiunta la LZ a NE di Bagango, paracadutati e distruggi lo Shilka che assicura protezione antiaerea alla citta' e dai il via libera all'assalto elitrasportato dei bersaglieri. Resisti e aspetta che le unita' alleate prendano posizione. A questo punto incursori o bersaglieri devono distruggere l'antenna radar che e' protetta da regolari dell'SLA. Una volta distrutta saranno disponibili i comandi radio per richiedere l'esfiltrazione degli incursori a nord e delle unita' di bersaglieri, nel frattempo riunite in una unica unita', a Ovest-sud-ovest. Una volta rientrati alla base fare rapporto agli ufficiali in attesa."]];
player createDiaryRecord["Diary", ["Situazione", "<br/>Quattro AB212 con a bordo altrettante squadre aspettano il nostro ok via radio per iniziare l'assalto."]];
player createDiaryRecord["Diary", ["Suggerimenti", "<br/>Utilizza il tempo sul C-27 per scegliere il tuo equipaggiamento. Controlla ogni tanto la radio 0-0."]];

// Finale
tskWestObj6 = INC1 createSimpleTask ["Finale: Bisboccia"]; 
tskWestObj6 = com1 createSimpleTask ["Finale: Bisboccia"];
tskWestObj6 setSimpleTaskDescription ["Raggiungi le ragazze sul bus"];
// Conclusione missione
tskWestObj5 = INC1 createSimpleTask ["Conclusione: Fare rapporto"];
tskWestObj5 = com1 createSimpleTask ["Conclusione: Fare rapporto"]; 
tskWestObj5 setSimpleTaskDescription ["Raggiungi gli ufficiali agli hangar per fare rapporto"];
tskWestObj5 setSimpleTaskDestination (getMarkerPos "Rapporto");
// Obiettivo secondario Incursori
tskWestObj4 = INC1 createSimpleTask ["#2 Inc.: Rimanere in vita ed esfiltrare"]; 
tskWestObj4 setSimpleTaskDescription ["Una volta certi che la postazione radar sia distrutta e che i bersaglieri siano in rotta verso la base, portarsi in zona di esfiltrazione e chiamare il recupero. "];
tskWestObj4 setSimpleTaskDestination (getMarkerPos "Esfiltrare_inc");
// Obiettivo secondario Bersaglieri
tskWestObj3 = com1 createSimpleTask ["#2 Bers.: Congiungere le squadre"]; 
tskWestObj3 setSimpleTaskDescription ["Prendi sotto il tuo comando tutte le squadre di Bersaglieri"];
tskWestObj3 setSimpleTaskDestination (getMarkerPos "raggruppamento");
// Obiettivo principale Bersaglieri
tskWestObj2 = com1 createSimpleTask ["Distruggere il radar"];
tskWestObj2 = INC1 createSimpleTask ["Distruggere il radar"]; 
tskWestObj2 setSimpleTaskDescription ["Distruggi l'antenna radar nell'atrio del municipio"];
tskWestObj2 setSimpleTaskDestination (getMarkerPos "Radar");
// Obiettivo principale Incursori
tskWestObj1 = INC1 createSimpleTask ["#1 Incursori: Distruggere lo Shilka"]; 
tskWestObj1 setSimpleTaskDescription ["Elimina lo Shilka e dai il via libera all'eliassalto"];
tskWestObj1 setSimpleTaskDestination (getMarkerPos "Shilka");
//>---------------------------------------------------------<

I specified the units that need to see the tasks.

But its not elegant.

By the way, no doubling, no tasks missing.

In another user mission i found this:

if(!isMultiplayer) then
{
	EnableTeamSwitch true;
	addSwitchableUnit player;
	onTeamSwitch
	{	// objects "_from" and "_to" are available
		if(0 == count simpleTasks player) then
		{
			{
				_task = player createSimpleTask[""];
				_task setSimpleTaskDestination ( taskDestination _x ); 
				_task setSimpleTaskDescription taskDescription _x;
				_task setTaskState taskState _x;
			} forEach simpleTasks _from;
		};
		if(!isNull currentTask _from) then
		{
			currTask = currentTask _from;
			player setCurrentTask currentTask _from;
		};			
		{ addSwitchableUnit _x; } forEach units group player;
		group player selectLeader player;
		[] execVM "diary.sqf";
		//[true] execVM "initMission.sqf";
	};
};
};

But I don't understand it enough to adapt.

Last question, 'cause I'm spent.

To show results and statistics at the end of the mission, have I to do something?

I remember some debriefing stuff but at the moment I'm really off.

Edited by puzzola

Share this post


Link to post
Share on other sites

I am fixing two mission to give them to Arremba San Zorzo.

Even if I can play them with no bug, he has two problems.

In one mission a C-27 flying through the mountains crash down (never occurred to me in very high number of tests, nor now).

In the other the game crashes as soon as he select mission and return this error:

Data file too short 'Missions\Free_Ortego_1.5.SaraLite.pbo'. Expected 92196 B, got 87572 B

Edited by puzzola

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×