Jump to content
Sign in to follow this  
golfpro1286

Need help with objective completions.

Recommended Posts

I have tried to search for this, but no luck. I am working on a mission and need to have the completed objectives seen on screen by all member of the Blufor side. Currently it only shows the task completed message on screen to the player who collected evidence or killed the target, not the entire team. Thanks for the help!

Share this post


Link to post
Share on other sites

How can you expect people to help you if you dont post any information of your problem?

-How did you set up the objectives?

-how did you setup the objective completion conditions?

-some detail? (did you make a script or did you just put "objective = someone createSimpleTask ["something"]" to some trigger "on act" area?)

-code?

-screenshots? (If relevant, of course.)

Share this post


Link to post
Share on other sites

Hi,

There are two ways to accomplish that.

(1) Create individually named tasks for each named playable unit rather than a generic task created for player

(2) On the check for the event happening, set a variable to a value and broadcast that value to all participants using a publicVariable statement and update each individually named task

Or

(1) Check for the event, then set a variable to a value and broadcast that value to all participants using a publicVariable statement

(2) Check for the variable being set to that particular value and have the tasks completed

The topmost method has my preference due to its reliability.

Regards,

Sander

Share this post


Link to post
Share on other sites

I ave multiple objectives, all of witch are set up through triggers. Here is an example of one of them.

Cond:

!aliveAdam

OnAct:

"2" objStatus "DONE"; tskobj_2 setTaskState "SUCCEEDED"; player setCurrentTask tskobj_3; obj_3 = true; publicVariable "obj_3";

Then I have a trigger set to the completion of task 2:

Cond:

taskcompleted tskobj_2;

OnAct:

 tskobj_3 = player createSimpleTask ["Search Adam's body."]; tskobj_3 setSimpleTaskDescription ["Verify Adam's death by taking his dogtags, also search for any other items of interest.","Search Adam's body.","Search Adam's body."]; task3 setSimpleTaskDestination markerpos "Adam"; player setCurrentTask tskobj_3; hint "Verify Adam's death by taking his dogtags, also search for any other items of interest." ;

Now when "Adam" is killed only the person who kills him gets to view the hint. I would like an easy yet reliable way to have all people on Blufor view the hint. I am pretty new to this. Sanders answer above mostly confused me lol.

Edited by golfpro1286

Share this post


Link to post
Share on other sites

Hints are local in argument and effect. You need to use one of sander's methods for broadcasting variable and checking variable, for the hint to appear for all or the selected few.

Have the completed objective broadcast a public variable and set up a check for variable on the intended recipients using addPublicVariableEventHandler

https://community.bistudio.com/wiki/addPublicVariableEventHandler

When the event handler detects the broadcasted public variable, it'll execute it's code (the hint for the intended recipient).

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

I have no idea how to do any of that : / think you could post an example?

Share this post


Link to post
Share on other sites

For this demo you need two people playing. The eventhandler doesn't work in singleplayer (including MP with a single player). There has to be two or more.

Place a BluFor unit. In his init field type:

"obj_3" addPublicVariableEventHandler {hint "This is what you want them to see"};

