Home   Help Search Login Register  

Author Topic: Broadcasting Objectives  (Read 3217 times)

0 Members and 1 Guest are viewing this topic.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Broadcasting Objectives
« on: 02 Mar 2009, 03:43:27 »
Problem:
So I have an officer who has an addaction attached to him saying "Recieve Mission Orders" and it executes a script called missionOrders.sqf. When I run this on my dedicated server the Objectives are only seen by the person who initiated the script (action). So, everyone has to go to him individually.

missionOrders.sqf
Code: [Select]
//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: Ironman
//////////////////////////////////////////////////////////////////

if(obj1Stat && CratesDestroyed)then{"2" objStatus "active";};

if(obj2Stat && ShiekhArrives)then{"3" objStatus "active";};

if(obj3Stat && CaptureRecorder)then{"4" objStatus "active";};

if(obj4Stat && DestroyComms)then{"5" objStatus "active";};

"1" objStatus "active";
obj1Stat = true;

If you could fill me in on my missing knowledge that would be sweet. I am pretty sure the problem exists in the AddAction command because in the command ref it says it only executes for the one executing it... that might be on the biki not sure.
« Last Edit: 02 Mar 2009, 03:49:14 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Broadcasting Objectives
« Reply #1 on: 02 Mar 2009, 03:53:12 »
Code: (init.sqf) [Select]
call compile preprocessFileLineNumbers "updateStatus.sqf";
Code: (updateStatus.sqf) [Select]
objStatusHandler =
{
  private ["_objective", "_status"];
  _objective = _this select 0;
  _status = _this select 1;
  _objective objStatus _status;
};

"updateObjStatusEvent" addPublicVariableEventHandler { (_this select 1) call objStatusHandler };

// Update status on all machines on the network.
updateObjStatus =
{
  updateObjStatusEvent = _this;
  publicVariable "updateObjStatusEvent"; // Update on all remote machines.
  _this call objStatusHandler; // Update on the local machine.
};
Code: (To update any status on every machine, including the local one) [Select]
["1", "DONE"] call updateObjStatus;
Thus you'd do:
Code: [Select]
if(obj1Stat && CratesDestroyed)then{ ["2", "ACTIVE"] call updateObjStatus; };
etc...

(warning: sorry, untested code)
« Last Edit: 02 Mar 2009, 04:31:25 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Broadcasting Objectives
« Reply #2 on: 06 Mar 2009, 02:59:07 »
When a JIP occurs the objective that is currently active is checked off as complete... I just go back to the officer and select the addAction and then it resets the objective....any ideas?
TS3 IP: tor.zebgames.com:9992

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Broadcasting Objectives
« Reply #3 on: 06 Mar 2009, 23:28:55 »
Sorry, yes, JIP was overlooked.
Code: (updateStatus.sqf) [Select]
objStatusHandler =
{
  private ["_objective", "_status"];
  _objective = _this select 0;
  _status = _this select 1;

  _objective objStatus _status;

  // Any other effects that should happen on status change should go here.
};

"updateObjStatus1Event" addPublicVariableEventHandler { (["1"] + (_this select 1)) call objStatusHandler };
"updateObjStatus2Event" addPublicVariableEventHandler { (["2"] + (_this select 1)) call objStatusHandler };
"updateObjStatus3Event" addPublicVariableEventHandler { (["3"] + (_this select 1)) call objStatusHandler };
"updateObjStatus4Event" addPublicVariableEventHandler { (["4"] + (_this select 1)) call objStatusHandler };
"updateObjStatus5Event" addPublicVariableEventHandler { (["5"] + (_this select 1)) call objStatusHandler };
"updateObjStatus6Event" addPublicVariableEventHandler { (["6"] + (_this select 1)) call objStatusHandler };
// May need more status handling events depending on how many the mission uses.

// Update status on all machines on the network.
updateObjStatus =
{
  private ["_event", "_objective", "_status"];
  _objective = _this select 0;
  _status = _this select 1;

  _event = format ["updateObjStatus%1Event", _objective];
  call compile format ["%1 = [_status]", _event];
  publicVariable _event; // Update on all remote machines.
  _this call objStatusHandler; // Update on the local machine.
};
Otherwise, the usage is the same as shown earlier (just updateStatus.sqf that has changed).

