Jump to content
Sign in to follow this  
BEAKSBY

How do I get the identify avehicle using cursortarget?

Recommended Posts

HI Folks,

I would like the repair the vehicle while my player is looking at it with the cursor, not from inside.

I've added a Repair addAction to the vehicle:

_vehType = _this select 0;
_tank = createVehicle [_vehType, [037,079], [], 0, "NONE"];  
_tank setPos [(_pos select 0), (_pos select 1), 0];

_tank addAction [("<t color=""#66FFFF"">" + ("Repair/Flip") +"</t>"), {[_vehType] execvm "Repair.sqf"}];

Repair.sqf

_veh = _this select 0; 

_timeForRepair = 2;

if (!isnull cursortarget) then { _object = cursortarget}; // name of object
_veh = (vehicle player);  
 hint format ["Please wait %1 seconds to repair _veh: %2 \n vehicle player: %3 \n _object %4",_timeForRepair, _veh, (vehicle player), _object]; 
sleep _timeForRepair;
_veh setFuel 1;
_veh setDamage 0;
_veh setVehicleAmmo 1;
_veh setpos [getpos _veh select 0, getpos _veh select 1, 0];

But _veh results in the player and so does vehicle player?

_object resutls in any

How do identify the vehicle the player's cursor is targetting and how then how can I repair it from outside?

Share this post


Link to post
Share on other sites

Well, the reason _object is resulting in any is because you're defining it in a different scope than you're calling it from.

Try adding private["_object"] at the top or simply define _object = objNull; anywhere above your if/then statement.

Share this post


Link to post
Share on other sites

Nevermind, solved it with ...

_

veh = "";
_timeForRepair = 2;

_pos  = screenToWorld [0.5,0.5];// land position 
if (!isnull cursortarget) then { _veh = cursortarget}; // name of object
//_veh = (vehicle player);  

sleep _timeForRepair;
_veh setFuel 1;
_veh setDamage 0;
_veh setVehicleAmmo 1;
_veh setpos [getpos _veh select 0, getpos _veh select 1, 0];

hint format ["Please wait %1 seconds to repair _veh: %2 \n vehicle player: %3",_timeForRepair, _veh, (vehicle player)];

Thanks for the quick response Horner...

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  

×