Results 1 to 9 of 9

  Click here to go to the first Developer post in this thread.  

Thread: Randomly picking a mission from a list of missions

Hybrid View

  1. #1

    Randomly picking a mission from a list of missions

    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:

    Code:
    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:
    Code:
    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:
    Code:
    _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:
    Code:
    _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.
    My custom missions:
    TOH - COOP5 Operation Pegasus http://forums.bistudio.com/showthrea...ration-Pegasus
    TOH - COOP Convoy attack (both Hinds and stock versions) http://forums.bistudio.com/showthrea...-Convoy-Attack
    A2CO Multi-mission Template http://forums.bistudio.com/showthrea...48#post2182048
    Basic Vehicle respawn script (A3 Alpha) http://forums.bistudio.com/showthrea...72#post2389272

    [EVO] Multigaming Clan is recuiting at www.evoclan.net

  2.   Click here to go to the next Developer post in this thread.   #2
    tl;dr

    Have an array containing all mission names. In your case then paths to scripts
    Code:
    _myMissions = ["Mission1", "Mission2", "Mission3", "Mission4"];
    _curMission = _myMissions select floor random count _myMissions;
    [] execVM _curMission;
    >>> mondkalb.org - For DK: Stikkontakt

  3. #3
    Master Sergeant
    Join Date
    Jan 4 2011
    Location
    Tipton, UK
    Posts
    655
    Author of the Thread
    Quote Originally Posted by Mondkalb View Post
    tl;dr

    Have an array containing all mission names. In your case then paths to scripts
    Code:
    _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?

  4.   This is the last Developer post in this thread.   #4
    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)

  5. #5
    Master Sergeant
    Join Date
    Jan 4 2011
    Location
    Tipton, UK
    Posts
    655
    Author of the Thread
    Quote Originally Posted by Mondkalb View Post
    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:

    Code:
    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";
    Last edited by [EVO] Dan; Jun 11 2012 at 15:58.

  6. #6
    Master Sergeant
    Join Date
    Jan 4 2011
    Location
    Tipton, UK
    Posts
    655
    Author of the Thread
    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:

    Code:
    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:

    Code:
    sleep 5;
    {hint "workin"} forEach allUnits;
    sleep 5;
    Last edited by [EVO] Dan; Jun 11 2012 at 21:53.

  7. #7
    Master Gunnery Sergeant Hellfire257's Avatar
    Join Date
    Feb 17 2009
    Location
    (getPosATL player)
    Posts
    1,207
    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! ):

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

  8. #8
    Master Sergeant
    Join Date
    Jan 4 2011
    Location
    Tipton, UK
    Posts
    655
    Author of the Thread
    This code:

    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?

  9. #9
    Master Sergeant
    Join Date
    Jan 4 2011
    Location
    Tipton, UK
    Posts
    655
    Author of the Thread
    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.
    Code:
    sleep 5;
    
    serverlogic setVehicleInit "hint 'workin'";
    processInitCommands;

Similar Threads

  1. (solved) Duplicate memory missions in mission list
    By OMAC in forum TAKE ON HELICOPTERS - OFFICIAL SCENARIOS
    Replies: 2
    Last Post: Nov 21 2011, 13:20
  2. ACE co 8-10 Moscow File - Randomly generated mission
    By galzohar in forum ARMA 2 & OA - USER MISSIONS
    Replies: 15
    Last Post: Oct 18 2011, 04:05
  3. At mission start randomly place POW's
    By Meatball0311 in forum ARMA - MISSION EDITING & SCRIPTING
    Replies: 5
    Last Post: Oct 20 2007, 21:30
  4. Red Hammer Mission "Picking up the Peices"
    By MotherRussiaAK74 in forum TROUBLESHOOTING
    Replies: 6
    Last Post: Jan 28 2002, 01:26
  5. Picking up the pieces mission!!
    By Nighthawk in forum OPF MISSIONS
    Replies: 4
    Last Post: Jan 1 2002, 11:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •