Jump to content
Sign in to follow this  
[evo] dan

Randomly picking a mission from a list of missions

Recommended Posts

I have tried to create a set of scripts that will work in multiplayer which will randomly generate a number, and then sync this number with clients so that they will know which mission needs to be spawned (there is going to be multiple little missions within this one mission, randomly picked). However, when I host this on a non-dedi server and have people join, only I see the hints and get the tasks show up, noone else does. It does not seemingly work if someone JIP's either. Can someone help me out here?

Heres the mission file:

http://dl.dropbox.com/u/28062918/mmt2.utes.rar

init.sqf:

publicVariable "ambushSite";
player globalChat "Initialising Mission";

sleep 5;


numberOfSites = 2;
if(isServer) then {
   _ambushSite = 1 + (round random (numberOfSites-1));
   publicVariable "ambushSite";
player setVariable ["ambushSite", _ambushSite, TRUE];
};	

// if ((!isServer) && (player != player)) then
// {
 // waitUntil {player == player};
// };

processInitCommands;

finishMissionInit;

player globalChat "Mission Initialisation Complete";



sleep 30;
execVM "main.sqf";

main.sqf:

publicVariable "ambushSite";

_ar4 = player getVariable ["ambushSite", 0];
if(_ar4 == 1)then{
hint "its 1";
execVM "missions\mission1.sqf";
};
if(_ar4 == 2)then{
hint "its 2";
execVM "missions\mission2.sqf";
};

mission1.sqf:

_nm = 1;

//add new mission
	tskObj1 = player createSimpleTask["Primary: Patrol"]; 
	tskObj1 setSimpleTaskDescription["Patrol along the given route.", "Patrol", "Patrol"];

//trigger creation
_triggeram1 = createTrigger["EmptyDetector",[3500,3500,0]];
_triggeram1 setTriggerArea [160,160,0,false];
_triggeram1 setTriggerActivation ["ALPHA","PRESENT",true];
_triggeram1 setTriggerTimeout [1,1,1,true];
_triggeram1 setTriggerStatements ["this", "hint 'meh'; dude = 1; publicVariable 'dude'; player setVariable ['dude', dude, TRUE];", "hint 'trigger off'"];

//marker generation
_Marker3 = createMarker ["Marker3", [3500,3500]]; 
"Marker3" setMarkerShape "RECTANGLE";
"Marker3" setMarkerSize [50,50];

while{_nm == 1} do {
_ar5 = player getVariable ["dude", 0];
sleep 10;
hint "working";
if(_ar5 == 1) then {
	hint "You've done it right";
	numberOfSites = 1;
	if(isServer) then {
	_ambushSite = 2 + (round random (numberOfSites-1));
	player setVariable ["ambushSite", _ambushSite, TRUE];
	};
	sleep 60;
	hint "loading";
	execVM "main.sqf";
	_nm = 0;
};
};

mission2.sqf:

_nm = 1;

//add new mission
	tskObj2 = player createSimpleTask["Primary: Patrol2"]; 
	tskObj2 setSimpleTaskDescription["Patrol along the given route.", "Patrol2", "Patrol2"];

//trigger creation
_triggeram2 = createTrigger["EmptyDetector",[3550,3550,0]];
_triggeram2 setTriggerArea [160,160,0,false];
_triggeram2 setTriggerActivation ["BRAVO","PRESENT",true];
_triggeram2 setTriggerTimeout [1,1,1,true];
_triggeram2 setTriggerStatements ["this", "hint 'meh'; dude1 = 1; publicVariable 'dude1'; player setVariable ['dude1', dude1, TRUE];", "hint 'trigger off'"];

//marker generation
_Marker3 = createMarker ["Marker4", [350,350]]; 
"Marker4" setMarkerShape "RECTANGLE";
"Marker4" setMarkerSize [50,50];

while{_nm == 1} do {
_ar5 = player getVariable ["dude1", 0];
sleep 10;
hint "working";
if(_ar5 == 1) then {
	hint "You've done it right";
	numberOfSites = 1;
	if(isServer) then {
	_ambushSite = 1 + (round random (numberOfSites-1));
	player setVariable ["ambushSite", _ambushSite, TRUE];
	};
	sleep 60;
	hint "loading";
	execVM "main.sqf";
	_nm = 0;
};
};

