Jump to content
Moldisocks

Switching player's view back to their unit after using camCreate

Recommended Posts

Hey, i am making a mission where i want a menu to be displayed over the top of a specific camera and camera angle, the menu will allow the player to select their desired spawn point and then click spawn (image of menu below). The menu and the camera angle scripts are wokring perfectly (for what i need them for), but when i press spawn, the player is moved to the designated spawn area, but the camera stays in roughly the same position (i say roughly, because for some reason it seems to change FOV and move slightly down). The way the code works is explained further down in this post.

 

vRgYn5v.png

 

The menu and the camera angle are made by calling menuInit.sqf when the player is initialised (so player will see this menu and camera as soon as they enter server).

Spoiler

//filename: menuInit.sqf

menuOpen = true;
createDialog "mainSpawnMenu";
waitUntil {!isNull (findDisplay 12034);};

_spawnNames = ["Base","A-Petrol Station","B-Playground","C-Church","D-Contrustion Site","E-Cemetry", "F-Industrial Area"];

_ctrl = (findDisplay 12034) displayCtrl 1500;
lbClear _ctrl;
{_ctrl lbAdd _x;} forEach _spawnNames;

lbSetCurSel [1500,0];
while {menuOpen} do {
_test = [] call mld_fnc_spawnMenuCamera;
sleep (0.2);
};
 

The ListBox is populated using the above code aswell. The while do loop in the above loop will call mld_fnc_spawnMenuCamera constantly as long as menu is open, so that i will check which check box is selected (just realised while writing this that it is very inefficeint way of doing this, and i realised that during testing i had made 1786345 cameras XD, but i decided to keep this code in here anyway as a place holder).

Spoiler

//filename: fn_spawnMenuCamera

_CPAT = [] call mld_fnc_selectCamPosition;    //CATP stands for Camera Position and Target
_CamPos = _CPAT select 0;
_CamTarg = _CPAT select 1;
cam = "camera" camCreate (_CamPos);
cam cameraEffect ["Internal", "BACK"];
cam camSetTarget (_CamTarg);
cam camSetFov 1;
cameraEffectEnableHUD true;
cam camCommit 0;

 

Once the player selects the Spawn button a function called fn_spawnPlayer.sqf is called:

Spoiler

//filename : fn_spawnPlayer.sqf

_csatPosArray = [] call mld_fnc_selectCamPosition;

_spPos = _csatPosArray select 2;

player setPos _spPos;

closeDialog 895;
menuOpen = false;
camDestroy cam;

this function should move the player's unit to the designated point, close the menu and destory the camera. This function was supposed to do those things and return control on the player's unit back to the unit and then change the camera to the player's unit (basically switching the camera back to the unit).

 

destroyCam is one of the main reasons as to why i started this topic. I using destroy camera the best way to get rid of the menu's camera and return to the player's POV (and give controls back to the player. If this is not how you would do it at all please suggest a better way of doing it.

 

Thanks

Share this post


Link to post
Share on other sites

use this instead of just camdestroy

cam cameraEffect ["terminate","back"];
camDestroy cam;

 

Share this post


Link to post
Share on other sites

@JSD You are becoming an avid reader of my threads haha. 

 

ok i will try this later today, see what happens. I have a feeling that i still will not work, just because of the fact that there are 1.7 million cammera indexes. This is because i am looping my camera creation script constantly, this must be fixed. 

 

Would something like this work to fix the constant camera creation?

in fn_spawnMenuCamera:

Spoiler

if (isNull cam) then {

 

CPAT = [] call mld_fnc_selectCamPosition;    //CATP stands for Camera Position and Target
_CamPos = _CPAT select 0;
_CamTarg = _CPAT select 1;
cam = "camera" camCreate (_CamPos);
cam cameraEffect ["Internal", "BACK"];
cam camSetTarget (_CamTarg);
cam camSetFov 1;
cameraEffectEnableHUD true;
cam camCommit 0;

 

} else {

 

CPAT = [] call mld_fnc_selectCamPosition;    //CATP stands for Camera Position and Target
_CamPos = _CPAT select 0;
_CamTarg = _CPAT select 1;

cam camSetTarget (_CamTarg);

cam camSetPos _camPos;

cam camSetFov 1;

cam camCommit 0;

};

The above script will still be executed constantly, which will allow for the constant checking of the selectCamPosition, but will not create infinite cameras (if im not wrong).

Thanks for the reply

Share this post


Link to post
Share on other sites

You seem to be doing something similar to what I just did so I had the same questions a few weeks back :p. What are you actually trying to achieve with creating a camera every .2 seconds?

I'll take a good look later cause it's past midnight and I'm mid-netflix session :p

Share this post


Link to post
Share on other sites

Awesome, did you get answers to your questions that worked?

 

2 hours ago, JSD said:

What are you actually trying to achieve with creating a camera every .2 seconds?

 

I was attempting to check which spawn point is selected by the player every 0.2s, by using the lbCurSel command in fn_selectCamPosition function, and if the player had selected a new spawn point, then the camera pos and target will change so that it will show an overview of that spawn point. The original fn_spawnMenuCamera function was run constantly and therefore constantly created new cameras, i am currently working on new script that will just check the variable, instead of creating a new camera and checking(possible fix for the script in last post).

 

So yeah don't want to create a new camera every 0.2s, i want to check which spawn point is selected by the player and then setPos of the camera depending on the selection.

Share this post


Link to post
Share on other sites

You should have a look at this page, specifically the "onLBSelChanged" bit. You can make it run a script whenever you select a new position.

Share this post


Link to post
Share on other sites
29 minutes ago, JSD said:

You should have a look at this page, specifically the "onLBSelChanged" bit. You can make it run a script whenever you select a new position.

ffs, haha went through all that shit above, yet there is a EH for exactly what i needed. Will modify script.

 

Thanks @JSD, like the other time great replies and solutions.

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

×