Cancelling Left-Mouse Trigger
by Chris "C2" Byars · in Torque Game Engine · 09/21/2005 (4:08 am) · 6 replies
Referring to this function:
fps/client/scripts/default.bind.cs
I have scripted in makeshift grenades by making an invisible weapon, which fires grenades (projectiles). By hitting the right mouse button it calls a function which causes your player to switch to the invisible weapon and it fires a single grenade, simulating throwing a grenade, and then switches back.
Problem is, if you hit the right click (which activates the invisible weapon and fires one grenade) and then hit the left click (regular fire button) you may get stuck on the invisible weapon. The regular fire will interfere if you press it during the function.
Solution: Basically I need to make function throwGrenade (on the client side, which sends the command to the server to call function serverCmdThrowGrenade, to not work if the player's left mouse button is down.
fps/client/scripts/default.bind.cs
function mouseFire(%val)
{
$mvTriggerCount0++;
}
moveMap.bind( mouse, button0, mouseFire );I have scripted in makeshift grenades by making an invisible weapon, which fires grenades (projectiles). By hitting the right mouse button it calls a function which causes your player to switch to the invisible weapon and it fires a single grenade, simulating throwing a grenade, and then switches back.
Problem is, if you hit the right click (which activates the invisible weapon and fires one grenade) and then hit the left click (regular fire button) you may get stuck on the invisible weapon. The regular fire will interfere if you press it during the function.
Solution: Basically I need to make function throwGrenade (on the client side, which sends the command to the server to call function serverCmdThrowGrenade, to not work if the player's left mouse button is down.
function throwGrenade(%val)
{
if(%val)
commandToServer('ThrowGrenade');
}
#2
Still trying to figure out the correct syntax for how this would be done.
09/22/2005 (4:05 am)
Nope. :/Still trying to figure out the correct syntax for how this would be done.
#3
09/24/2005 (11:49 am)
Anybody else know how to do this?
#4
09/26/2005 (4:51 pm)
I'd check your shapebaseimage datablock's state settings and make sure it's actually able to change state when the trigger is pressed... i.e. The appropriate stateAllowImageChange value is set to true.
#5
I'm firing an assault rifle, holding the left mouse trigger down. I right-click to activate the throwGrenade command (Which switches weapons momentarily and fires one grenade through script, and then switches back to the current weapon), and as soon as I quit holding down the fire button for the XM8, the weapon switches to the invisible "grenadeLauncher" and does not fire a grenade, and remains on that invisible weapon. Then I can fire using the left mouse button, because now the weapon is mounted as any old weapon. Bad.
So the simplest way I've thought of to solve this is to only allow throwGrenade to function if the left mouse trigger is not being pressed.
09/26/2005 (5:53 pm)
Yes, that is set. It's not what the problem is, though. It's difficult to describe.I'm firing an assault rifle, holding the left mouse trigger down. I right-click to activate the throwGrenade command (Which switches weapons momentarily and fires one grenade through script, and then switches back to the current weapon), and as soon as I quit holding down the fire button for the XM8, the weapon switches to the invisible "grenadeLauncher" and does not fire a grenade, and remains on that invisible weapon. Then I can fire using the left mouse button, because now the weapon is mounted as any old weapon. Bad.
So the simplest way I've thought of to solve this is to only allow throwGrenade to function if the left mouse trigger is not being pressed.
#6
09/26/2005 (6:24 pm)
Alas, I've solved it, using your advice. By setting the ability to change image whilst firing on all weapons, it no longer has the glitch. :)
Torque 3D Owner Peter Simard
Default Studio Name
function throwGrenade(%val) { if(%val && !$MouseOn) commandToServer('ThrowGrenade'); }