Jump to content

Sign in to follow this  
MrSanchez

Detect if person pressed LMB

Recommended Posts

How would I detect an unit pressing LMB? One without a weapon, so the Fired eventhandler wouldn't work...

Oh and preferably compatible with a person holding LMB, as it has to fire a static weapon (remotely) while holding LMB

I've searched and I couldn't find anything regarding LMB so i assigned to another key however, my main question then is: how do I fire a static weapon remotely?

edit: I found a thread that is exactly describing the problem, and people were not able to do it 3 years ago however they announced that there was a new function coming soon and in the meanwhile has anyone succeeded to do it?

http://forums.bistudio.com/showthread.php?96184-Make-attachTo-weapon-fire-on-command/page2

Thanks in advance

Edited by PhonicStudios

Share this post


Link to post
Share on other sites

Hey,

Does anyone know whether its possible to fire a static weapon remotely? I wouldn't mind an invisible AI or whatsoever but just that u can only see the weapon fire.

Share this post


Link to post
Share on other sites

Regarding the mouse button, the scope is a control and not a display, i believe i tried adding a displayeventhandler before with OnMouseButtonDown(control) but it didn't work.

Now the 'fire' function requires an AI to be the gunner of the static weapon which I'm trying to avoid, not sure about fireAtTarget since it needed a target to shoot at, and i just want the static weapon to fire in the direction it is aiming at, as I attached mini tripods to a plane and want them to shoot straight. Not sure whether there's a formula for this, but I'll go and test whether using fireAtTarget using an empty static machinegun to shoot at a valid (vehicle) target will make the gun fire at all, which it didn't with the 'fire' function.

edit: after testing, seems that nor fire or fireAtTarget will make a static weapon fire UNLESS there is a player/ai in the gunner position.

Anyone have any ideas left?

Edited by PhonicStudios

Share this post


Link to post
Share on other sites

Have your weapon change direction to face the position you want it to face in a loop.

To have it fire, you can simulate it by creating particle effects; have it emit it's usual gunshot sound, and then creating the projectile and setting its velocity.

Share this post


Link to post
Share on other sites

If your using a static weapon then you could use the invisible AI

grp = createGroup west;

unit = grp createunit ["InvisibleManW_EP1",getpos this,[],0,"none"];

Share this post


Link to post
Share on other sites

^ did not know that.. I assume there is an InvisibleManE_EP1 as well?

Share this post


Link to post
Share on other sites

No there isn't but you can just change grp = createGroup west; to east

Share this post


Link to post
Share on other sites

F2k Sel, I have heard 'rumours' of an invisible man in arma2 but I never found the actual code to create one, I will test this asap and post whether it works.

Although this does make me wonder, if I get the gun to shoot, is there any way so that I can make it shoot while pressing LMB, as my initial question was?

I honestly didn't think it'd be so hard to find an eventhandler that fires if a person presses LMB in-game without any menu open or whatsoever.

Kind regards,

Martin

Share this post


Link to post
Share on other sites
  PhonicStudios said:
I honestly didn't think it'd be so hard to find an eventhandler that fires if a person presses LMB in-game without any menu open or whatsoever.

I've already given you the answer. The display you attach it to is 46, the main screen.

waituntil {!isnull (finddisplay 46)};
(findDisplay 46) displayAddEventHandler ["ButtonDown","hint 'test'"];

Share this post


Link to post
Share on other sites

Yeah, while testing this it won't show any hint message whatsoever :/

Also, I got the static weapons to fire however I'm trying to get them NOT to rotate, seems like they're just rotating on themselves :S

Share this post


Link to post
Share on other sites

Hmm, you're right - scope doesn't support displays.

Works for keys though:

waituntil {!isnull (finddisplay 46)};
(findDisplay 46) displayAddEventHandler ["KeyDown","hint 'test';"]; 

Maybe there is a way though for the mouse clicks to be detected. The only other thing I can think of is trying:

http://community.bistudio.com/wiki/actionKeys

http://community.bistudio.com/wiki/ArmA_2:_CfgDefaultKeysMapping

And get _key from the eventhandler above (but with yours pass the returned value to the script that checks what the key is).

_array = actionKeys "Fire";

_key = _this select 1;  // (I think - can't remember exactly)

if (_key in _array) then
{
 // code
};