(warning: sorry, untested code again)

EDIT: Typo...oops
« Last Edit: 07 Mar 2009, 03:51:33 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Broadcasting Objectives
« Reply #4 on: 07 Mar 2009, 03:47:38 »
Thanks for your willingness to help again spooner.  :-* hahaha
TS3 IP: tor.zebgames.com:9992

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Broadcasting Objectives
« Reply #5 on: 07 Mar 2009, 03:56:40 »
Just corrected a typo that you might not otherwise notice.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Broadcasting Objectives
« Reply #6 on: 10 Apr 2009, 21:30:21 »
Just because this next question is related somewhat to this script....

So I have the first objective check off but when I go to an officer to get my next objective it just resets the First objective to active again. I am pretty sure it is because of the last 4 lines of code.... I am not sure how to execute this though. I don't want the players to make every objective active right away.... I only want it to go one at a time...

This is what will set off once you visit the officer:
Code: [Select]
if(obj1Stat && CratesDestroyed && isServer)then{ ["2", "ACTIVE"] call updateObjStatus; };

if(obj2Stat && ShiekhArrives && isServer)then{["3", "ACTIVE"] call updateObjStatus; };

if(obj3Stat && CaptureRecorder && isServer)then{["4", "ACTIVE"] call updateObjStatus;
_box = createVehicle ["AAMI154" , [0, 0, 0], ["Mb_pos1", "Mb_pos2", "Mb_pos3"], 0, "NONE"];
_building = nearestBuilding _box;
_building addEventHandler ["KILLED", { ["5", "DONE"] call updateObjStatus; DestroyComms = true;} ];};

if(obj4Stat && DestroyComms && isServer)then{["5", "ACTIVE"] call updateObjStatus;};

obj1Stat = true;
["1", "ACTIVE"] call updateObjStatus;
"obj1a" setMarkerType Obj1area;
"obj1"  setMarkerType Des_ammo;

So how could I better write this sqf?
« Last Edit: 16 Apr 2009, 00:46:29 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Broadcasting Objectives
« Reply #7 on: 18 Apr 2009, 17:30:49 »
Code: [Select]
i=0

while{i==0}do{

  obj1Stat = true;
  ["1", "ACTIVE"] call updateObjStatus;
  "obj1a" setMarkerType Obj1area;
  "obj1"  setMarkerType Des_ammo;

   i=i+1
}

Is that a way to ensure that the code only run's one time?

*EDIT*
 The "" marks at the beginning of a while loop are only used for Sqs I am assuming.
« Last Edit: 20 Apr 2009, 00:29:23 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Broadcasting Objectives
« Reply #8 on: 19 Apr 2009, 14:36:16 »
Code: [Select]
if (not obj1Stat) then
{
  obj1Stat = true;
  ["1", "ACTIVE"] call updateObjStatus;
  "obj1a" setMarkerType Obj1area;
  "obj1"  setMarkerType Des_ammo;
}
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Broadcasting Objectives
« Reply #9 on: 20 Apr 2009, 00:28:26 »
I edited the previous code I put out.... is there something wrong with the way I am doing it? It worked on my local server.... waiting to test it on the dedi.


*EDIT*
Well my way didn't work. Am unsure why but maybe because I didn't make "i" a global variable? Will try spooner's method now since he is a programming wiz.
« Last Edit: 20 Apr 2009, 03:01:54 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Broadcasting Objectives
« Reply #10 on: 21 Apr 2009, 13:02:58 »
By definition, a variable named "i" is global. One called "_i" would be local.

The function of my offered code is exactly the same as your code, but it is considerably less messy in its logic (i.e. I don't have to peer at it for some time to work out what it is supposed to do). If your code doesn't work then mine probably won't either.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Broadcasting Objectives
« Reply #11 on: 21 Apr 2009, 21:53:25 »
hmm.

Ok so just to clarify the problem is after I clear the first OBJ and it checks off on map it won't go to OBJ2. Instead it just resets OBJ1 like we didn't do anything. Could JIP be a problem? Like I said my code works on my local server but not on Dedi, so it is one of those quarky MP coding errors I assume.
TS3 IP: tor.zebgames.com:9992