(Normally this would go in a trigger or a script, but to keep the demo simple we're using a player object to initialize the event handler.)

Place another Blufor unit next to him. Make it playable.

Place a trigger near the units. Make it activated by BluFor present. In the OnAct. field type:

obj_3 = true; publicvariable "obj_3";

The trigger is playing the part of our completed objective broadcasting the new objective as true to all.

The event handler will pick up the broadcasted variable and play the hint to all players (because we haven't localized it for specific players).

Save. Start the mission and have your buddy join as the other unit.

Somebody run in the trigger. Hint message "This is what you want them to see" will show for both players.

The "event" which the event handler detects to fire its code is the assigned variable being broadcast. The event handler code can be pretty much anything workable, including call or spawn a side script.

Edited by OpusFmSPol
correcting an error.

Share this post


Link to post
Share on other sites
For this demo you need two people playing. The eventhandler doesn't work in singleplayer (including MP with a single player). There has to be two or more.

Place a BluFor unit. In his init field type:

"obj_3" addPublicVariableEventHandler {hint "This is what you want them to see"};

(Normally this would go in a trigger or a script, but to keep the demo simple we're using a player object to initialize the event handler.)

Place another Blufor unit next to him. Make it playable.

Place a trigger near the units. Make it activated by BluFor present. In the OnAct. field type:

obj_3 = true; publicvariable "obj_3";

The trigger is playing the part of our completed objective broadcasting the new objective as true to all.

The event handler will pick up the broadcasted variable and play the hint to all players (because we haven't localized it for specific players).

Save. Start the mission and have your buddy join as the other unit.

Somebody run in the trigger. Hint message "This is what you want them to see" will show for both players.

EDIT: The "event" which the event handler detects to fire its code is the assigned variable becoming true. The event handler code can be pretty much anything workable, including call or spawn a side script.

Thanks for the reply, this is starting to make a lot more sense to me now. If I am understanding you correctly I should hopefully be able to modify the two triggers I already have in place. Let me know if you think this would work...

Trigger to complete task 2:

Cond:

!aliveAdam

OnAct:

"2" objStatus "DONE"; tskobj_2 setTaskState "SUCCEEDED"; player setCurrentTask tskobj_3; tskobj_3 = true; publicVariable "tskobj_3";

Trigger to create task 3 with hint to all players.

Cond:

taskcompleted tskobj_2;

OnAct:

 tskobj_3 = player createSimpleTask ["Search Adam's body."]; tskobj_3 setSimpleTaskDescription ["Verify Adam's death by taking his dogtags, also search for any other items of interest.","Search Adam's body.","Search Adam's body."]; task3 setSimpleTaskDestination markerpos "Adam"; player setCurrentTask tskobj_3; hint "Verify Adam's death by taking his dogtags, also search for any other items of interest." ; "tskobj_3" addPublicVariableEventHandler {hint "Verify Adam's death by taking his dogtags, also search for any other items of interest."};

I hope I have interpreted your post correctly. Thanks again for your help.

Share this post


Link to post
Share on other sites

Don't think it'll work. You need the event handler to initialize -before- the variable broadcasts. The way you have it the variable will broadcast before the event handler initializes.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites
Don't think it'll work. You need the event handler to initialize -before- the variable becomes true. The way you have it the variable will broadcast before the event handler initializes.

Hmmm do I need to make a new trigger somewhere? I thought I had it figured out lol but guess not. I did not get a chance to test it as none of my friends were available tonight.

Share this post


Link to post
Share on other sites

You could lay down a new trigger with the event handler in it. Make it a full map trigger (no radius) and set to anybody present. As soon as the game starts the event handler will initialize. But if you have an init.sqf script, it would be a better place to put it.

Share this post


Link to post
Share on other sites
You could lay down a new trigger with the event handler in it. Make it a full map trigger (no radius) and set to anybody present. As soon as the game starts the event handler will initialize. But if you have an init.sqf script, it would be a better place to put it.

Thanks for being so patient with me, let me give this another go...

So in my init.sqf I put this:

"tskobj_3" addPublicVariableEventHandler {hint "Verify Adam's death by taking his dogtags, also search for any other items of interest."};

If I am understanding this correctly then the hint should fire when "tsk_obj3" becomes active via a trigger, correct?

So in my trigger I place this:

Cond:

!Alive Adam;

On Act:

"2" objStatus "DONE"; tskobj_2 setTaskState "SUCCEEDED"; player setCurrentTask tskobj_3; tskobj_3 = true; publicVariable "tskobj_3";

In my second trigger to create the task in the map menu:

cond:

taskcompleted tskobj_2;

onact:

tskobj_3 = player createSimpleTask ["Search Adam's body."]; tskobj_3 setSimpleTaskDescription ["Verify Adam's death by taking his dogtags, also search for any other items of interest.","Search Adam's body.","Search Adam's body."]; task3 setSimpleTaskDestination markerpos "Adam"; player setCurrentTask tskobj_3; hint "Verify Adam's death by taking his dogtags, also search for any other items of interest." ;

Is that how it's supposed to be done? I should be able to test it tonight to find out, I will post my findings.

Share this post


Link to post
Share on other sites
If I am understanding this correctly then the hint should fire when "tsk_obj3" becomes active via a trigger, correct?

Correct, when "tskobj_3" gets broadcast.

"2" objStatus "DONE"; tskobj_2 setTaskState "SUCCEEDED"; player setCurrentTask tskobj_3; tskobj_3 = true; [b][u]publicVariable "tskobj_3";[/u][/b]

That underlined portion will fire the event handler code.

Is that how it's supposed to be done?

Should work.

Edited by OpusFmSPol
correcting error for future viewers - the broadcast is what counts

Share this post


Link to post
Share on other sites
Correct, when "tskobj_3" becomes defined as True (as opposed to False).

"2" objStatus "DONE"; tskobj_2 setTaskState "SUCCEEDED"; player setCurrentTask tskobj_3; [b][u]tskobj_3 = true; publicVariable "tskobj_3";[/u][/b]

That underlined portion will fire the event handler code.

Should work.

Yep! That is exactly what I was thinking, and will be testing tonight, thanks again for all of your help!

Share this post


Link to post
Share on other sites

Alright so I was FINALLY able to test this and the event handlers seem to be working, however I am now having trouble with my very first task. It will assign the first task to all players at the start of the mission, however, only the player that completes it gets the task updated and message displayed. I know the event handlers are working becuase during the test I completed the first task and was the only one to see the message and have the new task set. I then had the other player complete the next task, at which point I was able to see the message and have the task updated. So my theory is that something is happening with my code for the first task being completed Here is what I have; The first task is set up to be complete when an evidence file is picked up.

I placed an object on the map named "evid1" and in its init field this:

this addaction ["Collect evidence!", "collect.sqf"];

In collect.sqf I have this:

deletevehicle evid1; tskEvidence1 setTaskState "SUCCEEDED"; [objNull, ObjNull, tskEvidence1, "SUCCEEDED"]; setCurrentTask tskobj_test; tskobj_test = true; publicVariable "tskobj_test"; 

To start the task I used the briefing.sqf and init.sqf

In init.sqf:

execVM "briefing.sqf"; 
BIS_Effects_Burn = compile preprocessFileLineNumbers "\ca\Data\ParticleEffects\SCRIPTS\destruction\burn.sqf";
i=[mi8,10,time,false,false] spawn BIS_Effects_Burn;


"tskobj_test" addPublicVariableEventHandler {hint "tskobj_test" addPublicVariableEventHandler {hint "The file contains evidence that suggests that NSK and his army have taken over the Vatra airport and turned it into their military compound! Find him and kill him!"};

"tskobj_3" addPublicVariableEventHandler {hint "tskobj_3" addPublicVariableEventHandler {hint "Verify NSK's death by taking his dogtags, also search for any other items of interest"};


"tskobj_4" addPublicVariableEventHandler {hint "tskobj_4" addPublicVariableEventHandler {hint "After examining the photo evidence recovered from NKS's corpse it is apparent a new group of hostiles only known as 
'O4V' has started construction of a massive base at the smuggler's airport. Seek out and destroy the leaders of the group to maintain BSA dominance of Panthera Island. Stand by for 'O4V' leader intel."};

"tskobj_metalhead" addPublicVariableEventHandler {hint "tskobj_metalhead" addPublicVariableEventHandler {hint "Check your tasks for 'O4V' leader hit list. Eliminate them all with extreme prejiduce!"};

[] execVM "halo.sqf";

In the briefing.sqf I have this:

player createDiaryRecord ["Diary", ["Collect Evidence File.", 
"Ace has tipped BSA off that he is in possession of dispathes that woudld be of great interest to the team! All BSA members need to report to base immediately for departure.
Mission objectve: collect, examine, and act upon the information in the evidence file, good luck BSA!"]];



//objective 1

tskEvidence1 = player createSimpleTask["Collect Evidence"];
tskEvidence1 setSimpleTaskDescription ["Locate Evidence Folder at Ramon's Villa.", "Collect Evidence", "Collect Evidence"];
tskEvidence1 setSimpleTaskDestination (getMarkerPos "evid1");

Can you see what may be causing this problem? Thanks!

Share this post


Link to post
Share on other sites

Mmmm, I need to amend a previous statement I made above, now realizing it's an error; :16_6_8:

The broadcast of the variable is what sets off the event handler, not the tskobj_3 being true. The value doesn't have to change at all. When the variable is broadcast the receiver event handler will run it's code, regardless whether the value changes. The purpose of declaring it true would be to filter what will happen when true as opposed to false.

Can you see what may be causing this problem? Thanks!

Yes; the tasks and addactions are also local in effect. Like hints, they too will only run on the machine of the player who triggers the code. They too have to be set up in public variable event handlers, in order to run the code on other player's machines. You could use the same handler as the hint if that would work for your mission.

When you look up a command, keep in mind that when you see this box at the top: effects_local.gif that means the command is local.

https://community.bistudio.com/wiki/Category:Commands_with_local_effects

Info in this thread might help a little if your mission is coop rather than adversarial; the task and addAction issues encountered were very much the same as yours:

http://forums.bistudio.com/showthread.php?183977-CUSTOM-MISSION-SECOPS-ACE-TFAR-Chernarus

Also, in your code is this is an accidental paste error?:

[color="#FF0000"]"tskobj_test" addPublicVariableEventHandler {hint [/color][color="#0000CD"]"tskobj_test" addPublicVariableEventHandler {hint [/color]"The file contains evidence that suggests that NSK and his army have taken over the Vatra airport and turned it into their military compound! Find him and kill him!"};

[color="#FF0000"]"tskobj_3" addPublicVariableEventHandler {hint [/color][color="#0000CD"]"tskobj_3" addPublicVariableEventHandler {hint [/color]"Verify NSK's death by taking his dogtags, also search for any other items of interest"};

[color="#FF0000"]"tskobj_4" addPublicVariableEventHandler {hint [/color][color="#0000CD"]"tskobj_4" addPublicVariableEventHandler {hint [/color]"After examining the photo evidence recovered from NKS's corpse it is apparent a new group of hostiles only known as 'O4V' has started construction of a massive base at the smuggler's airport. Seek out and destroy the leaders of the group to maintain BSA dominance of Panthera Island. Stand by for 'O4V' leader intel."};

[color="#FF0000"]"tskobj_metalhead" addPublicVariableEventHandler {hint [/color][color="#0000CD"]"tskobj_metalhead" addPublicVariableEventHandler {hint [/color]"Check your tasks for 'O4V' leader hit list. Eliminate them all with extreme prejiduce!"};

Seems it should be:

"tskobj_test" addPublicVariableEventHandler {hint "The file contains evidence that suggests that NSK and his army have taken over the Vatra airport and turned it into their military compound! Find him and kill him!"};

"tskobj_3" addPublicVariableEventHandler {hint "Verify NSK's death by taking his dogtags, also search for any other items of interest"};

"tskobj_4" addPublicVariableEventHandler {hint "After examining the photo evidence recovered from NKS's corpse it is apparent a new group of hostiles only known as 'O4V' has started construction of a massive base at the smuggler's airport. Seek out and destroy the leaders of the group to maintain BSA dominance of Panthera Island. Stand by for 'O4V' leader intel."};

"tskobj_metalhead" addPublicVariableEventHandler {hint "Check your tasks for 'O4V' leader hit list. Eliminate them all with extreme prejiduce!"};

One other concern with the scripts:

[objNull, ObjNull, tskEvidence1, "SUCCEEDED"]; setCurrentTask tskobj_test;

should be

player setCurrentTask tskobj_test;

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Yes it is actually a full on co-op mission. I will read through that thread and try to get this fixed. and yeah that one was just a paste error. Thanks for your help!

Update: After reading through the thread that you linked, I have a better idea of what I need to do, just not really sure how to do it lol. I wish I had my laptop with me at work today so I could try some of this. I am wary of even posting a guess at how to code this as my other posts have been so jumbled but I will try it anyways (just don't laugh too hard at this). So I need to have the co-op team move to pick up an evidence file. In that file is intel that points to a target, the task is to find and kill him. Then evidence on the target leads to another group of targets to be killed.

To start the mission with the task set for all players to collect evidence I have this in the init.sqf:

execVM "briefing.sqf";

In the "biefing.sqf" file is this code:

//objective 1

tskEvidence1 = player createSimpleTask["Collect Evidence"]; tskEvidence1 setSimpleTaskDescription ["Locate Evidence Folder at Ramon's Villa.", "Collect Evidence", "Collect Evidence"];
tskEvidence1 setSimpleTaskDestination (getMarkerPos "evid1");

Here is where I get a little lost and I feel is where the problems start.

So I place an object named evid1 with this in the init field: (the addaction is local and needs to be attached to a public even handler?)

this addaction ["Collect evidence!", "collect.sqf"];

If I am reading all of this correctly the collect.sqf file only runs on the machine of the player who picks the file up and needs to be attached to a public even handler to run on all machines no matter who picks it up right? (not sure how to do that)

In the collect.sqf file is this code:

deletevehicle evid1; tskEvidence1 setTaskState "SUCCEEDED"; setCurrentTask tskobj_test; tskobj_test = true; publicVariable "tskobj_test";

So assuming that the above issues are solved I want to move on to creating the next task when tskEvidence1 is complete.

So then instead of having a trigger to create a new task when tskevidence1 is done, I make a task called tskobj_test using the init.sqf file and a new "tskobj_test.sqf" file to create the new task as such:

updated thought: Maybe I need a trigger where cond is

taskcompleted tskEvidence1;

with onAct:

"tskobj_test" addPublicVariableEventHandler {[] execVM "tskobj_test.sqf";};

So in the init.sqf

"tskobj_test" addPublicVariableEventHandler 
{
// Assign and Succeed the task:"tsakobj_test".
tskobj_test = player createSimpleTask ["Kill NSK"];
tskobj_test setSimpleTaskDescription ["The file shows NSK has taken over the Vatra airport and turned it into his military compound. Find and eliminate him."];
tskobj_test setTaskState "Assigned";
tskobj_test setTaskState "Succeeded";   

// Show message.
taskhint ["The file shows NSK has taken over the Vatra airport and turned it into his military compound. Find and eliminate him."]};

then in a file named tskobj_test.sqf I put this code in:

// Assign and Succeed the task:"tsakobj_test".
tskobj_test = player createSimpleTask ["Kill NSK"];
tskobj_test setSimpleTaskDescription ["The file shows NSK has taken over the Vatra airport and turned it into his military compound. Find and eliminate him."];
tskobj_test setTaskState "Assigned";
tskobj_test setTaskState "Succeeded";    

// Show message.
taskhint ["The file shows NSK has taken over the Vatra airport and turned it into his military compound. Find and eliminate him."];

now to complete this task a unit named "nsk" must be killed so in a trigger I put this:

cond:

!alive nsk;

onAct:

"test" objStatus "DONE"; tskobj_test setTaskState "SUCCEEDED"; player setCurrentTask tskobj_3; obj_3 = true; publicVariable "tskobj_3"; "tskobj_3" addPublicVariableEventHandler {[] execVM "tskobj_3.sqf";

So I THINK the next step is to set up the publicvariable "tskobj_3".

so in the init.sqf I put this:

"tskobj_3" addPublicVariableEventHandler 
{
// Assign and Succeed the task:"tsakobj_3".
tskobj_3 = player createSimpleTask ["search NSK's Body"];
tskobj_3 setSimpleTaskDescription ["Verify NSK's death by taking his dogtags, also search for any other items of interest."];
tskobj_test setTaskState "Assigned";
tskobj_test setTaskState "Succeeded";   

// Show message.
taskhint ["Verify NSK's death by taking his dogtags, also search for any other items of interest."]};

Then in the tskobj_3.sqf:

{
// Assign and Succeed the task:"tsakobj_3".
tskobj_3 = player createSimpleTask ["search NSK's Body"];
tskobj_3 setSimpleTaskDescription ["Verify NSK's death by taking his dogtags, also search for any other items of interest."];
tskobj_test setTaskState "Assigned";
tskobj_test setTaskState "Succeeded";   

// Show message.
taskhint ["Verify NSK's death by taking his dogtags, also search for any other items of interest."]};

LMAO my brain is fried, could not get past this, please help! I am almost 100% positive that I messed that up beyond all recognition and probably caused myself more harm than good! But I like to learn by trial and error. Thanks again for the help and the patience!

Edited by golfpro1286

Share this post


Link to post
Share on other sites
If I am reading all of this correctly the collect.sqf file only runs on the machine of the player who picks the file up and needs to be attached to a public even handler to run on all machines no matter who picks it up right?

Correct, the addAction is local in effect. When the addAction runs, it occurs on the machine of the player doing the action, and not on the machine of other players. The PVEH is used to run the same code for everyone else.

(Note: Delete the addAction from the object, or other players might run it and you'll end up with duplicate tasks.)

HOWEVER - deleteVehicle is a global command. effects_global.gif When that line runs, the evidence object will be deleted on all machines. And VERY important to consider is this:

"Deleting a vehicle, which is still being accessed by a running script, can result in a CTD." [crash to desktop] ...:butbut:

https://community.bistudio.com/wiki/deleteVehicle

So deleting the evidence object is the very LAST thing you do, and done separately from the tasks.

In a scenario like yours, I would have the init.sqf run a single script which sets up all the public variable event handlers, and each event handler would execVM the various task scripts. The player actions and triggers would be set to run the task scripts and broadcast public variable. That way the broadcaster and receivers all run the one and same task scripts; and the code doesn't have to be duplicated in the event handler code. Then the evidence object can be deleted separately from the task script (but to be safe, only AFTER the broadcaster script has completed and addAction has been removed from the object - I would suggest a trigger with a few seconds delay).

Putting together the task scripts would be part of the mission planning, where the tasks are laid out:

tasks:

----------

Briefing task:

"Collect Evidence"

"Locate Evidence Folder at Ramon's Villa."

task1:

"Kill NSK"

"The file shows NSK has taken over the Vatra airport and turned it into his military compound. Find and eliminate him."

task2:

"search NSK's Body"

"Verify NSK's death by taking his dogtags, also search for any other items of interest."

task3: ...etc.

scripts:

----------

briefing.sqf

task1.sqf

task2.sqf

task3.sqf ...etc.

event handlers:

----------

"tsk_obj0" addPublicVariableEventHandler {if (tsk_obj0) then {task1 = player execVM "task1.sqf"};};

"tsk_obj1" addPublicVariableEventHandler {if (tsk_obj1) then {task2 = player execVM "task2.sqf"};};

"tsk_obj2" addPublicVariableEventHandler {if (tsk_obj2) then {task3 = player execVM "task3.sqf"};};

"tsk_obj3" addPublicVariableEventHandler {if (tsk_obj3) then {task4 = player execVM "task4.sqf"};};

... etc.

(Note: The "if (tsk_objx) then" is a filter to ensure the task script will only run if the variable being broadcast is true - it allows you flexibility to add alternative code using "else" for when the variable is broadcast false. A success scenario vs. failure scenario.)

Briefing task is "tsk_obj0". When broadcast true, task1 script will run.

example event code:

task1 = player execVM "task1.sqf";
waitUntil {scriptDone task1};
tsk_obj0 = true;
publicVariable "tsk_obj0";

The task script runs for the action player, then broadcasts the variable true so the task script will run for others.

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  

×