Jump to content
Sign in to follow this  
wontial

Help with simplifying (improving?) my stupid and dirty script

Recommended Posts

In my mission an engineer tries to repair an immobile tank while other crews try to protect him. The repair takes time (100s) and in the meantime insurgents try to flank them.

At first I wanted to make a repair progress bar but in the end I just settled for repair percentage showing up with hint command. This is what I came up with -

hint "Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - 1%";

sleep 1;
hintSilent "Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - 2%";

sleep 1;
hintSilent "Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - 3%";

sleep 1;
hintSilent "Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - 4%";

.
.
.
sleep 1;
hintSilent "Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - 100%";

sleep 1;
hint "Emergency Repair Complete";

Yes, yes, ugly as hell, inefficient and stupid but its the best my jello brains was able to come up with and it does get the job done. (Almost :p)

But the problem lies when I try to change the time period. There's going to be dozens of repairs in my mission with each repairs taking different time.

This one takes 100 seconds, but other ones take 60 seconds, 2 minutes and so on.

It is excruciatingly painful and ugly trying to change the "sleep" numbers each time, thus I am seeking help and advice for keeping it short and simple.

I would really like to learn how this could be simplified, my knowledge of these scriptings are meager at best.

Any help would be greatly appreciated.

Thanks in advance!

Edited by wontial
Pressed enter by mistake

Share this post


Link to post
Share on other sites

private ["_seconds"];
_seconds = _this select 0;

hint "Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - 0%";
sleep 1;

for "_i" from 1 to _seconds do
{
   hintSilent format ["Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - %1%", round ((_i / _seconds) * 100)];
   sleep 1;
};

hint "Emergency Repair Complete";

A cleaner quick and dirty script. :) Save in an .sqf file and launch with:

_dummy = [100] execVM "[color="Red"]scriptname.sqf[/color]";

Replace 100 with the number of seconds you want.

Edited by bhaz
derp, forgot sleep

Share this post


Link to post
Share on other sites

Don't forget to pass the vehicle too:

_dummy = [100, MyVehicle] execVM "scriptname.sqf";

You can get it using

_vehicle = _this select 1;

Then when repair is done remember to actually repair it:

_vehicle setDamage 0.0,

Share this post


Link to post
Share on other sites

You can't have a percentile sign in format (it will not show up). Use this to work around it:

hintSilent format ["Emergency Repair in Progress \n Protect the engineer at all cost!\n\n Repairing - %1%2", round ((_i / _seconds) * 100), "%"];

Share this post


Link to post
Share on other sites

Beautiful. It works like a charm :)

Bhaz, thank you for the nicely wrapped script and muzzle deadfast thank you for the additional advice, it achieved exactly what I had in mind.

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  

×