Jump to content
Alert23

Enable Mouse Cursor/CursorTarget/CursorObject during Cutscene

Recommended Posts

Hi everyone,

 

my question is how/can i make the mouse Cursor visible in an static Camera view.

Spoiler

LV5WgQH7.png

 

i found this code on another thread

 

[] spawn 
{ 
 _ctrl = findDisplay 46 ctrlCreate ["RscPicture", 31357]; 
 _ctrl ctrlSetPosition [0.48, 0.4799, 0.04, 0.04]; 
 _ctrl ctrlSetText "\A3\ui_f\data\map\markers\military\destroy_CA.paa"; 
 _ctrl ctrlSetTextColor [1, 0, 0, 1];  
 _ctrl ctrlCommit 0; 
};

but how would i make this marker move with the mouse movement?

i want to create something like MoorHuhn

Share this post


Link to post
Share on other sites

You could do a loop what executes every frame:

while {!isNull _display} do {
	_ctrl ctrlSetPosition getMousePosition;
	_ctrl ctrlCommit 0;
	_frame = diag_frameNo;
	waitUntil {_frame != diag_frameNo};
};

 

Share this post


Link to post
Share on other sites
1 hour ago, 7erra said:

You could do a loop what executes every frame:


while {!isNull _display} do {
	_ctrl ctrlSetPosition getMousePosition;
	_ctrl ctrlCommit 0;
	_frame = diag_frameNo;
	waitUntil {_frame != diag_frameNo};
};

 

i tried something like this:

 

[] spawn {   
  
 	_ctrl = findDisplay 46 ctrlCreate ["RscPicture", 31357];   
  	_ctrl ctrlSetText "\A3\ui_f\data\map\markers\military\destroy_CA.paa";   
  	_ctrl ctrlSetTextColor [1, 0, 0, 1];  
 	_ctrl ctrlSetScale 0.15;  
  		
	while {!isnull findDisplay 46} do { 
			_ctrl ctrlSetPosition getMousePosition;    
			_ctrl ctrlCommit 0; 
     
 	}; 
};

but the marker dosent move while in-game but only in pause menu.

 

i try to do something like this:

waituntil {!isnull (finddisplay 46)};    
(findDisplay 46) displayAddEventHandler ["MouseButtonUP", {    
     
 if (_this select 1 == 0 && cursorObject isKindOf "Man") then {    
		playSound "ShotGunSound";  
		cursorObject setdammage 1;
		//some codes} else {  
    
 if (_this select 1 == 0) then {  
		playSound "ShotGunSound";
		//some codes
		};  
	};     
  false    
}];

attach that marker to the cursorObject and make it visible/moveable from a static camera view then on MouseButtonUp it will fire the code above.

Share this post


Link to post
Share on other sites

Is the screen static when shooting targets or is it the normal 3D movement with turning etc?

Share this post


Link to post
Share on other sites
8 hours ago, 7erra said:

Is the screen static when shooting targets or is it the normal 3D movement with turning etc?

its a static Camera View created with camcreate:

 

Spoiler

CameraView1 = "camera" camcreate [0,0,0];          
CameraView1 cameraeffect ["internal", "back"];     
showCinemaBorder false;

 

CameraView1 camPrepareTarget [14590,16806.8,0];
CameraView1 camPreparePos [14650.2,16746,2.25432];
CameraView1 camPrepareFOV 0.67;  
CameraView1 camCommitPrepared 0;

 

the idea is to have some sort of "crosshair" like marker serving as the CursorTarget/Object.

the problem is i cant get the mouse cursor or CursorTarget/Object to work in a static screen.

 

this is how the mission is looking now everyting is working great, shooting,reloading etc..

but unfortunately i cant get that marker move by MouseMovement.

pwXUH9JV.png

 

Share this post


Link to post
Share on other sites

Ah okay that should be easy. You could create a dialog and also move your ui elements to that dialog. The mouse should now be moveable

Share this post


Link to post
Share on other sites
5 hours ago, 7erra said:

Ah okay that should be easy. You could create a dialog and also move your ui elements to that dialog. The mouse should now be moveable

thank you for your help, creating a dialog is to complicated for me as i dident create any before.

isent there any other way to achive that?

Share this post


Link to post
Share on other sites

The dialog can be empty too. So put the following in the description.ext:

class ALERT_EmptyDialog
{
	idd = -1;
	class controls
	{
	};
};

