Jump to content

Recommended Posts

Hi all,

I'm trying to add a feature to a scenario which will allow players to use a menu action to create a camera (in this case a kestrel) which they can fly around in. Then, once they are done scouting, can use another menu action to destroy the camera and return to controlling their soldier.

 

Just on a quick testbed scenario I have the following scripts.

In my init.sqf I have

Quote

player addAction ["Spread your wings", "flyfree.sqf"];

 

Then I have two scripts.

 

In "flyfree.sqf" is have

Quote

_caller = _this select 1;
_caller removeAction 0;
cam = "Kestrel_Random_F" camCreate (_caller modelToWorld [0,0,20]);
cam cameraEffect ["FIXED", "BACK"];
cam camCommand "MANUAL ON";
_caller addAction ["Return to your body", "stopflying.sqf"];

///and then a loop I made to fix the camera problem I had where the "external" view of the kestrel camera kept clipping through the model
while {true} do
{cam cameraEffect ["FIXED", "BACK"];};

 

In "Stopflying.sqf" I have:

Quote

player removeAction 0;
cam cameraEffect ["TERMINATE", "BACK"];
camDestroy cam;
_caller addAction ["Spread your wings", "flyfree.sqf"];

 

Thus far the main problem I am encountering is that I cannot get any menu actions when you are transferred to controlling the camera. Is this an inherent feature of Arma with no workaround?

A second minor problem which may be my client is that in the debug commands I can destroy the camera, but it doesn't automatically return to controlling the soldier.

 

Any help will be greatly appreciated!

 

Thanks

Share this post


Link to post
Share on other sites

