Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Script that calls on radnom script?

  1. #1

    Script that calls on random script?

    Hello everyone,


    I'm currently stumped and need some assistance. Since I have very little scripting experience I was looking on how to call a random script through a script that is always running.

    I.E.
    The script calls randomly on a script which generates a obj in game, once that objective is complete it will wait for something around 60 seconds then it will execute another script (Obj).

    If anyone can help I would greatly appreciate it!

    Thanks in advance.

    -Bigshot
    Last edited by bigshotking; Jul 19 2011 at 07:16.

  2. #2
    Here is one way to do it:

    example:

    myscript0.sqf
    myscript1.sqf
    myscript2.sqf
    myscript3.sqf
    myscript4.sqf


    Code:
    _myscriptnum = floor(random 4);
    
    _scriptstr = format ["myscript%1.sqf",_myscriptnum];
    _randomscriptstrt = [] execVM  _scriptstr;
    This is not tested, just some ideas on how you can get started.
    Last edited by Riouken; Jul 19 2011 at 02:29.

  3. #3
    Gunnery Sergeant bigshotking's Avatar
    Join Date
    Feb 12 2011
    Location
    Notepad++
    Posts
    410
    Author of the Thread
    Well I found this on Mr. Murray's Editing Guide:

    Code:
    [] exec "scripts\music.sqs"; 
    _music = ["ATrack1","ATrack6", "ATrack10", "ATrack11", "ATrack12", "ATrack13", "ATrack14", "ATrack15", "ATrack19", "ATrack22"]; playMusic ( _music select floor(random((count _music) - 0.5 )));  exit;
    I suppose I can use this, but I'm not sure how to add that when the obj is complete it will call on another random script and make sure that the last one is not called on again later.

    @Riouken
    Thanks for the example, is there anyway you can break down what you gave me? I'm a little confused about how to use it.


    -Bigshot

  4. #4
    // These are the scripts that will spawn whatever your doing, lets say a side mission.

    myscript0.sqf
    myscript1.sqf
    myscript2.sqf
    myscript3.sqf
    myscript4.sqf


    example:

    myscript0.sqf:
    Code:
    // Operation fire the crapper.
    _veh = createVehicle ["Land_Toilet", [0,0,0], [], 0, "NONE"]; 
    
    // What ever  you want to code. etc...
    
    // Wait until they blow up the toilet and do this:
    waitUntil {!alive _veh};
    mysidemissionsfinished = true;

    This is your control script, start it from the init.sqf and let it loop. It will check every minute to see if you need to start another random script.

    missioncontrol.sqf:

    Code:
    while {true} do {
       If (mysidemissionsfinished) then {
                  
                 mysidemissionsfinished = false;
                 // this just selects a random number.
                 _myscriptnum = floor(random 4);
    
                 // this will take that random number and put it into a string that we can use to execVM.
                  _scriptstr = format ["myscript%1.sqf",_myscriptnum];
                  
                  // Here we use the string to execute the random mission.
                  _randomscriptstrt = [] execVM  _scriptstr;
          };
    sleep 60;
    };

    Stuff like this can get pretty complicated, Just write down a rough outline of your plans then break it down into smaller sections or "problems" then just start working through each item, and consult your outline anytime you get lost.
    Last edited by Riouken; Jul 19 2011 at 03:12.

  5. #5
    Gunnery Sergeant bigshotking's Avatar
    Join Date
    Feb 12 2011
    Location
    Notepad++
    Posts
    410
    Author of the Thread
    Thankyou that seems to be perfect!

    I'll make sure to credit you in the mission!

  6. #6
    Also, I didn't put it in the example, but if you dont know, make sure you only run those on the server. You don't want 32 Out-houses being spawned!

  7. #7
    Gunnery Sergeant bigshotking's Avatar
    Join Date
    Feb 12 2011
    Location
    Notepad++
    Posts
    410
    Author of the Thread
    It would spawn 32 toilets?

    Jezz....

    Ok then

    Code:
    // Operation fire the crapper.
    if (isMultiplayer) then {
       _veh = createVehicle ["Land_Toilet", [0,0,0], [], 0, "NONE"]; 
    };
    
    // What ever  you want to code. etc...
    
    // Wait until they blow up the toilet and do this:
    waitUntil {!alive _veh};
    mysidemissionsfinished = true;
    Will this work?

  8. #8
    In the top of all the scripts you should do this to make sure it only runs on the server:

    Code:
    // If you are not the server you will just exit the script.
    if (!isServer) exitWith {};
    
    
    // Operation fire the crapper.
    _veh = createVehicle ["Land_Toilet", [0,0,0], [], 0, "NONE"]; 
    
    // What ever  you want to code. etc...
    
    // Wait until they blow up the toilet and do this:
    waitUntil {!alive _veh};
    mysidemissionsfinished = true;
    Learn these - Get to know/love them:

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

    http://community.bistudio.com/wiki/local
    Last edited by Riouken; Jul 19 2011 at 03:49.

  9. #9
    Gunnery Sergeant bigshotking's Avatar
    Join Date
    Feb 12 2011
    Location
    Notepad++
    Posts
    410
    Author of the Thread
    Roger that, thanks for your help!

    -Bigshot

  10. #10
    Gunnery Sergeant bigshotking's Avatar
    Join Date
    Feb 12 2011
    Location
    Notepad++
    Posts
    410
    Author of the Thread
    Ok, I'm having some issues on this script here:
    Code:
    if (isServer) then {
    
    tsk1 = player createSimpleTask ["DESTROY"];
    tsk1 setSimpleTaskDescription ["Destroy the BMP3!", "DESTROY", "DESTROY"];
    tsk1 setSimpleTaskDestination (getMarkerPos "bmp_2");
    player setCurrentTask tsk1;
    tsk1 setTaskState "CREATED"; 
    [tsk1] call mk_fTaskHint;
    
    0 = [markerPos "bmp_1", "Infantry", 50, ["BIS_TK_INS"]] execVM "crB_scripts\crB_taskPatrol.sqf";
    0 = [markerPos "bmp_3", "Mechanized", 50, ["BIS_TK_INS"]] execVM "crB_scripts\crB_taskPatrol.sqf";
    _veh = createVehicle ["BMP3", getMarkerPos "bmp", [], 0, "NONE"];
    
    _trgc_1 = createTrigger["EmptyDetector", getMarkerPos "bmp_4"];
    _trgc_1 setTriggerArea[500,500,0,false];
    _trgc_1 setTriggerActivation["EAST","NOT PRESENT",false];
    _trgc_1 setTriggerStatements["this","hint "Area CLEAR"",""];
    _trgc_2 = createTrigger["EmptyDetector", getMarkerPos "bmp_5"];
    _trgc_2 setTriggerArea[0,0,0,false];
    _trgc_2 setTriggerActivation["NONE","PRESENT",false];
    _trgc_2 setTriggerStatements["!(alive _veh)","hint "BMP DESTROYED"",""];
    
    
    waitUntil {!alive _veh};
    
    tsk1 setTaskState "SUCCEEDED";
    [tsk1] call mk_fTaskHint;
    
    sleep 5;
    
    hint "OBJECTIVE COMPLETE";
    
    };
    I'm currently testing it with a radio trigger, I see the task hint pop-up but no-one else that is on the server I'm hosting on my computer can see it! Also not all of the AI are spawning in as well, oh and the triggers don't seem to fire either, even though the area is clear of all enemies! I've placed empty markers where all of these objects are spawning so that shouldn't be the problem.

    I've also tried this with the script:
    Code:
    if (!isServer) exitWith {};
    Any idea's whats going on?

    Thanks in advance.

    -Bigshot


    EDIT: The first example using if (isServer) then {}; yields the script not running at all! The other one if (!isServer) exitwith {}; results in me (the server host) only seeing the task pop-up and not the rest of my clients
    Last edited by bigshotking; Jul 20 2011 at 06:16.

Page 1 of 2 12 LastLast

Posting Permissions

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