Jump to content
zeeb

[SOLVED] Jet Fixer Script (When landed & stationary)

Recommended Posts

UPDATED: Script is now working as intended, a little personal tweaks and it should be good to go for extensive use.
I will update the script if anyone comes up with better solutions/performance fixes. (just post them in this thread)

Thank you guys for the assist!

Script: jetFixer.sqf

_veh = vehicle player;

while {true} do {
    waitUntil {
        sleep 1;
        getPosATL _veh # 2 < 10 &&
        speed _veh == 0
    };

    hint "Your jet will be fixed in 10 seconds";
    _veh setFuel 0;
    sleep 10;
    
    _veh setDamage 0;
    _veh setFuel 1;
    _veh setVehicleAmmo 1;
    
    hint "Your jet has been fixed (Cooldown 30 seconds)";
    sleep 30;
};

Init.sqf:

// Jet Fixer
this = [] execVM "scripts\jetFixer.sqf";

_No Longer Relevant_
Anyone know what I'm doing wrong?
Because I get the Missing ; error.

Besides, I don't think this script will work, but you never know. (I used the biki to find the info)

😅

Share this post


Link to post
Share on other sites

An if statement always requires the basic syntax of if () then {}.

You're missing the "then" part.

 

Also check those round brackets, they don't add up.

 

Cheers

Share this post


Link to post
Share on other sites

Hey, I've seen you around this forum a lot helping people out, I appreciate you stopping by.

I've fixed that issue, but as usual another one pops up..
This time it says Type Script, expected Object

This is the updated code:

_veh = this;

if ((getPosATL _veh) < 10) && ((speed _veh) == 0) then
{
	hint "Stay parked for 10 seconds to fix your jet.";
	sleep 10;
	_veh setDamage 0;
	_veh setFuel 1;
	_veh setAmmo 1;
	hint "Your jet has been fixed, you are ready for takeoff!";
};

If I use this select 0, I get met with a Type Script, expected Array,String,Config entry

Share this post


Link to post
Share on other sites

That's because you don't pass anything into the execVMed script, the first parameter is mandatory if you want to pass stuff inside the scope of a called/spawned/execVMed snippet.

Depends on were you're using this line, in the objects init field it could be something like this:

//jet init field
_this = this execVM "scripts\jetFixer.sqf";

Also use params to declare passed variables inside a scope, like this:

params ["_veh"];

