froggyluv 2136 Posted January 9, 2015 Trying to get one of just one of these cameras (either player or killer) to play randomly based off distance of player to killer just before Vanilla Death cam takes over. Ideally I'd love to play both cams but it seems impossible to stop the Vanilla death cam grainy drone stuff.. player = _this select 0; _killer = _this select 1; [b] if[/b] (_player distance _killer < 30) then {_camera = "camera" camCreate [(position _killer select 0)-0.75, (position _killer select 1)-0.75,(position _killer select 2) + 0.5]; _preload = [] spawn {waitUntil{preloadCamera [4516.60,2606.42,1.73]}}; _camera cameraEffect ["internal","back"]; _camera camSetFOV 1; _camera camSetTarget vehicle _killer; if(vehicle player != player) then {_camera camSetRelPos [0,10,1]}else{_camera camSetRelPos [0,2,1]}; _camera camCommit 0; waitUntil {camCommitted _camera}; _camera camCommand "inertia on";} [b]else[/b] {_camera = "camera" camCreate [(position _player select 0)-0.75, (position _player select 1)-0.75,(position _player select 2) + 0.5]; _preload = [] spawn {waitUntil{preloadCamera [4516.60,2606.42,1.73]}}; _camera cameraEffect ["internal","back"]; _camera camSetFOV 1; _camera camSetTarget vehicle _player; if(vehicle player != player) then {_camera camSetRelPos [0,10,1]}else{_camera camSetRelPos [0,2,1]}; _camera camCommit 0; waitUntil {camCommitted _camera}; _camera camCommand "inertia on";}; Share this post Link to post Share on other sites
froggyluv 2136 Posted January 9, 2015 (edited) Trying a different route: _player = _this select 0;_killer = _this select 1; _either = [ _player, _killer] call BIS_fnc_selectRandom;; _camera = "camera" camCreate [(position _either select 0)-0.75, (position _either select 1)-0.75,(position _either select 2) + 0.5]; _preload = [] spawn {waitUntil{preloadCamera [4516.60,2606.42,1.73]}}; _camera cameraEffect ["internal","back" but it always picks _player and never _killer, no matter what order I place them. If I reverse: _killer = _this select 0;_player = _this select 1; _either = [ _killer, _player]; _random = _either call BIS_fnc_selectRandom; ..then it always plays out _killer...? Why does selectRandom always pick the first array? Edited January 9, 2015 by froggyluv Share this post Link to post Share on other sites
jshock 513 Posted January 9, 2015 It doesn't, it is random, but with only two elements the odds are 50/50, ever time it's executed, so you just happened to have it randomly choose the same one a few times in a row. Share this post Link to post Share on other sites
Grumpy Old Man 3550 Posted January 9, 2015 It's an evenly distributed randomization and thus often doesn't feel entirely random. You could use selectRandomWeighted, and increase the weighting of the cam that hasn't been selected the last few times, then reset the weighting again as you seem fit. So you could initially start with _nul = [[_killer,_player],[0.5,0.5]] call BIS_fnc_selectRandomWeighted; and increase the weighting array depending on which cam was used last time, so you increase the probability of the other cam being chosen next time. Cheers Share this post Link to post Share on other sites
froggyluv 2136 Posted January 9, 2015 It's always choosing whomever is in the "_this select 0" -100% of the time. Somethings up but I don't know what. Grumpy Im assuming you mean: _killer = _this select 0; _player = _this select 1; _random = [[_killer,_player],[b][0.5,0.5]][/b] call BIS_fnc_selectRandomWeighted; _camera = "camera" camCreate [(position _random select 0)-0.75, (position _random select 1)-0.75,(position _random select 2) + 0.5]; _preload = [] spawn {waitUntil{preloadCamera [4516.60,2606.42,1.73]}}; _camera cameraEffect ["internal","back"]; And by changing it to [0.1,0.9]] it would be weighted toward the second option or Select 1, no? I can never get it to choose the 2nd option :( Share this post Link to post Share on other sites
Grumpy Old Man 3550 Posted January 10, 2015 Then take a look at where you're calling this script, seems to be something wrong there. Share this post Link to post Share on other sites
froggyluv 2136 Posted January 10, 2015 Hers my Init.sqf player addeventhandler ["killed", {handle = [(_this select 0),(_this select 1)] execVM "Killcamshort.sqf"}]; and Killcamshort.sqf: _player = _this select 0; _killer = _this select 1; _random = [[_player,_killer],[0.5,0.5]] call BIS_fnc_selectRandomWeighted; _camera = "camera" camCreate [(position _random select 0)-0.75, (position _random select 1)-0.75,(position _random select 2) + 0.5]; _preload = [] spawn {waitUntil{preloadCamera [4516.60,2606.42,1.73]}}; _camera cameraEffect ["internal","back"]; _camera camSetFOV 1; _camera camSetTarget vehicle _killer; if(vehicle player != player) then {_camera camSetRelPos [0,10,1]}else{_camera camSetRelPos [0,2,1]}; _camera camCommit 0; waitUntil {camCommitted _camera}; _camera camCommand "inertia on"; _camera = "camera" camCreate [(position _player select 0)-0.75, (position _player select 1)-0.75,(position _player select 2) + 0.5]; _preload = [] spawn {waitUntil{preloadCamera [4516.60,2606.42,1.73]}}; _camera cameraEffect ["internal","back"]; _camera camSetFOV 1; _camera camSetTarget vehicle _player; if(vehicle player != player) then {_camera camSetRelPos [0,10,1]}else{_camera camSetRelPos [0,2,1]}; _camera camCommit 0; waitUntil {camCommitted _camera}; _camera camCommand "inertia on";}; sleep 4.0; if (not isNull vehicle _killer) then { _camera camSetTarget vehicle _killer; _camera camPreparePos [ getPos vehicle _killer select 0, (getPos vehicle _killer select 1) -10,getPos vehicle _killer select 2]; }else{ _camera camSetTarget vehicle _killer }; _camera camSetFOV 0.3; _camera camCommit 4; waitUntil {camCommitted _camera}; Sleep 3.0; titleCut["", "BLACK out",2]; _player cameraEffect ["terminate","back"]; camUseNVG false; camDestroy _camera; Share this post Link to post Share on other sites
Grumpy Old Man 3550 Posted January 10, 2015 Just tried it, working as expected. Array = []; for "_i" from 0 to 100 do { _result = [["A","B"],[0.5,0.5]] call BIS_fnc_selectrandomweighted; Array pushback _result }; _text = format ["A: %1 B: %2",{_x isEqualto "A"} count Array,{_x isequalto "B"} count Array]; copytoclipboard str _text; "A: 59 B: 42" I fail to see where you're changing the weighting array in the script you posted. Maybe you're overlooking something, is the script actually called "Killcamshort"? Try to do a bit debugging by yourself, never hurts to learn that. Use systemchat str _player; systemchat str _killer; in your script and go from there. Share this post Link to post Share on other sites
froggyluv 2136 Posted January 10, 2015 (edited) Got it! Just had to rewrite and simplify, thanks for your help :) Edited January 10, 2015 by froggyluv Share this post Link to post Share on other sites
froggyluv 2136 Posted January 10, 2015 Two more questions: A. I notice sometimes the camera instantaneously goes to target which is desired, where other times there is a slight delay which takes away the "Bam!" impact feel. Is there a way to ensure script plays immediately via eventhandler? B. Probably obscure question, but I've looked thru the entire function list for whatever controls the inherent BI Death Cam ending with no luck, is there such a function that can be made nil or delayed so that more camera work can be done before it kicks in? Share this post Link to post Share on other sites
froggyluv 2136 Posted January 24, 2015 Now im just getting greedy but I wanna know if it's possible to randomly call an sqf file via addventhandler: _scriptPath = "deathCam\"; _threeKill = ["killCamShort2.sqf", "killCamShort.sqf", "killCam.sqf"]; _randomScript = [_threeKill] CALL BIS_fnc_SELECTRANDOM; player addeventhandler ["killed", {handle = [(_this select 0),(_this select 1)] execVM format ["%1%2",_scriptPath,_randomScript]}]; Deathcam being the folder all 3 sqf files sit in but so far no luck at all. Share this post Link to post Share on other sites
fight9 14 Posted January 24, 2015 use compile to turn string to code Share this post Link to post Share on other sites
jshock 513 Posted January 24, 2015 (edited) Something like this I think: call compile format [ " player addEventHandler [ 'killed', { handle = [(_this select 0),(_this select 1)] execVM %1; } ] ", (_scriptPath + _randomScript) ]; EDIT: Decided to call compile the whole line. Edited January 24, 2015 by JShock Share this post Link to post Share on other sites
froggyluv 2136 Posted January 24, 2015 _scriptPath = "deathCam\"; _threeKill = ["killCamShort2.sqf", "killCamShort.sqf", "killCam.sqf"]; _code = compile _threekill; _randomScript = [_code] CALL BIS_fnc_SELECTRANDOM; player addeventhandler ["killed", {handle = [(_this select 0),(_this select 1)] execVM format ["%1%2",_scriptpath,_code]}]; Still no cigar :n: Sorry Jshock can't quite following what your up to Share this post Link to post Share on other sites
fight9 14 Posted January 24, 2015 (edited) Oh, i think eventHandler code is in its own scope. The above local variables are not defined within. player addEventhandler ["killed", { _files = ["killCamShort2.sqf", "killCamShort.sqf", "killCam.sqf"] call BIS_fnc_selectRandom; _script = format ["deathCam\%1",_files]; handle = [(_this select 0),(_this select 1)] execVM _script; } ]; Sorry about the compile comment. I was thinking call, not execVM. The difference is you call code rather than a string. Or try using a string instead of code: _files = ["killCamShort2.sqf", "killCamShort.sqf", "killCam.sqf"] call BIS_fnc_selectRandom; _script = format ['[(_this select 0),(_this select 1)] execVM "deathCam\%1"',_files]; player addEventHandler ["killed",_script]; Edited January 24, 2015 by Fight9 code errors Share this post Link to post Share on other sites
froggyluv 2136 Posted January 24, 2015 Well damn fight9 that looked it was gonna be the winner but still a no go and i have no idea why... Share this post Link to post Share on other sites
fight9 14 Posted January 24, 2015 The last one worked for me through the debug console. Edit: both of these version worked for me. player addEventhandler ["killed", { _files = ["killCamShort2.sqf", "killCamShort.sqf", "killCam.sqf"] call BIS_fnc_selectRandom; _script = format ["deathCam\%1",_files]; handle = [(_this select 0),(_this select 1)] execVM _script; } ]; _files = ["killCamShort2.sqf", "killCamShort.sqf", "killCam.sqf"] call BIS_fnc_selectRandom; _script = format ['[(_this select 0),(_this select 1)] execVM "deathCam\%1"',_files]; player addEventHandler ["killed",_script]; Share this post Link to post Share on other sites
froggyluv 2136 Posted January 24, 2015 Oh ffs I had an old folder of 'Deathcam' in my root folder so the config was constantly calling that rather then the one in the .pbo itself- I didnt even know that was possible :o Thanks alot man, they both do work beautifully. Share this post Link to post Share on other sites