FireWeaponAtLoc() function

For AI and campaign script related discussions and questions

FireWeaponAtLoc() function

Postby Berserk Cyborg » 21 Sep 2017, 07:07

Fire a weapon at the given coordinates.
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();
}


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.
Last edited by Berserk Cyborg on 21 Sep 2017, 19:20, edited 1 time in total.
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 270
Joined: 26 Sep 2016, 19:56

Re: Laser Satellite firing function

Postby Berg » 21 Sep 2017, 07:49

Be nice to insert s quick vid showing the las sat firing in the top left or right corner of game screen one can only wish
User avatar
Berg
Regular
Regular
 
Posts: 1864
Joined: 02 Sep 2007, 23:25
Location: Australia

Re: Laser Satellite firing function

Postby NoQ » 21 Sep 2017, 14:09

A skirmish map that gets slowly sandwiched by neutral lassat strikes, forcing the players to move the base around. Mmm.

Do we want to unhardcode the weapon name to add various nukes eventually?
User avatar
NoQ
Special
Special
 
Posts: 6068
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: FireWeaponAtLoc() function

Postby Berserk Cyborg » 21 Sep 2017, 19:21

I changed it into fireWeaponAtLoc(x, y, weapon) so that is no longer hardcoded.

Edit:
It is now in the master branch.
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 270
Joined: 26 Sep 2016, 19:56

Re: FireWeaponAtLoc() function

Postby Twister22 » 21 Sep 2017, 23:12

Say is this feature for only the laser satellite?
or can you use this with other weapons as well.
WZ2120&Nukemod Duo
http://forums.wz2100.net/viewtopic.php?f=49&t=13527
donate the project!
http://donations.wz2100.net/
User avatar
Twister22
Trained
Trained
 
Posts: 140
Joined: 28 Aug 2017, 22:18
Location: United States, Alabama

Re: FireWeaponAtLoc() function

Postby Twister22 » 21 Sep 2017, 23:49

I tried your new feature but then a problem occured with the rules.js when adding the following line


fireWeaponAtLoc(40, 40, LasSat);
WZ2120&Nukemod Duo
http://forums.wz2100.net/viewtopic.php?f=49&t=13527
donate the project!
http://donations.wz2100.net/
User avatar
Twister22
Trained
Trained
 
Posts: 140
Joined: 28 Aug 2017, 22:18
Location: United States, Alabama

Re: FireWeaponAtLoc() function

Postby Berserk Cyborg » 22 Sep 2017, 00:02

fireWeaponAtLoc(40, 40, "LasSat"). Otherwise that would be passing in a, likely undefined, variable.
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 270
Joined: 26 Sep 2016, 19:56

Re: FireWeaponAtLoc() function

Postby Twister22 » 22 Sep 2017, 00:28

Berserk Cyborg wrote:fireWeaponAtLoc(40, 40, "LasSat"). Otherwise that would be passing in a, likely undefined, variable.

Thanks i forgot the quotes on the weapon
it did work but nothing happened to my command center though
here's the coordinates For Sk-rush ""The First one not the second""
x:20 y:73
I played as player 3 but then nothing happened to my command center
WZ2120&Nukemod Duo
http://forums.wz2100.net/viewtopic.php?f=49&t=13527
donate the project!
http://donations.wz2100.net/
User avatar
Twister22
Trained
Trained
 
Posts: 140
Joined: 28 Aug 2017, 22:18
Location: United States, Alabama

Re: FireWeaponAtLoc() function

Postby Berserk Cyborg » 22 Sep 2017, 01:00

It uses world coordinates, not tile coordinates (use the ones inside the brackets [] in debug mode). What you were firing at is effectively the NW corner of the map. fireWeaponAtLoc(2200, 2200, "LasSat") would destroy part of player 0's base on the Rush map.
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 270
Joined: 26 Sep 2016, 19:56


Return to Scripting