OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting Multiplayer => Topic started by: Ironman 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
//////////////////////////////////////////////////////////////////
// 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.
-
call compile preprocessFileLineNumbers "updateStatus.sqf";
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.
};
["1", "DONE"] call updateObjStatus;
Thus you'd do:
if(obj1Stat && CratesDestroyed)then{ ["2", "ACTIVE"] call updateObjStatus; };
etc...
(warning: sorry, untested code)
-
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?
-
Sorry, yes, JIP was overlooked.
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
-
Thanks for your willingness to help again spooner. :-* hahaha
-
Just corrected a typo that you might not otherwise notice.
-
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:
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?
-
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.
-
if (not obj1Stat) then
{
obj1Stat = true;
["1", "ACTIVE"] call updateObjStatus;
"obj1a" setMarkerType Obj1area;
"obj1" setMarkerType Des_ammo;
}
-
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.
-
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.
-
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.