Jump to content
Sign in to follow this  
bigshotking

Script that calls on radnom script?

Recommended Posts

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

Edited by bigshotking

Share this post


Link to post
Share on other sites

Here is one way to do it:

example:

myscript0.sqf

myscript1.sqf

myscript2.sqf

myscript3.sqf

myscript4.sqf

_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.

Edited by Riouken

Share this post


Link to post
Share on other sites

Well I found this on Mr. Murray's Editing Guide:

[] 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

Share this post


Link to post
Share on other sites

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

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


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.

Edited by Riouken

Share this post


Link to post
Share on other sites

Thankyou that seems to be perfect!

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

It would spawn 32 toilets?

Jezz....

Ok then

// 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?

Share this post


Link to post
Share on other sites

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


// If you are not the server you will just exit the script.
[color="Red"]if (!isServer) exitWith {};[/color]


// 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

Edited by Riouken

Share this post


Link to post
Share on other sites

Ok, I'm having some issues on this script here:

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:

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

Edited by bigshotking

Share this post


Link to post
Share on other sites

@bigshotking:

Hints are local, that script is running on the server and not on all clients. What you need to use in this instance is Remote Execution.

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

place a functions module down on the map.

waitUntil{!(isNil "BIS_MPF_InitDone")};

// This will hint to everyone currently connected to the game.
[nil,nil,rHINT,"OBJECTIVE COMPLETE."] call RE;

Also you should refrain from using the key word (player) in scripts that will not be run locally on the client machine. Right now your script would break in multiplayer, this script is limited to the server and the (player) key word is null on the server machine.

As for a fix for this, you should either offload the task updates to another script and run those with either RE or a publicVariableEventHandler.

Also I think task master, which I think your using, has some type of multiplayer function to update tasks globally, but I will have to read the documentation to find out for sure.

@psvialli

Just add the completed side missions to an array and check that array when your getting the new side mission to see if it has been completed yet.

---------- Post added at 05:49 AM ---------- Previous post was at 05:29 AM ----------

The Reason why your triggers are not firing are due to this:

_trgc_2 setTriggerStatements["!(alive _veh)","hint "BMP DESTROYED"",""];

Should look like this:

_trgc_2 setTriggerStatements["!(alive _veh)","hint [color="red"]"[/color]"BMP DESTROYED"[color="Red"]"[/color]",""];

When you use "" in strings you need to double them up so the engine knows to actually place a " there and not just end the string.

Share this post


Link to post
Share on other sites

First of all thanks Riouken. You've been a great help so far! I saw psvialli asked what would make the objective from running twice. You said some sort of an array. What can I add to the mission control script to make it not call on a mission that was already called on?

Second of all,

waitUntil{!(isNil "BIS_MPF_InitDone")};

// This will hint to everyone currently connected to the game.
[nil,nil,rHINT,"OBJECTIVE COMPLETE."] call RE;

In the code you gave me above what goes where?

The first line goes into the init of the Functions module?

Then the second one gets thrown into my script?

I'm sorry if I sound like an idiot with this scripting, I'm about to start another year of school and will be taking a computer programming class.

What is the scripting language of Arma? C or C++?

Again thanks for your help Riouken.

-Bigshot

EDIT: @Riouken I'm using "script_mk_taskhint_10_mikey" I'm not sure where this is from but I think it might be from Armed Assault.

Edited by bigshotking

Share this post


Link to post
Share on other sites

I'm at work right now, I can give you an example of the array I refrenced when I get home, if Denonized or Kyalania does not post an example before then.

As to the RE code I posted:

Place the waitUntil at the top of any script that you call RE in.

The second line replaces the normal hint code in any place where you need to hint to players in a multiplayer mission.

Share this post


Link to post
Share on other sites

Thanks Kylania!

Still can't seem to get this to pop-up:

[nil,nil,rHINT,""OBJECTIVE COMPLETE.""] call RE;

I've also tried with just single quotes, oh and I also put this in the init of the Function Module:

waitUntil{!(isNil "BIS_MPF_InitDone")};

Thanks for the help guys.

-Bigshot

EDIT: Thanks for the feed back Riouken

Share this post


Link to post
Share on other sites

will post an example later.

Edited by Riouken
needed to rewrite example

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  

×