Again, it may not work but that's all I can think of.

Edited by Das Attorney

Share this post


Link to post
Share on other sites

It didn't quite work, but so far I'll leave it the way it is except there is one major problem with my entire system.

So I have a machinegun attached to a vehicle, and now theres an invisible AI gunning it, however I want the static machinegun to be facing the direction of the vehicle its attached to at ALL times.

However whatever I do with SetDir/VectorDir it seems like the AI is very stubborn and is rotating on its own. I tried a couple of commands to stop the AI rotating the weapon but that didn't work either.

Also when I use SetDir for example, to 0 (due to the machinegun being attached to the vehicle, 0 is the relative direction to the direction of the vehicle) however that doesn't work either.

Anybody have any ideas?

edit: After using SelectPlayer to become one of the gunners, I noticed that the invisible AI's direction always stays the same, the direction of the AI's gun (static machinegun) is equal to the vehicle, so basically it should work.

However turns out that I need to change the direction of the static weapon's >turret< as that one isn't equal to the direction of the vehicle, does anybody know how to get the direction of a turret instead?

edit2: I'm nearly getting there, after doing some research I found the way to get the direction of a turret, http://community.bistudio.com/wiki/weaponDirection . However I do not know how to set the direction.

MAIN QUESTION:

edit3: I found it, however it's for VBS2 :/ http://resources.bisimulations.com/wiki/setWeaponDirection, I'm losing hope, is there any ArmA2 alternative to this?

Kind regards,

Martin

Edited by PhonicStudios

Share this post


Link to post
Share on other sites

reading through, it looks like you tried using "onMouseButtonDown" but how about

"MouseButtonDown"

for displayAddEventHandler.

Edited by Nimrod_Z
useless bit o code. didnt read thread

Share this post


Link to post
Share on other sites

here's a bit of code from 1 of celery's scripts that uses mouse button presses.

findDisplay 46 displayAddEventHandler ["MouseButtonDown","if ((_this select 1)==0) then {CLY_mouse1down=true};if ((_this select 1)==1) then {CLY_mouse2down=true}"];
findDisplay 46 displayAddEventHandler ["MouseButtonUp","if ((_this select 1)==0) then {CLY_mouse1up=true}"];

uses variables to enact different effects from key presses.

Share this post


Link to post
Share on other sites

If your using a static weapon like the M2 then you can use unit setformdir 45 to have it turn to that direction.

Other units may need to specify the gunner gunner tank_name setformdir 45.

You will also need to disable AI targeting system to stop them targeting any enemy they see.

unit disableAI "AutoTarget";
unit disableAI "Target";

However you then run into the next problem, the AI have a built in scan system which can't be disabled.

They will start to rotate, you could keep reissuing the setformdir command

Another way oddly is to change the side to Civilian as they don't seem to have the scan routine and will stay facing the direction you tell them to face.

The Side shouldn't be a problem as you force them to fire anyway.

If you want to change elevation then use something like modeltoworld

unit dowatch (unit modelToWorld [0,110,33]);

Share this post


Link to post
Share on other sites

I modified nimrod_z's code and it works just the way I want it however I have two remaining problems :/

1. When going down a slope/dive for example, the static machine guns will not elevate down, the direction is fine now(thanks to F2k Sel) but the weapon does not elevate down along with the vehicle. I have always had questions about modelToWorld, and I have no clue how to use this to get the elevation of the main vehicle and to set the elevation of the machine guns.

2. I tested it manually and it is impossible to fire static weapons if they are up-side down, and since I attached a few to them to a plane, i wont be able to fire while doing a barrel roll, that is not much of a problem however if the plane banks like 85 degrees or more the invisible AIs decide to literally jump off, they just disembark. How can I force the AIs to stay in the gunner seat at ALL times?

So far I really appreciate all the help I've received and I'm definitely learning from it.

Kind regards,

Martin

Share this post


Link to post
Share on other sites

It's not possible to keep them in the gun, the gun will force them out and they can't be re mounted until the angle has reduced.

All you can do is a loop that keeps trying to force the unit into the gun but you may need to attach the man to the gun to stop him falling.

I'm not sure about the gun angle you may have to use modeltoworld which would be a position in front of the aircraft rather than the gun.

unit dowatch (aircraft modelToWorld [0,110,0]);

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
Sign in to follow this  

×