The fact that you cannot use the add action to kill the cam is normal (the action is attached to the player object), the workaround is to define a key to exit the cam view. Also yous should consider naming your cam YOURTAG_cam instead of just cam (just for good practice and to avoid possible conflicts.
Using

player cameraEffect ["terminate","back"];

instead of

cam cameraEffect ["TERMINATE", "BACK"];

should allow you to regain control.

  • Like 1

Share this post


Link to post
Share on other sites

I've streamlined everything into a single script:

Quote

_caller = _this select 1;
YOURTAG_cam = "Kestrel_Random_F" camCreate (_caller modelToWorld [0,0,10]);
YOURTAG_cam cameraEffect ["FIXED", "BACK"];
YOURTAG_cam camCommand "MANUAL ON";
_flycleanup = {terminate _terminator; terminate _flycam;};
_flycam = {while {true} do
    {YOURTAG_cam  cameraEffect ["FIXED", "BACK"];}};
_terminator = {
    waitUntil {inputAction "reloadMagazine" > 0};
    [] spawn _flycleanup;  
    camDestroy YOURTAG_cam ;
    player cameraEffect ["TERMINATE", "BACK"];
    };
[] spawn _flycam;
[] spawn _terminator;

 

I'm now getting "Error undefined variable in expression: _flycleanup".

 

I assume this is because I have not defined the script for _flycleanup within the definition for _terminator.

I need to terminate _terminator script so that reloading once back in control of the player object doesn't pop up an error about YOURTAG_cam.

Also I need to terminate _flycam so that the view isn't constantly returning to the space where the now deleted YOURTAG_cam was!

 

I feel I am going about this the wrong way, does anyone have an idea where I'm going wrong?

 

Thanks!

Share this post


Link to post
Share on other sites

I think you must pass the parameters to what's between {} it is executed in a different scope and therefore not received properly.  for example:
 

_myScript = {params ["_unit]; deleteVehicle _unit};
//parameter must be passed so;
[someunit] Spawn _myScript;

But that's not perhaps the wisest way to go about it, you'll get mixed up very quickly with the script you posted above. Also why the while loop? it doesn't seem necessary to me.
 

while {true} do
    {YOURTAG_cam  cameraEffect ["FIXED", "BACK"];}

This will constantly close the cam (and throw errors once you destroy it) it is absolutely not necessary.
Finaly when I said:
 

Quote

Also yous should consider naming your cam YOURTAG_cam instead of just cam (just for good practice and to avoid possible conflicts.

What I meant was tag your variable with your OFPEC tag it's not an obligation but it's good practice and it often avoids conflicts with other scripts/functions/variables.
So in YOURTAG_cam YOURTAG should be your own personal tag. Eg. MY online handle is Mr H. so I tag all my addons/functions/public & global variables "MRH" hence in a script of mine the cam would be called MRH_cam (since it's not a private variable and cam is a very common variable name). Private variables such (beginning with _) such as: _thisIsAnExample do not need to be tagged since they are private.

Share this post


Link to post
Share on other sites

I think I understand the parameter problem, I will have a go at rectifying it tomorrow. I'm surprised I can't find an example of someone trying something similiar to what i'm attempting, maybe it just is unworkable!

 

1 hour ago, Mr H. said:

Also why the while loop? it doesn't seem necessary to me.

The "External" view using the Kestrel model clips through the model, resulting in an ugly mesh covering part of the screen. This loop ensures a smooth third-person viewpoint at all times.

 

1 hour ago, Mr H. said:

What I meant was tag your variable with your OFPEC tag it's not an obligation but it's good practice and it often avoids conflicts with other scripts/functions/variables.

Right! That makes sense, thank you for the clarification and all your help so far.

 

Cheers!

 

Share this post


Link to post
Share on other sites

It is workable and quite easy to do, many people use cameras and make them exit by keypress, I've done it in a mod for a bullet cam here's an example:
https://github.com/MisterHLunaticwraith/MRHMilsimTools/blob/DevBranch/Addons/MRHSniperAid/Functions/fn_MilsimTools_SniperTraining_BulletCam.sqf
 

I allow killing the cam by pressing enter with this snippet:
 

_ehKeyDown = (findDisplay 46) displayAddEventHandler ["KeyDown",
{
	_toggleStatus = player getVariable 'MRH_BulletCamUserPref';
	if (isNil '_toggleStatus') then {_toggleStatus = false;};
	if ((_this select 1) == 57) then {
				if (_toggleStatus) then {_toggleStatus = false; hint (localize'STR_MRH_SniperTraining_BCOFF');} else { _toggleStatus = true; hint (localize 'STR_MRH_SniperTraining_BCON');};
									};
	player setVariable ['MRH_BulletCamUserPref', _toggleStatus];

if ((_this select 1) == 28) then {
_cam = player getVariable "MRH_BulletCam";
if (isNil "_cam") ExitWith {};
_cam cameraEffect ["terminate","back"];
camDestroy _cam;
}; 

Found here:
https://github.com/MisterHLunaticwraith/MRHMilsimTools/blob/DevBranch/Addons/MRHSniperAid/Functions/fn_MilsimTools_SniperTraining_onTrainingZoneEntered.sqf

but there are many other things going on in these functions, you would have to sort out what you need from the code.

  • Like 3

Share this post


Link to post
Share on other sites

I've trimmed everything out and for now have a working version,

Quote

_caller = _this select 1;
BIRD_cam = "Kestrel_Random_F" camCreate (_caller modelToWorld [0,0,2]);
BIRD_cam cameraEffect ["FIXED", "BACK TOP"];
BIRD_cam camCommand "MANUAL ON";
waitUntil {inputAction "reloadMagazine" > 0};
camDestroy YOURTAG_cam ;
player cameraEffect ["TERMINATE", "BACK"];

The caveat being that I cannot get the desired 3rd person view of the bird model (you were completely correct, returning to the player object just did not work with the loop I made).

 

Any ideas on how I can achieve this 3rd person view without problematic loops?

 

Thanks again, you've been a great help!

  • Thanks 1

Share this post


Link to post
Share on other sites

If you want the cam to follow the kestrel around just create a cam (that's not a kestrel) and attach a kestrel object in front of it. That's a suggestion, I haven't tried it and don't know if it will work or if it's the effect you're aiming at.

  • Like 1

Share this post


Link to post
Share on other sites
20 hours ago, Mr H. said:

If you want the cam to follow the kestrel around just create a cam (that's not a kestrel) and attach a kestrel object in front of it. That's a suggestion, I haven't tried it and don't know if it will work or if it's the effect you're aiming at.

I gave it a go, and it works! Thank you ever so much for your suggestions and guidance.

  • Thanks 1

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

×