joew 0 Posted June 19, 2017 How to start count how many km the player drive and exec some function after he drove X km? For e.g I want the script to exec something after the player drove 5+ km... Thank you!!! Share this post Link to post Share on other sites
JSD 18 Posted June 19, 2017 is it literally driving 5 km or should the player be 5 km away from a certain point? For the last one something like waitUntil {player distance *startingpos* > 5000}; might do. Share this post Link to post Share on other sites
joew 0 Posted June 19, 2017 49 minutes ago, JSD said: is it literally driving 5 km or should the player be 5 km away from a certain point? For the last one something like waitUntil {player distance *startingpos* > 5000}; might do. Thank you JSD!!!! But it is the first option: literally driving 5 km. The starting pos don't matter, for ex. the player can go ahead 3km and came back 2km, this will get 5km. Do u knew any way, please? Share this post Link to post Share on other sites
JSD 18 Posted June 19, 2017 Just now, joew said: Thank you JSD!!!! But it is the first option: literally driving 5 km. The starting pos don't matter, for ex. the player can go ahead 3km and came back 2km, this will get 5km. Do u knew any way, please? I'm not sure about any actual way of doing it but you may just check the position every few seconds, get the distance from the last position and then add the distance to some variable. I'm not too good at this :P This may do?: (Haven't tested or anything) _distance = 0; _oldPos = position player; waitUntil { // wait a few seconds sleep 5; // get the traveled distance and add it to the distance variable _traveledDistance = _oldPos distance position player; _distance = _distance + _traveledDistance; // set position for next cycle or whatever it's called _oldPos = position player; // go ahead if the distance is over 5000 _distance > 5000; }; 1 Share this post Link to post Share on other sites
joew 0 Posted June 19, 2017 1 hour ago, JSD said: I'm not sure about any actual way of doing it but you may just check the position every few seconds, get the distance from the last position and then add the distance to some variable. I'm not too good at this :P This may do?: (Haven't tested or anything) _distance = 0; _oldPos = position player; waitUntil { // wait a few seconds sleep 5; // get the traveled distance and add it to the distance variable _traveledDistance = _oldPos distance position player; _distance = _distance + _traveledDistance; // set position for next cycle or whatever it's called _oldPos = position player; // go ahead if the distance is over 5000 _distance > 5000; }; Thank you @JSD!!! I will test it and reply here when I'm done! Share this post Link to post Share on other sites
Belbo 462 Posted June 19, 2017 I once made this mileage counter: https://github.com/Pergor/ADV_MissionTemplate/blob/master/adv_missiontemplate.altis/functions/unused/fn_mileage.sqf Maybe that's something for you. Share this post Link to post Share on other sites
killzone_kid 1329 Posted June 19, 2017 You can set up a trigger and add distance every 0.5 sec fnc_chkMileage = { params ["_veh", "_limit", ["_driven", 0]]; private _counter = createTrigger ["EmptyDetector", [0,0,0], false]; _counter setVariable ["data", [_veh, _limit, _driven, getPosWorld _veh]]; _counter setTriggerStatements [ ' thisTrigger getVariable "data" call { params ["_veh", "_limit", "_driven", "_lastPos"]; _newPos = getPosWorld _veh; _driven = _driven + (_lastPos vectorDistance _newPos); _this set [2, _driven]; _this set [3, _newPos]; _driven >= _limit } ', ' hint "distance complete"; deleteVehicle thisTrigger; ', '' ]; }; // example [car, 1000] call fnc_chkMileage; After about 1000m the hint will pop up 1 Share this post Link to post Share on other sites