Author Topic: Functions on an "Artillery Beacon" weapon not working.  (Read 2515 times)

I am making an edit of the Artillery Beacon for personal use.  I am trying to make it so it fires only one laser directly at the point at which the beacon sends up its smoke.

I'm trying to make it fire from 2000 (height units)* up, sending the beam 200 (velocity rate units)* downward.
Quote
function InactiveETOIBeaconProjectile::OnExplode(%this,%obj,%pos)
{
   %p = new Projectile()
   {
      dataBlock = ActiveETOIBeaconProjectile;
      initialPosition = vectorAdd(%pos, "0 0 1");
      client = %obj.client;
   };
   MissionCleanup.add(%p);
}

function energystrike(%pos, %client)
{
   %x = getWord(%pos, 0);
   %y = getword(%pos, 1);
   %z = getWord(%pos, 2);
   %r = containerRayCast(vectoradd("0 0 1", %x SPC %y SPC %z), vectorAdd("0 0 -200", %x SPC %y SPC %z), $typemasks::InteriorObjectType);
   if(%r)
   {
      %hitheight = getWord(%r, 3);
      %newVertDist = %hitHeight - %z;
      if(%newvertDist < 90)
      {
         dropshell(%beacon);
         return;
      }
      else
         %vertDist = %newVertDist - 1;
   }
   else
      %vertdist = 2000;
   %p = new Projectile()
   {
      dataBlock = ETOIBeamProjectile;
      initialPosition = vectorAdd(%x SPC %y SPC %z, "0 0" SPC %vertDist);
      initialVelocity = "0 0 -200";
      client = %client;
   };
   MissionCleanup.add(%p);
}

Should begin at:  "function energystrike"

*please correct me on this.  Is it Torque Units and Torque Units/sec, or something else?

Edit:  Does this belong in Coding Help.  I realized this just after I posted.

Okay, I've seen that there are 11 views to this page, and there are no comments.  I know that people don't just casually browse this board like Off-Topic.

This is the single technical problem left, and it probably involves just a simple change of a few characters.

People are browsing it, but only people who know how to solve things reply!

I'll forward this to Jetz, he wrote the script. I'm stuff at scripting.
I'll tell him to reply or else.

Well, the raycast you meddled with a few lines into the energystrike function has nothing to do with velocity. It was a feature that would allow artillery shells to be spawned in interiors under a high roof, like in the bedroom. There actually appears to be a bug in the original code there because I misused dropshell, and that bug is carried over to your edit, but it doesn't actually matter, because with no interiors, everything within that if statement will never be called.

To change the number of projectiles spawned, you'll want to look at the end of the active beacon's explosion method. The raycasts in both methods can be trimmed out because interiors don't exist.

I'll tell him to reply or else.
You never mentioned an "or else!" Hell, you never even told me to reply! You just said he needed help! We live in a world of lies!


Well, the raycast you meddled with a few lines into the energystrike function has nothing to do with velocity. It was a feature that would allow artillery shells to be spawned in interiors under a high roof, like in the bedroom. There actually appears to be a bug in the original code there because I misused dropshell, and that bug is carried over to your edit, but it doesn't actually matter, because with no interiors, everything within that if statement will never be called.

To change the number of projectiles spawned, you'll want to look at the end of the active beacon's explosion method. The raycasts in both methods can be trimmed out because interiors don't exist.
You never mentioned an "or else!" Hell, you never even told me to reply! You just said he needed help! We live in a world of lies!
Alright, thanks, but for some reason the projectile still isn't spawning.  Would you like the Add-On to see for yourself?

You should have put the full code
Try giving the projectile position, rotation and scale fields

Alright, thanks, but for some reason the projectile still isn't spawning.  Would you like the Add-On to see for yourself?
The active beacon explosion script would help.

You should have put the full code
Try giving the projectile position, rotation and scale fields
Nah, most stuff will just default if you don't include it in creating the object. What he has should be sufficient. Though he could trim down the position bit since he's only spawning one projectile.

