Jump to content
Sign in to follow this  
A-SUICIDAL

ATV Action "Flip/Repair ATV"

Recommended Posts

An example of how much of a determined novice scripter I am.

I flipped my ATV on its side when I hit a very tiny rock. I got pissed. My friend laughed. I left the game and came back a half an hour later and asked him to join my game for a minute, then I introduced him to my new ATV vehicle. Broom! Broom!

Here is the example mission:

flip_repair_atv.Takistan.zip

This script will add an action to your ATV that will appear only if the ATV is damaged or lying on its side or both. When the action is performed while still riding on the vehicle, it will first remove the action, then it will make you hop off, locks the vehicle, sets your position 1 meter from the vehicle, turns you 170 so you are facing the vehicle, sets the vehicle back on its feet again, then an animation starts where you turn even more towards the vehicle, then kneel and repair the for 20 seconds, sets the vehicle back to full health, then switches you to a kneeling position with weapon lowered, unlocks the vehicle, then you are free to hop back on and keep driving. If you hop off the vehicle first and then choose the action to "Flip/Repair" the vehicle, the same functions are performed.

I have multiple remove action commands because I don't know how to create variables and all that select 0 and select 1 stuff, so I am asking for help from the experts here to help me make my novice script more professional. I'm sure that there is an entirely different and better way to accomplish what I am trying to do, but for now, it does work and I am using it in my current mission creation. It makes perfect sense that you should be able to flip an ATV back on it's feet using your muscles and that there would be a console in the vehicle containing a can of Fix-A-Flat and a simple toolkit. This script is not meant for 10000 ton tanks.

Share this post


Link to post
Share on other sites

You can simply put the condition into the action itself so that it will appear only when the conditions are met. _this is the array of arguments that are passed into the executed script. With addAction the first argument is the object with the action and the second one is the caller of the action. By defining them and referring to them in the script you can make the script more universal so that it can work for any vehicle that has the action or unit that repairs it.

Using "player" in scripts can create horrible bugs in MP because it refers to the player unit on each client, so every player will be affected by the same command.

ATV's init:

this addAction ["Flip/Repair ATV","flip_repair_atv1.sqf",nil,true,true,"","!canMove atv1 or damage atv1>0"]

Script:

_atv=_this select 0;
_unit=_this select 1;

_atv lockDriver true;
_atv lockCargo true;
_unit setPos [ getPos _atv select 0, (getPos _atv select 1) +1, getPos _atv select 2];
_atv setPos [ getPos _atv select 0, (getPos _atv select 1) +0, getPos _atv select 2];
_unit switchMove "RepairingKneel";
_unit setDir 170;
_atv setDamage 0;
sleep 20;
_unit switchMove "aidlpknlmstpslowwrfldnon_idlesteady02";
_atv lockDriver false;
_atv lockCargo false;

Share this post


Link to post
Share on other sites

The stuff you had for the init gave me errors. Typo maybe? IDK

---------- Post added at 10:40 PM ---------- Previous post was at 10:26 PM ----------

Also, the way you have it set up it's not removing the action.

I found a way to remove the action at Kylania's example script page here.

So I incorporated it in the script.

I went back to using a trigger to detect and here's what I changed in the script:

_atv = _this select 0;
_unit=_this select 1;
_p = _this select 0;
_id = _this select 2;
[_p] joinSilent _unit;
_p removeaction _id;
_atv lockDriver true;
_atv lockCargo true;
_unit setPos [ getPos _atv select 0, (getPos _atv select 1) +1, getPos _atv select 2];
_atv setPos [ getPos _atv select 0, (getPos _atv select 1) +0, getPos _atv select 2];
_unit switchMove "RepairingKneel";
_unit setDir 170;
_atv setDamage 0;
sleep 20;
_unit switchMove "aidlpknlmstpslowwrfldnon_idlesteady02";
_atv lockDriver false;
_atv lockCargo false;

---------- Post added at 10:52 PM ---------- Previous post was at 10:40 PM ----------

Bugs so far:

1.) You can choose to repair the vehicle from like 10 meters away, where as the action to get in the vehicle appears from like 2 or 3 meters away. I need a way to decrease the action distance some how.

2.) The vehicle still offers the action after the vehicle has been completely destroyed. I need a way to remove the action if it's destroyed.

3.) If you get shot and killed while repairing the vehicle, the repair animation continues and when the animation completes moments later, that's when it finally shows your death animation. I need a way to stop the repair animation from continuing if the player is shot and killed.

Share this post


Link to post
Share on other sites

Celery, I would like to use what what you posted above for the ATV's Init field, but because it gave me an error, I went back to using the triggers that I originally had set up. Can you double check what you wrote?

Share this post


Link to post
Share on other sites
The stuff you had for the init gave me errors. Typo maybe? IDK

Sorry, forgot the priority value:

this addAction ["Flip/Repair ATV","flip_repair_atv1.sqf",nil,1,true,true,"","(!canMove atv1 or (damage atv1>0 and damage atv1<1)) and player distance atv1<3"]

Defining _this select 0 again is useless and the action shouldn't be removed because it appears only when the conditions are met anyway. Remove this bit from the script:

_p = _this select 0;

_id = _this select 2;

[_p] joinSilent _unit;

_p removeaction _id;

Share this post


Link to post
Share on other sites

Instead of atv1 in the condition use _target that way you don't have to retype and keep track of atv object names for every addAction.

Share this post


Link to post
Share on other sites

Sorry for the necropost, but I just wanted to say thanks a lot for this-- it implemented smoothly and will really help improve the mission I am working on.

Share this post


Link to post
Share on other sites

A friend of mine asked me for my repair script recently and found this thread. I just wanted to update the thread with what I am currently using in my missions for repairing/flipping a vehicle.

This will add the action (in red) to repair or flip the vehicle if it is alive and damaged or unable to move (on it's side).

In the init of any vehicle, for this example and ATV, just add this:

this addAction [("<t color=""#FF0000"">" + ("Repair ATV") + "</t>"),"veh_repair.sqf",nil,+50,true,true,"","alive _target && (!canMove _target or (damage _target>0 and damage _target<1)) and player distance _target<5"];

veh_repair.sqf:

_veh = _this select 0;
_unit = _this select 1;

if ( vehicle _unit != _unit) then {
       hint "You must disembark before you can perform this action.";
       sleep 6;
       hint "";
} else {
if (isEngineOn _veh) then {
       hint "You must turn engine off before you can perform this action.";
   	sleep 6;
   	hint "";
} else {
       _veh lock true; //so you can't get back into the vehicle while repairing.
_unit switchMove "AinvPknlMstpSlayWrflDnon_medic"; //repair animation.
sleep 4;
_unit switchMove "amovpknlmstpsraswrfldnon_gear";  //for quick repairs - this stops the animation sooner and returns the player to a crouched position aiming their rifle.

   	_veh setPos [ getPos _veh select 0, (getPos _veh select 1) +0, getPos _veh select 2];
   	_veh setpos [ getPos _veh select 0, getPos _veh select 1, +0.01]; 

  	_veh setDamage 0;
  	_veh lock false;
};
};

When I look back at my original post I think, omg I really sucked at scripting back then, lol.

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  

×