Now you can create it with

createDialog "ALERT_EmptyDialog";

 

Share this post


Link to post
Share on other sites

Thank you, this indeed made the mouseCursor visible/moveable but now this code:

Spoiler

waituntil {!isnull (finddisplay 46)}; (findDisplay 46) displayAddEventHandler ["MouseButtonUP", { if (_this select 1 == 0 && cursorObject isKindOf "Man") then { playSound "ShotGunSound"; cursorObject setdammage 1; //some codes} else { if (_this select 1 == 0) then { playSound "ShotGunSound"; //some codes }; }; false }];

 Does not work if i press the LMB.

 

Share this post


Link to post
Share on other sites

Ah yeah you'll have to add that code to the newly created dialog:
 

class ALERT_EmptyDialog
{
	idd = -1;
	onLoad = "_this execVM ""ui_init.sqf"";";
	class controls
	{
	};
};

And the ui_init.sqf:

params ["_display"];
_display displayAddEventHandler ["MouseButtonUP", { 
	if (_this select 1 == 0) then { 
		playSound "ShotGunSound"; 
		if (cursorObject isKindOf "Man") then {
			cursorObject setdammage 1; //some codes
		};
	false
}];

(Also a little bit of better if then statements).

 

I just noticed that cursorObject is not gonna work. The cursorObject will always return what is in the center of the screen, not where the mouse cursor actually is. To maintain a static camera view you'd probalby do some more math with lineintersectsObjs or some command of that sort 🤔

  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, 7erra said:

with lineintersectsObjs or some command of that sort

i did something like this:

ui_init.sqf:

sleep 0.3;
waitUntil {!(isNull(findDisplay 46))};      
ShotGunShot1 = (findDisplay 46) displayAddEventHandler ["MouseButtonDown", {      
       {
 	if ((_this select 1 == 0 && side _x == east && alive _x && lineIntersects [ getPosASL StaticCamera1, getPosASL _x])) then {
                  (findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", ShotGunShot1];      
                  playSound "ShotGunSoundEffect";    
                  _x setdammage 1; 
                  0006 cutText ["","PLAIN", 1]; 
                  null = [] execVM "scripts\ShotGunShoot2.sqf";}  
 else {    
      
 	if (_this select 1 == 0) then { 
                  (findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", ShotGunShot1];    
                  playSound "ShotGunSoundEffect"; 
                  0006 cutText ["","PLAIN", 1]; 
                  null = [] execVM "scripts\ShotGunShoot2.sqf";    
      				};    
   			};       
  		false
	}     
}];

it's not giving me any error but still dosent work.

Share this post


Link to post
Share on other sites
15 hours ago, Alert23 said:

_x == east

_x is undefined

15 hours ago, Alert23 said:

alive _x

_x is undefined

15 hours ago, Alert23 said:

getPosASL _x

_x is undefined

15 hours ago, Alert23 said:

null =

That's useless

 

Please pay more attention to your brace layout, its a total mess and makes it hard to see what's actually going on.

Like. this brace is the closing brace for the if,then from above right?

 

firefox_2020-02-27_10-46-34.png

 

WRONG!

notepad++_2020-02-27_10-47-00.png

Its something completely else that you don't expect.

So lets clean up your brace layout and indentation to be able to see whats really going on.

 

sleep 0.3;
waitUntil {!(isNull(findDisplay 46))};
ShotGunShot1 = (findDisplay 46) displayAddEventHandler ["MouseButtonDown", {
    {
        if ((_this select 1 == 0 && side _x == east && alive _x && lineIntersects [ getPosASL StaticCamera1, getPosASL _x])) then {
            (findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", ShotGunShot1];
            playSound "ShotGunSoundEffect";
            _x setdammage 1;
            0006 cutText ["","PLAIN", 1];
            null = [] execVM "scripts\ShotGunShoot2.sqf"
        } else {
            if (_this select 1 == 0) then {
                (findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", ShotGunShot1];
                playSound "ShotGunSoundEffect";
                0006 cutText ["","PLAIN", 1];
                null = [] execVM "scripts\ShotGunShoot2.sqf";
            };
        };
        false
    }
}];

Here, that's better.

Now we see that your code, actually does nothing at all.

All your MouseDown handler does, is return a piece of code, starting at the first { and ending at the last }

you never execute that code though, so it does nothing.

 

 

Now I don't know what to do with _x, you never set that variable, i have no idea where you expect it to be coming from.

 

15 hours ago, Alert23 said:

if (_this select 1 == 0) then {

You do this check twice. It would be easier to just do a

 

if (_this select 1 != 0) exitWith {};

at the start of your handler and be done with it.

 

15 hours ago, Alert23 said:

false

Why do you return false here? that doesn't seem to have any purpose.

Share this post


Link to post
Share on other sites
On 2/27/2020 at 10:52 AM, Dedmen said:

Please pay more attention to your brace layout, its a total mess and makes it hard to see what's actually going on.

thank you for your reply, most of the time i dont know what im doing, its just copy-paste untill something works 🙂

On 2/27/2020 at 10:52 AM, Dedmen said:

_x is undefined 

but why is _x undefined?

i have editor placed opfor units and _x should refer to them or?

 

im trying to create something like This

i have a static camera view and a mouse pointer which should execute this code if i press on an unit

sleep 0.3;
waitUntil {not (isNull(findDisplay 46))};      
ShotGunShot1 = (findDisplay 46) displayAddEventHandler ["MouseButtonDown", {      
{
 		if ((_this select 1 == 0 && _x isKindOf "CAmanBase" && side _x == east && alive _x && lineIntersects [ getPosASL staticCamera1, getPosASL _x])) then { 
                  (findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", ShotGunShot1];      
                  playSound "ShotGunSoundEffect";    
                  _x setdammage 1; 
                  0006 cutText ["","PLAIN", 1]; 
                  [] execVM "scripts\ShotGunShoot2.sqf";} 
 else {    
      
 if (_this select 1 == 0) then { 
                  (findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", ShotGunShot1];    
                  playSound "ShotGunSoundEffect"; 
                  0006 cutText ["","PLAIN", 1]; 
                  [] execVM "scripts\ShotGunShoot2.sqf";};    
		
		};
	}forEach allunits; 
}];

so i try to make a code which should kill only the opfor unit i press on, but if i use

forEach allunits

it will execute on all or many units.

Share this post


Link to post
Share on other sites

Any help or hint anyone how i can finish my mission please?

Share this post


Link to post
Share on other sites

I’m interested in the solution, if there is one. /Fredrik 

Share this post


Link to post
Share on other sites
On 2/28/2020 at 6:36 PM, Alert23 said:

i have editor placed opfor units and _x should refer to them or?

_x doesn't magically refer to anything. Its set by command like forEach/count/select/apply

 

On 2/28/2020 at 6:36 PM, Alert23 said:

so i try to make a code which should kill only the opfor unit i press on, but if i use

you can get the unit you are aiming on by using cursorTarget or cursorObject commands.

Share this post


Link to post
Share on other sites
On 3/3/2020 at 10:39 AM, Dedmen said:

you can get the unit you are aiming on by using cursorTarget or cursorObject commands.

Not from a static camera where the UI mouse pointer is the cursor, as per OP.

Share this post


Link to post
Share on other sites
On 3/3/2020 at 11:39 AM, Dedmen said:

you can get the unit you are aiming on by using cursorTarget or cursorObject commands.

i already managed to get that work:

 

Spoiler

waitUntil {not (isNull(findDisplay 46))};     
ShotGunShot1 = (findDisplay 46) displayAddEventHandler ["MouseButtonUP", {     
      
 if (_this select 1 == 0 && cursorObject isKindOf "CAmanBase") then {
        (findDisplay 46) displayRemoveEventHandler ["MouseButtonUP", ShotGunShot1];     
             playSound "ShotGunSoundEffect";   
            cursorObject setdammage 1;
            0006 cutText ["","PLAIN", 1];
            [] execVM "scripts\ShotGunShoot2.sqf";}
 else {   
     
 if (_this select 1 == 0) then {
        (findDisplay 46) displayRemoveEventHandler ["MouseButtonUP", ShotGunShot1];   
             playSound "ShotGunSoundEffect";
             0006 cutText ["","PLAIN", 1];
             [] execVM "scripts\ShotGunShoot2.sqf";   
            };   
      };         
}];

 

 

2 hours ago, Larrow said:

Not from a static camera where the UI mouse pointer is the cursor, as per OP.

yes exactly, i cant get that work with cursorobject.

Share this post


Link to post
Share on other sites
On 3/4/2020 at 3:26 PM, Alert23 said:

yes exactly, i cant get that work with cursorobject.

camera position + getCameraViewDirection + math to make a line + lineIntersects

Share this post


Link to post
Share on other sites
1 hour ago, Dedmen said:

camera position + getCameraViewDirection + math to make a line + lineIntersects

Or for no math:

getPos _cam + screenToWorld + lineIntersectsObjs

Share this post


Link to post
Share on other sites
7 hours ago, Dedmen said:

getCameraViewDirection

Only retrieves camera direction of a unit, not a static camera.

 

Spoiler

//Create a blue arrow helper 10m infront of the player
mouseTarget = createVehicle[ "Sign_Arrow_Blue_F", player getPos[ 10, getDir player ], [], 0, "CAN_COLLIDE" ];

//Create a camera 2m infront of the player
cam = "camera" camCreate ( player getPos[ 2, getDir player ] );
//Set camera 2m off the ground
cam setPosATL ( getPosATL cam vectorAdd[ 0, 0, 2 ] );
//Switch to the cameras static view
cam cameraEffect[ "Internal", "Back" ];

//Create a blank UI so we can see the mouse pointer
createDialog "RscDisplayCommon";

//On render update
addMissionEventHandler[ "Draw3D", {
	
	//Max distance of intersect
	_maxDistance = 200;
	
	//Camera position
	_camPos = getPosATL cam;
	
	//Mouse screen position as world
	_worldPos = screenToWorld getMousePosition;
	
	//Direction( normalised ) from camera to mouse world position
	_vectorDir = _camPos vectorFromTo _worldPos;
	
	//Calculate line end position
	_lineEnd = _camPos vectorAdd ( _vectorDir vectorMultiply _maxDistance );

	//Get first surface intersections between camera and line end
	lineIntersectsSurfaces[ ATLToASL _camPos, ATLToASL _lineEnd ] select 0 params[ [ "_pos", [] ] ];

	//If we have an intersection
	if ( count _pos isEqualTo 3 ) then {
		//Move the blue arrow to the intersection
		mouseTarget setPosASL _pos;
	}else{
		diag_log format[ "%1: No intersect position", time ];
	};
}];

 

 

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites

Thank you very very much for your time and effort, now i need to adabt my code to yours somehow.

Share this post


Link to post
Share on other sites

Hi!

I´m interested in the solution. Can someone please make a short demo or something like that so I understan how to use this script etc....
Please

Regards

Fredrik (erpesjo@gmail.com)

Share this post


Link to post
Share on other sites

Any solution in sight? I also need to Shoot in a static screen. Cant figure Out How to do it. Getting crazy soon. 
 

Share this post


Link to post
Share on other sites

It's not hard. @Larrow has given pretty much all of the solutions for you. You just need to adjust his code slightly.


Try this.

//Create a camera 2m infront of the player
cam = "camera" camCreate ( player getPos[ 2, getDir player ] );
//Set camera 2m off the ground
cam setPosATL ( getPosATL cam vectorAdd[ 0, 0, 2 ] );
//Switch to the cameras static view
cam cameraEffect[ "Internal", "Back" ];

//Create a blank UI so we can see the mouse pointer
createDialog "RscDisplayCommon";

//On render update
addMissionEventHandler[ "Draw3D", {

	//Max distance of intersect
	_maxDistance = 200;

	//Camera position
	_camPos = getPosATL cam;

	//Mouse screen position as world
	_worldPos = screenToWorld getMousePosition;

	//Direction( normalised ) from camera to mouse world position
	_vectorDir = _camPos vectorFromTo _worldPos;

	//Calculate line end position
	_lineEnd = _camPos vectorAdd ( _vectorDir vectorMultiply _maxDistance );

	//Get first surface intersections between camera and line end
	lineIntersectsSurfaces[ ATLToASL _camPos, ATLToASL _lineEnd ] select 0 params[ [ "_pos", [] ] ];

	//If we have an intersection
	if ( count _pos isEqualTo 3 ) then {
		//Check for nearby entities to the selected position
		_EntityToKill = (_pos nearEntities [["Man"], 5]) select 0;
		// kill nearest entitity
		_EntityToKIll setDamage 1;
	}else{
		diag_log format[ "%1: No intersect position", time ];
	};
}];

Credit to Larry for the majority of the code above, 

  • 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

×