if (((getPosATL _veh # 2) < 10) && ((speed _veh) == 0)) then
{
	hint "Stay parked for 10 seconds to fix your jet.";
	sleep 10;
	_veh setDamage 0;
	_veh setFuel 1;
	_veh setAmmo 1;
	hint "Your jet has been fixed, you are ready for takeoff!";
};

Also fixed the missing bracket and a possible oversight with getPosATL (I believe you want the altitude be below 10).

Not tested but should do the trick.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
Quote

EDIT: Nevermind, was a typo, accidentally used setAmmo instead of setVehicleAmmo.
Now I just need a loop so it doesn't run only once and it's pretty much done! Will upload the complete script when it's finished. 😀



I didn't get any errors, but the script didn't execute correctly. 😕
Why use params ["_veh"]; instead of _veh = this select 0;?


Indeed, I want the jet to repair, rearm and refuel when it's on the ground and parked after a set amount of time. I'm making a 5v5 jet fighter mission with sector control without missiles, so I want the players to be able to rearm after landing instead of using infinite ammo since the cannon on the jets has very limited ammo.

 

Thanks for taking your time!

Share this post


Link to post
Share on other sites

this means nothing in a script, but _this does work for a script. Note the difference between this and _this. Don't forget this and do not miss the underscore.

1 hour ago, zeeb said:

I didn't get any errors, but the script didn't execute correctly. 😕
Why use params ["_veh"]; instead of _veh = this select 0;?

params ["_veh"]; is really useful way to assign multiple variables. Of course, you just can _veh = _this select 0 or _veh = _this#0 also. (select and # are equivalent. I prefer the later.)

Also, GOM missed a thing so it won't work.

_this = [this] execVM "scripts\jetFixer.sqf";

Try this instead. At least, it will work, as not intended as your wish though.

Share this post


Link to post
Share on other sites

Thank you for the explanations, I had to actually check the difference on the underscore and without, turns out I had them backwards.
I didn't actually know that select 0 and #0 was the same, will use the latter going forward. This explains the #2 that Grumpy added.

Thanks, I'll try it out and it's totally OK if it doesn't work as intended (Which it doesn't by the way haha), just means I got some learning to do. 🙂

Share this post


Link to post
Share on other sites
6 minutes ago, POLPOX said:

Also, GOM missed a thing so it won't work.


_this = [this] execVM "scripts\jetFixer.sqf";

Try this instead. At least, it will work, as not intended as your wish though.

You can also use

 

_this = this execVM "scripts\jetFixer.sqf";

instead.

When using params inside the .sqf there should be functionally no difference.

See example 2 on the wiki:

 

[123] call {
	params ["_myvar"];
};

// Below would produce the same result as above
123 call {
	params ["_myvar"];
};

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks Grumpy!

By the way guys, how come this one is not working?
while {(_veh ammo primaryWeapon) == 0} do { //stuff here };

It gives me Generic error in expression.
And what is up with the while{}, shouldnt it be while()?

Share this post


Link to post
Share on other sites
2 minutes ago, zeeb said:

while {(_veh ammo primaryWeapon) == 0} do { //stuff here };

It gives me Generic error in expression.
And what is up with the while{}, shouldnt it be while()?

primaryWeapon requires unit to work. So, (_veh ammo primaryWeapon _veh) == 0 is the code supposed to be... BUT, primaryWeapon only works for a soldier not for vehicles.

 

Also the question, the short answer is it just does, the long answer is while needs a code which defined in {} rather than regular brackets () because needs to evaulate the code everytime when it starts another loop to get the boolean. If is while ((player ammo primaryWeapon player) == 0) do {/*thing*/}; and if the player's rifle's empty when it runs, will never stop even if it's not empty anymore. It's unlike an if statement, which only needs to get the boolean for once.

Share this post


Link to post
Share on other sites

Ah, thank you.
Just confused me since it's while() in C++. 😜

Anyway, I managed to fix it. Now I just have to find out how to globally find the turret on each plane. (Which is why I tried primaryWeapon, really hoped it would work 😕)
I don't want it to trigger just because you lack some flares, rather only when turret ammo is 0.


Back to reading!

Share this post


Link to post
Share on other sites

Tried to make a global ammo check script, but it didn't work. Don't know why it wont, but I'm so tired right now that I have no energy left to read anymore biki.
Been at this script for a few hours now and the batteries are empty.

If you have any inputs on why it wont work the script is below (tried to remove the vehicle init to make it affect all player driven vehicles present in the mission):

_veh = (vehicle player);

_gun = currentWeapon _veh;
_vehNoAmmo = false;

while {true} do {
	if ((_veh ammo _gun) == 0) then {
		_vehNoAmmo = true;
	};
};

while {_vehNoAmmo} do {
	hint "Your jet will be rearmed in 10 seconds.";
	sleep 10;
	_veh setVehicleAmmo 1;
	hint "Your jet has been rearmed!";
	_vehNoAmmo = false;
};

This is in the Init.sqf:

// Jet Rearm
execVM "scripts\jetRearm.sqf";

 

Share this post


Link to post
Share on other sites

May I suggest,

waitUntil {
		sleep 5;
		(_veh ammo _gun) == 0
			};
	_vehNoAmmo = true;
};

With several functions running at the same time While True will affect performance.

 

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your input, switched out the while{true} statement. 🙂

Do you know how I can call this globally on all player controlled vehicles? Because when everything works as it should I'll have to tackle adding infinite ammo to AI controlled vehicles.
Which may turn bothersome since AI and players share the same vehicles, depending on how many players are playing the mission. But I don't know, it might be really easy.

Like:

if (isPlayer) then {
	// Land, go stationary for 10 seconds, rearm/refuel/repair.
} else {
	// Get infinite ammo
};

More or less what I'm going for.

Share this post


Link to post
Share on other sites

Add this EH to your AI controlled vehicles for infinite ammo,

this addeventhandler ["Fired",{ 
 (_this select 0) setvehicleammo 1; 
}]; 

And perhaps remove it when player takes control of vehicle.
 

  • Like 1

Share this post


Link to post
Share on other sites

Appreciate the assist.
I already do have that line of code, however I haven't found out yet how to only implement it when vehicle is controlled by the AI and not the player.
However, I guess I'll put that last on the list since the rearm/repair/refuel function for the players is of higher priority, been at it for some time now haha.

 

Share this post


Link to post
Share on other sites

I tried this script:

params ["_veh"];

_gun = currentWeapon _veh;
_vehNeedAssist = false;

null = [] spawn {
	while {true} do {
		waitUntil {
			sleep 1;
			(getPosATL _veh # 2) < 10;
			(speed _veh) == 0;
			true
		};
		
		_vehNeedAssist = true;
	};
};
	
while {_vehNeedAssist} do {
	hint "Stay parked for 10 seconds to fix your jet";
	sleep 10;
	_veh setDamage 0;
	_veh setFuel 1;
	_veh setVehicleAmmo 1;
	hint "Your jet has been fixed";
	_vehNeedAssist = false;
};

But now I get Undefined variable in expression: _veh.

I've been looking at the BIKI, at other threads etc for solutions and nothing is working, tried with/without brackets, spawn, <insert more stuff here>.

Not gonna lie, after being at it for over 8 hours, without having it working as intended, is taking its toll on my psyche.
About to smash my F'ing keyboard and throw this mission into the trashcan then light it on fire.. 🤬

Share this post


Link to post
Share on other sites

Well, so I assumed your goal and here's my answer, which is really stupid way but simple and work well.

_trg1 = createTrigger ["EmptyDetector",[0,0,0]] ;
_trg1 setTriggerActivation ["NONE","PRESENT",true] ;
_trg1 setTriggerStatements [
	"getPosATL vehicle player#2 < 10 and speed vehicle player < 5",
	"hint 'Stay still for 10 seconds to fix and rearm your jet.'",
	""
] ;

_trg2 = createTrigger ["EmptyDetector",[0,0,0]] ;
_trg2 setTriggerActivation ["NONE","PRESENT",true] ;
_trg2 setTriggerStatements [
	"getPosATL vehicle player#2 < 10 and speed vehicle player < 5",
	"
		_veh = vehicle player ;
		_veh setDamage 0 ;
		_veh setFuel 1 ;
		_veh setVehicleAmmo 1 ;
		hint 'Fixed and rearmed, locked and loaded!'
	",
	""
] ;
_trg2 setTriggerTimeout [10,10,10,true] ;

 

  • Like 2

Share this post


Link to post
Share on other sites

Thank you man, I appreciate you helping out, I'll check it out! 🙂

Anyway, it's more or less solved, I'll post the working script in the first post.
I thank all of you, you've helped me out a lot and I learned a lot in the process!

Keep doing what you're doing. ❤️

  • Like 1

Share this post


Link to post
Share on other sites
10 hours ago, zeeb said:

// Land, go stationary for 10 seconds, rearm/refuel/repair.

 

Hello there zeeb !

 

You can also try to use an eventhandler instead of a loop , in order to save some performace.

Take a look here :

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers

  • Like 1

Share this post


Link to post
Share on other sites

Thank you George, I'm actually planning on learning Event Handlers today so that BIKI link will come in handy.
Appreciate your help! 🙂

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

×