The active beacon explosion script would help.
All the functions:
Code: [Select]
package ETOISmokeBeaconPackage
{
function Armor::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
{
if(%col.dataBlock $= "ETOISmokeBeaconItem" && %col.canPickup)
{
for(%i=0;%i<%this.maxTools;%i++)
{
%item = %obj.tool[%i];
if(%item $= 0 || %item $= "")
{
%freeSlot = 1;
break;
}
}

if(%freeSlot)
{
%obj.pickup(%col);
return;
}
}
Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
}
};
activatePackage(ETOISmokeBeaconPackage);

function ETOISmokeBeaconImage::onCharge(%this, %obj, %slot)
{
%obj.playthread(2, spearReady);
%obj.lastHESlot = %obj.currTool;
}

function ETOISmokeBeaconImage::onAbortCharge(%this, %obj, %slot)
{
%obj.playthread(2, root);
}

function ETOISmokeBeaconImage::onFire(%this, %obj, %slot)
{
%obj.playthread(2, spearThrow);
Parent::OnFire(%this, %obj, %slot);

%currSlot = %obj.lastHESlot;
%obj.tool[%currSlot] = 0;
%obj.weaponCount--;
messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
serverCmdUnUseTool(%obj.client);
}

function ETOISmokeBeaconImage::onDone(%this,%obj,%slot)
{
%obj.unMountImage(%slot);
}

function InactiveETOIBeaconProjectile::OnExplode(%this,%obj,%pos)
{
%p = new Projectile()
{
dataBlock = ActiveETOIBeaconProjectile;
initialPosition = vectorAdd(%pos, "0 0 1");
client = %obj.client;
};
MissionCleanup.add(%p);
}

function energystrike(%pos, %client)
{
%x = getWord(%pos, 0);
%y = getword(%pos, 1);
%z = getWord(%pos, 2);
%r = containerRayCast(vectoradd("0 0 1", %x SPC %y SPC %z), vectorAdd("0 0 -200", %x SPC %y SPC %z), $typemasks::InteriorObjectType);
if(%r)
{
%hitheight = getWord(%r, 3);
%newVertDist = %hitHeight - %z;
if(%newvertDist < 90)
{
dropshell(%beacon);
return;
}
else
%vertDist = %newVertDist - 1;
}
else
%vertdist = 500;
%p = new Projectile()
{
dataBlock = ETOIBeamProjectile;
initialPosition = vectorAdd(%x SPC %y SPC %z, "0 0" SPC %vertDist);
initialVelocity = "0 0 -200";
client = %client;
};
MissionCleanup.add(%p);
}

Problem seems to be that you don't have a function for the active beacon, and I can't tell if you have a projectile for that at all. The way the artillery beacon would work is after the first projectile "explodes," it spawns a second projectile, the active one, that emits smoke and lasts for a little bit. Then when that one "explodes" it calls the dropshell function several times to spawn artillery shells. Your equivalent to dropshell seems to be energystrike, but you on't seem to have anything that calls this method.

Wow, I'm surprised that I missed that.

Code: [Select]
function ActiveETOIBeaconProjectile::OnExplode(%this,%obj,%pos)
{
%vertDist = 6000;
%beammax = 1;
for(%s=0;%s>=%beammax;%s)
schedule(0, energystrike, %pos, %obj.client);
}
Tried implementing it and removing the random stuff, but it seems to either not work at all, crash me, or spawn two beams in the same location.

This was the latest version.  Also changing the height at which the beam appears to 6000.

You could reduce that entire method to a single call to the energystrike function, since the %vertDist was just part of the raycast, the schedule was there for the delay between the beacon activating and the shells, and the for loop was there to spawn multiple shells. That for loop is written incorrectly. (Or rather technically functional but would not work as intended for any practical purposes unless for some reason you want a loop that starts at 0, never increments, and stops when it's less than 1 - that is to say, instantly.)