Blockland Forums > Suggestions & Requests

i need a weapon script

Pages: (1/1)

Nasoa:

if someone could write a weapon script that would spawn a couple dozen very slow moving projectiles randomly in front of the wielder when fired, that would be great

it also needs to not have any animations play on equip or fire

MARBLE MAN:

sure thing!

MARBLE MAN:

function vectorSpread(%vector, %spread) {
   %x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
   %y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
   %z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;

   %mat = matrixCreateFromEuler(%x SPC %y SPC %z);
   return vectorNormalize(matrixMulVector(%mat, %vector));
}
function mImage::onFire(%data,%obj,%slot)
{
   %count=mFloor(%data.projectileCount);
   %spread=%data.projectileSpread;
   if(!%count)
      %count=1;
   %projectile = %data.projectile;
   %vector = %obj.getMuzzleVector(0);
   %muzzle = %obj.getMuzzlePoint(0);
   for(%i=0;%i<%count;%i++)
   {
      %proj = new Projectile()
      {
         datablock = %projectile;
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
         initialPosition = %muzzle;
         initialVelocity = vectorScale(vectorSpread(%vector,%spread),%projectile.muzzleVelocity);
      };
      %proj.setScale("1 1 1");
      MissionCleanup.add(%proj);
   }
}
datablock ProjectileData(mImageTestProjectile:blankaBallProjectile)
{
   uiname = "mImage Projectile";
   muzzleVelocity=30;
};
datablock ItemData(mImageTestItem:PrintGun)
{
   uiname = "mImage Item";
   image = mImageTestImage;
   colorShiftColor="0 0.7 0 1";
};
datablock ShapeBaseImageData(mImageTestImage:PrintGunImage)
{
   projectile = mImageTestProjectile;
   projectileCount = 12;
   projectileSpread = 0.01;
   colorShiftColor="0 0.7 0 1";
   stateEmitter[2]="";
   stateSound[2]="";
   stateSequence[2]="";
};
function mImageTestImage::onFire(%data,%obj,%slot)
{
   mImage::onFire(%data,%obj,%slot);
}


I wrote some dandy code for this to work on Whatever weapon you want


--- Code: ---function vectorSpread(%vector, %spread) {
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;

%mat = matrixCreateFromEuler(%x SPC %y SPC %z);
return vectorNormalize(matrixMulVector(%mat, %vector));
}
function mImage::onFire(%data,%obj,%slot)
{
   %count=mFloor(%data.projectileCount);
   %spread=%data.projectileSpread;
   if(!%count)
      %count=1;
   %projectile = %data.projectile;
   %vector = %obj.getMuzzleVector(0);
   %muzzle = %obj.getMuzzlePoint(0);
   for(%i=0;%i<%count;%i++)
   {
      %proj = new Projectile()
      {
         datablock = %projectile;
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
         initialPosition = %muzzle;
         initialVelocity = vectorScale(vectorSpread(%vector,%spread),%projectile.muzzleVelocity);
      };
      %proj.setScale("1 1 1");
      MissionCleanup.add(%proj);
   }
}
--- End code ---

Use it like this:

Here's some pseudo code:


datablock ShapeBaseImageData(myImage)
{
   projectile = mImageTestProjectile;
   projectileCount = 12;
   projectileSpread = 0.01;
};
function myImage::onFire(%data,%obj,%slot)
{
   mImage::onFire(%data,%obj,%slot);
}

Product from code from beginning:





Godspeed, my friend

tell me if damage doesn't work, because that might be a problem

Pages: (1/1)

Go to full version