Windows override LMB movement

X

xhrys

Guest
Hi everyone.
As this is my first post on here (as well as my first attempt in creating a game). It's nice to meet you :D
I can't find a thread on this anywhere. If there is one, would you please post it. Otherwise...
I'm working on a top down shooter and I'm trying to set the weapon fire command to shift (hold) + LMB.
The problem is, the LMB currently controls the movement of the character/hero when clicked (moves towards the cursor).
So I guess what I'm asking is, is it possible to code it so that when shift is held down, it overrides the character's LMB controls for movement, and rather keeps the character standing still to fire their weapon when LMB is clicked alongside it.
It would basically be like Diablo.
Thanks for any help :D
 
A

Aura

Guest
Code:
if (mouse_check_button_pressed(mb_left)) {
   if (keyboard_check(vk_shift)) {
      //Fire...
   }
   else {
      //Movement...
   }
}
 
X

xhrys

Guest
Thank you for your reply Aura :D
I made some headway with your code.
So... so far, I'm able to hold down LMB and move to the cursor's position,
as well as hold down shift and fire a fireball from a weapon with LMB without moving.
What I want to change is having to hold down LMB to move to the cursor's position and rather make it one click.
Here's what I got so far with the coding (sorry if I made chopsuey out of it :p)
--------------------------------------------------------------------------------------------------
if mouse_check_button(mb_left)
{
if keyboard_check(vk_shift)
{instance_create(obj_hero.x,obj_hero.y,obj_fireball)}
else
{
if mouse_check_button(mb_left) && instance_exists(obj_mouseclick)
{action_potential_step(obj_mouseclick.x,obj_mouseclick.y,1,0)}
else
{if !instance_exists(obj_mouseclick)
speed = 0}
}
}
--------------------------------------------------------------------------------------------------
Is there anything I can do to fix it?
 
A

Aura

Guest
First of all, let me tell you about a few minor things that might lead you to issues later.

1. Do NOT use the deprecated action_*() functions. There's a reason behind why they are not documented. Those functions exist only due to the way GM handles D&D actions. All the D&D actions are converted to their respective action_*() functions upon compilation. But those functions are not supposed to be used directly (or at all) by you. The actual function that you want is mp_potential_step().

2. You should not call the same function unnecessarily again and again. You have called mouse_check_button() and instance_exists() twice, it does not cause any issues per se. But it is a bad habit and makes it more difficult for you to trace the code.

Either way, you would have to use mouse_check_button_pressed() for that. You would also have to use a variable which tells when to move, since mp_potential_step() needs to be called constantly. If you call it inside the if statement, the instance would move only for a single step and not continuosly towards the target. Declare a variable called will_move in the Create event and set it to false, then you can go about doing something like this in the Step event:

Code:
if (mouse_check_button_pressed(mb_left)) {
   if (keyboard_check(vk_shift)) {
      instance_create(x, y, obj_fireball);
   }
   else {
      will_move = true;
   }
}

if (will_move) {
   if (instance_exists(obj_mouseclick)) {
      mp_potential_step(obj_mouseclick.x, obj_mouseclick.y, 1, false);
   }
   else {
      will_move = false;
   }
}
else {
   speed = 0;
}
 
Top