Thank you for any help in advance.

Share this post


Link to post
Share on other sites

tl;dr

Have an array containing all mission names. In your case then paths to scripts

_myMissions = ["Mission1", "Mission2", "Mission3", "Mission4"];
_curMission = _myMissions select floor random count _myMissions;
[] execVM _curMission;

Share this post


Link to post
Share on other sites
tl;dr

Have an array containing all mission names. In your case then paths to scripts

_myMissions = ["Mission1", "Mission2", "Mission3", "Mission4"];
_curMission = _myMissions select floor random count _myMissions;
[] execVM _curMission;

so that would replace my random number generator? But how would that be synced in multiplayer then?

Share this post


Link to post
Share on other sites

Via a set of publicVariableEventhandlers kicking things on clients into motion once the server says so.

However I recommend running the mission only on the server and merely broadcasting it's effects on the players via network. (Briefing)

Share this post


Link to post
Share on other sites

However I recommend running the mission only on the server and merely broadcasting it's effects on the players via network. (Briefing)

you mean essentially the way that I was doing it, just without the public variables and using your random selection of something in an array?

Or would I have to use a different way of broadcasting its effects to players? I was thinking of doing it the way I did it before, where each client executes the mission but only somethings are done on there side. or is there a different way you recommend (remember I am a scripting noob).

Thank you for your help so far.

Also I assume this will work on a nondedi server too?

Heres my init.sqf now:

publicVariable "ambushSite";
player globalChat "Initialising Mission";

sleep 5;


numberOfSites = 2;
if(isServer) then {
_myMissions = ["mission1.sqf", "mission2.sqf"];
_curMission = _myMissions select floor random count _myMissions;
[] execVM _curMission;
};	

// if ((!isServer) && (player != player)) then
// {
 // waitUntil {player == player};
// };

processInitCommands;

finishMissionInit;

player globalChat "Mission Initialisation Complete";

Edited by [EVO] Dan

Share this post


Link to post
Share on other sites

ahh, now I know what you mean, just got to figure a way how to get the mission tasking to show up for all players if the mission script is only working serverside. How would I go about doing that (I guess I gotta execute the briefing.sqf for each person via this script, but not sure how to do it)

Could I use forEach or is it not suitable for this (seeing as only the mission is executed serverside):

http://community.bistudio.com/wiki/forEach

or should I perhaps use this?:

http://community.bistudio.com/wiki/addMPEventHandler

edit:

I used forEach, however I only got it to work for allUnits, I could not figure out how to do it just for units on a particular side only (could someone help me out there). Gotta test it on MP yet still but here is what I have got so far.

init.sqf:

player globalChat "Initialising Mission";

sleep 5;

if(isServer) then {
_myMissions = ["template.sqf"];
_curMission = _myMissions select floor random count _myMissions;
[] execVM _curMission;
};	

// if ((!isServer) && (player != player)) then
// {
 // waitUntil {player == player};
// };

processInitCommands;

finishMissionInit;

player globalChat "Mission Initialisation Complete";

template.sqf:

sleep 5;
{hint "workin"} forEach allUnits;
sleep 5;

Edited by [EVO] Dan

Share this post


Link to post
Share on other sites

An if statement should do the trick there, Dan.

My syntax is horrible for this sort of thing, but you want something like this (beware of syntax errors! :p):

{if (side _x == WEST) then {hint "workin"}} forEach allUnits;

Share this post


Link to post
Share on other sites

This code:

sleep 5;
{hint "workin"} forEach allUnits;
sleep 5;

did not work over multiplayer for me and my clanmate.

This is what I did:

-I was hosting a non dedi server

-My clanmate joined before the mission started, and I waited for him to load before starting the mission after we got to the map.

-I got the hint, but he did not

-I was using the same init.sqf as I put up on my last post.

So where am I going wrong with this since it is not working?

Share this post


Link to post
Share on other sites

Got the thing to work, I used setVehicleInit and processInitCommands and now it works in MP. I put a game logic down names serverlogic to get it to work.

sleep 5;

serverlogic setVehicleInit "hint 'workin'";
processInitCommands;

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  

×