FireWeaponAtLoc() function
Posted: 21 Sep 2017, 07:07
Fire a weapon at the given coordinates.
Works fine on the first fire. Unfortunately after that a small, immobile projectile texture shows up where it is about to hit and then it fires with a delay. That issue only happens in campaign.
Code: Select all
//-- \subsection{fireWeaponAtLoc(x, y, weapon_name)}
//-- Fires a weapon at the given coordinates (3.2.4+ only).
static QScriptValue js_fireWeaponAtLoc(QScriptContext *context, QScriptEngine *)
{
int xLocation = context->argument(0).toInt32();
int yLocation = context->argument(1).toInt32();
QScriptValue weaponValue = context->argument(2);
int weapon = getCompFromName(COMP_WEAPON, weaponValue.toString());
SCRIPT_ASSERT(context, weapon > 0, "No such weapon: %s", weaponValue.toString().toUtf8().constData());
Vector3i target;
target.x = xLocation;
target.y = yLocation;
target.z = map_Height(xLocation, yLocation);
WEAPON sWeapon;
sWeapon.nStat = weapon;
// send the projectile using the selectedPlayer so that it can always be seen
proj_SendProjectile(&sWeapon, nullptr, selectedPlayer, target, nullptr, true, 0);
return QScriptValue();
}