Jump to content
Sign in to follow this  
jakkob4682

How to call a script?

Recommended Posts

I know how to create a script and then set the parameter and call it with execVM"somescript.sqf", however what I'm looking for is something like this

hitman = _this select 0
asset = _this select 1;
target = _this select 0;

{
	if ((faction _x == "USMC")&&(typeOf _x == "USMC_SoldierS_Sniper")&&(isPlayer _x)) then {
		hitman = _x;
	};
}forEach allUnits;

{
	if (typeOf _x == "USMC_Soldier_Officer") then {
		asset = _x;
	};
}forEach allUnits;

if (hitman distance asset < 5) then {
	tsk1 = hitman createSimpleTask ["contracts","target one"];
	tsk1 setSimpleTaskDescription ["Youve been assigned target one a local insurgent recruiter who may have intel on other targets in the area","first target is a recuiter","recruiter"];
	{
		if ((side _x == east)&&(typeOf _x == "TK_INS_Warlord")) then {
			target = _x;
			tsk1 setSimpleTaskTarget [target,true];
			};
	}forEach allUnits;
	};
if !((alive target)&&(hitman distance asset < 5)) then {
	tsk1 setTaskState "Succeeded";
	tsk2 = hitman createSimpleTask ["contracts","target two"];
	tsk2 setSimpleTaskDescription ["Good job on the kill but we have bigger problems now. A local engineer has been making ieds for the insurgents. We need to kill him","Kill the engineer","target two"];
	{
		if (typeOf _x == "INS_Soldier_sab") then {
			target = _x;
			tsk2 setSimpleTaskTarget [target,true];
			};
	}forEach allUnits;
	};
if ((taskCompleted tsk1)&&!(alive target)) then {
	tsk2 setTaskState "Succeeded";
	};

if ((taskCompleted tsk1)&&(taskCompleted tsk2)) exitWith {
	"All contracts complete return to base";
	};
[hitman,asset,target];	
Hitman = compile scriptThis;

will this work? basically i want to create a script that does two things, when hitman gets within 5 meters it creates the first task, after that task is done, it checks for the distance again then assigns a second task. The script isn't complete

Edited by jakkob4682
completed script w/ task check for 2nd task

Share this post


Link to post
Share on other sites

Hi. Honestly, you should complete the script & test it. If there's some problems you can't work out, then post you're script and explain what it's supposed to do and what it is doing currently. From the looks of it, the conditions look like they would work. Personally, I couldn't go any further than telling you that, becasue I would then have to try and test a uncompleted script, testing bits and pieces I suppose... etc etc.

Share this post


Link to post
Share on other sites

editted script to complete it, to check if target is alive and 1st task is complete.

---------- Post added at 19:37 ---------- Previous post was at 19:27 ----------

The next thing I want to do create another set of tasks once the player reaches another position but I want to be able to call the hitman function from the 2nd script if you know what i mean. So basically

if (hitman in _array) then {
hitman = compile "hitmantasks.sqf"// the original script that create the tasks
call hitman;
};

but I want to be able to change the value of target from the 2nd script so that it references different class names/objects etc.

Edited by jakkob4682
editted code

Share this post


Link to post
Share on other sites

Have you tested it to see if it works? If so, what are your findings? Any errors? Does it work as expected? These are the things you need to post.

Share this post


Link to post
Share on other sites

can I call this script from the init.sqf without setting the parameters? since the values are dynamic will it matter?

---------- Post added at 20:06 ---------- Previous post was at 19:41 ----------

It won't create the first task for some reason, and the distance check isn't working. When the mission starts I am more than 5 meters away from asset and it just creates the 2nd task. nothing in the rpt file either.

---------- Post added at 20:20 ---------- Previous post was at 20:06 ----------

still not working, not sure if its something to do with the syntax or not since theres no rpt errors, I'm wonder if the position of ! is the cause of the issue i.e.

is there a difference between
!((alive target)&&(taskCompleted tsk1))
(!(alive target)&&(taskCompleted tsk1))
((!alive target)&&(taskCompleted tsk1))

Share this post


Link to post
Share on other sites

The first check will never be true unless you're directly infront of asset.

Use waitUntil instead.

It'll create the second task since you are more than 5m away from the target, and _target hasn't been defined yet (as far as I can see, I don't know if you pass anything to the script), so the second check is true.

Try something like this:

waitUntil {hitman distance asset < 5};

This halts the script until the first condition is true.

Sadly I can't actually copy the whole script since it cuts it down to 2 lines, so I cut it down.

Share this post


Link to post
Share on other sites
The first check will never be true unless you're directly infront of asset.

Use waitUntil instead.

It'll create the second task since you are more than 5m away from the target, and _target hasn't been defined yet (as far as I can see, I don't know if you pass anything to the script), so the second check is true.

Try something like this:

waitUntil {hitman distance asset < 5};

This halts the script until the first condition is true.

Sadly I can't actually copy the whole script since it cuts it down to 2 lines, so I cut it down.

now the problem is the 2nd task isnt updating after I kill the target, I don't want to several different variables for each task, would rather have one variable accessable by all tasks and just change it after the target dies the first time.

Share this post


Link to post
Share on other sites

For some reason I can't get it to add tsk2 after target is dead. Is it possible to still use target as the variable after the first task? Or do I need to use a different variable for that?

i.e.

waitUntil {!(alive target

---------- Post added at 03:17 ---------- Previous post was at 02:27 ----------

do i need to add another variable for that such as target1?

Edited by jakkob4682
spelling

Share this post


Link to post
Share on other sites

Are you making sure you're right next to asset? (So the Officer)

Try placing a hint under the waitUntil !{(alive target) && (hitman distance < 5)}.

Actually I just noticed, due to the ! being infront of the whole, the distance of the hitman towards the asset has to be greater than 5, since it only checks for false statements.

But as I said, try placing a hint "debug" or something after the WaitUntil to see if it kicks off.

Share this post


Link to post
Share on other sites
Are you making sure you're right next to asset? (So the Officer)

Try placing a hint under the waitUntil !{(alive target) && (hitman distance < 5)}.

Actually I just noticed, due to the ! being infront of the whole, the distance of the hitman towards the asset has to be greater than 5, since it only checks for false statements.

But as I said, try placing a hint "debug" or something after the WaitUntil to see if it kicks off.

After adding hintSilent "player is within range of asset" it only fires once, the first time i get within range of the officer, added a teleport trigger to go back and forth quickly to and from the asset as well, 2nd task isnt updating, and target doesn't get reassigned.

Can I use a setVariable command on the variable target for something like

target setVariable ["alive",true,false];
if !(alive target) then {
target setVariable ["alive",false,false];

i guess its a question of how do I assign a value to target after the original target is killed.

Share this post


Link to post
Share on other sites

The reason why it does not update is because it only checks every if statement once and does not halt if the first if-statement is true.

To prevent this, try to execute the script again once the first task is complete, so the script checks everything once again.

Share this post


Link to post
Share on other sites

at the risk of getting humiliated... what exactly do you mean by execute the script again once the first task is complete? I tried using a second waitUntil command to check if taskCompleted tsk1 and not alive target and that didn't work either.

---------- Post added at 20:34 ---------- Previous post was at 20:19 ----------

	
if !(alive target) then {
           tsk1 setTaskState "Succeeded";
};	

{	
if (typeOf _x == "INS_Soldier_Sab") then {
target = _x;
tsk2 = hitman createSimpleTask ["Bomb Maker"];			
tsk2 setSimpleTaskDescription ["We found a laptop that had a local ied makers address on it go investigate the address","Local IED Manufacturer","bomb maker "];            
tsk2 setSimpleTaskTarget [target,true]; 			
tsk2 setTaskState "Assigned";			
hitman setCurrentTask tsk2;
};	
}forEach allUnits;	

Edited by jakkob4682
formatting

Share this post


Link to post
Share on other sites

waitUntil !{alive target};             tsk1 setTaskState "Succeeded";
nul = [whateveryoupassedtothescript] execVM "scriptname.sqf";

This executes the script again, but this can sometimes cause problems, like the task getting set to succeeded once again. I haven't found a suitable way to fix this though.

Share this post


Link to post
Share on other sites

Yeah i figured out that I need to put in the waitUntil command thanks for all the help!!! very informative and definitely learned a lot from this

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  

×