Pickling Code is Pickling.

Author Topic: Pickling Code is Pickling.  (Read 3086 times)

Well I'm in a pickle. This code was meant for a lightsaber weapon that I will be using for star wars mod, so if you want to show your support, please help. Right now RKY and me have been trying to make it so you can use /commands and eventually a gui to change the hilt on your saber. But after lots of toiling and strife it still keeps its original model. The slash commands don't do anything. Help Please. Code is below.
Code: [Select]
//lightSaber.cs
datablock AudioProfile(lightSaberDrawSound)
{
   filename    = "./sound/button.wav";
   description = AudioClosest3d;
   preload = true;
};
datablock AudioProfile(lightSaberHitSound)
{
   filename    = "./sound/button.wav";
   description = AudioClosest3d;
   preload = true;
};


//effects
datablock ParticleData(lightSaberExplosionParticle)
{
   dragCoefficient      = 2;
   gravityCoefficient   = 1.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   spinRandomMin = -90;
   spinRandomMax = 90;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 300;
   textureName          = "base/data/particles/chunk";
   colors[0]     = "0.0 1.0 0.0 0.9";
   colors[1]     = "0.0 1.0 0.25 0.0";
   sizes[0]      = 0.5;
   sizes[1]      = 0.25;
};

datablock ParticleEmitterData(lightSaberExplosionEmitter)
{
   ejectionPeriodMS = 7;
   periodVarianceMS = 0;
   ejectionVelocity = 8;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 60;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "lightSaberExplosionParticle";
};

datablock ExplosionData(lightSaberExplosion)
{
   //explosionShape = "";
   lifeTimeMS = 500;

   soundProfile = lightSaberHitSound;

   particleEmitter = lightSaberExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = true;
   camShakeFreq = "20.0 22.0 20.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Dynamic light
   lightStartRadius = 3;
   lightEndRadius = 0;
   lightStartColor = "00.2 0.0 0.6";
   lightEndColor = "0 0 0";
};


//projectile
AddDamageType("lightSaber",   '<bitmap:add-ons/ci/lightSaber> %1',    '%2 <bitmap:add-ons/ci/lightSaber> %1',1,1);
datablock ProjectileData(lightSaberProjectile)
{
   //projectileShapeName = "~/data/shapes/arrow.dts";
   directDamage        = 35;
   directDamageType  = $DamageType::lightSaber;
   radiusDamageType  = $DamageType::lightSaber;
   explosion           = lightSaberExplosion;
   //particleEmitter     = as;

   muzzleVelocity      = 50;
   velInheritFactor    = 1;

   armingDelay         = 0;
   lifetime            = 100;
   fadeDelay           = 70;
   bounceElasticity    = 0;
   bounceFriction      = 0;
   isBallistic         = false;
   gravityMod = 0.0;

   hasLight    = false;
   lightRadius = 3.0;
   lightColor  = "0 1 0.0";
};


//////////
// item //
//////////
datablock ItemData(lightSaberItem)
{
category = "Weapon";  // Mission editor category
className = "Weapon"; // For inventory system

// Basic Item Properties
shapeFile = "./shapes/betalightSaber1.dts";
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;

//gui stuff
uiName = "LightSaber";
iconName = "./ItemIcons/lightSaber";
doColorShift = true;
colorShiftColor = "0.0 1.0 1.000 1.000";

// Dynamic properties defined by the scripts
image = lightSaberImage1;
canDrop = true;
};

//function lightSaber::onUse(%this,%user)
//{
// //if the image is mounted already, unmount it
// //if it isnt, mount it
//
// %mountPoint = %this.image.mountPoint;
// %mountedImage = %user.getMountedImage(%mountPoint);
//
// if(%mountedImage)
// {
// //echo(%mountedImage);
// if(%mountedImage == %this.image.getId())
// {
// //our image is already mounted so unmount it
// %user.unMountImage(%mountPoint);
// }
// else
// {
// //something else is there so mount our image
// %user.mountimage(%this.image, %mountPoint);
// }
// }
// else
// {
// //nothing there so mount
// %user.mountimage(%this.image, %mountPoint);
// }
//}

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(lightSaber1Image)
{
   // Basic Item properties
   shapeFile = "./shapes/Betalightsaber1.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   //eyeOffset = "0.1 0.2 -0.55";

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = false;

   eyeOffset = "0.7 1.2 -0.25";

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = lightSaberItem;
   ammo = " ";
   projectile = lightSaberProjectile;
   projectileType = Projectile;

   //melee particles shoot from eye node for consistancy
   melee = true;
   doRetraction = false;
   //raise your arm up or not
   armReady = true;

   //casing = " ";
   doColorShift = true;
   colorShiftColor = "0.0 1.0 0.0 1.000";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.5;
stateTransitionOnTimeout[0]      = "Ready";
stateSound[0]                    = lightSaberDrawSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "PreFire";
stateAllowImageChange[1]         = true;

stateName[2] = "PreFire";
stateScript[2]                  = "onPreFire";
stateAllowImageChange[2]        = false;
stateTimeoutValue[2]            = 0.1;
stateTransitionOnTimeout[2]     = "Fire";

stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "CheckFire";
stateTimeoutValue[3]            = 0.2;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
//stateTransitionOnTriggerUp[3] = "StopFire";

stateName[4] = "CheckFire";
stateTransitionOnTriggerUp[4] = "StopFire";
stateTransitionOnTriggerDown[4] = "Fire";


stateName[5]                    = "StopFire";
stateTransitionOnTimeout[5]     = "Ready";
stateTimeoutValue[5]            = 0.2;
stateAllowImageChange[5]        = false;
stateWaitForTimeout[5] = true;
stateSequence[5]                = "StopFire";
stateScript[5]                  = "onStopFire";


};
datablock ShapeBaseImageData(lightSaber2Image)
{
   // Basic Item properties
   shapeFile = "./shapes/BetaLightSaber2.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   //eyeOffset = "0.1 0.2 -0.55";

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = false;

   eyeOffset = "0.7 1.2 -0.25";

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = lightSaberItem;
   ammo = " ";
   projectile = lightSaberProjectile;
   projectileType = Projectile;

   //melee particles shoot from eye node for consistancy
   melee = true;
   doRetraction = false;
   //raise your arm up or not
   armReady = true;

   //casing = " ";
   doColorShift = true;
   colorShiftColor = "0.0 1.0 0.0 1.000";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.5;
stateTransitionOnTimeout[0]      = "Ready";
stateSound[0]                    = lightSaberDrawSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "PreFire";
stateAllowImageChange[1]         = true;

stateName[2] = "PreFire";
stateScript[2]                  = "onPreFire";
stateAllowImageChange[2]        = false;
stateTimeoutValue[2]            = 0.1;
stateTransitionOnTimeout[2]     = "Fire";

stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "CheckFire";
stateTimeoutValue[3]            = 0.2;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
//stateTransitionOnTriggerUp[3] = "StopFire";

stateName[4] = "CheckFire";
stateTransitionOnTriggerUp[4] = "StopFire";
stateTransitionOnTriggerDown[4] = "Fire";


stateName[5]                    = "StopFire";
stateTransitionOnTimeout[5]     = "Ready";
stateTimeoutValue[5]            = 0.2;
stateAllowImageChange[5]        = false;
stateWaitForTimeout[5] = true;
stateSequence[5]                = "StopFire";
stateScript[5]                  = "onStopFire";


};

function lightsaberImage1::onPreFire(%this, %obj, %slot)
{
//messageAll( 'MsgClient', 'lightSaber prefired!!!');
//Parent::onFire(%this, %obj, %slot);
%obj.playthread(2, armattack);
}

function lightSaberImage1::onStopFire(%this, %obj, %slot)
{
%obj.playthread(2, root);
//messageAll( 'MsgClient', 'stopfire');
}

function LightSaberitem::onUse(%this,%a,%b,%c,%d,%e)
{
 %Hilt = %client.Hilt;
 switch(%Hilt)
 {
  case 0:
   %this.image = LightSaber1Image;
  case 1:
   %this.image = LightSaber2Image;
 }
 Parent::onUse(%this,%a,%b,%c,%d,%e);
}

function serverCmdhilt1(%client)
{
%client.Hilt = 0;
}

function serverCmdhilt2(%client)
{
%client.Hilt = 1;
}

Are the models the same? :cookieMonster: Just kidding
The only thing wrong I can see is the prefire and stopfires are named lightsaberimage1 instead of lightsaber1image, and lightsaber2 has no functions, but they shouldn't effect the image much. what am I doing posting in coding help :(

Right now RKY and me
Arrrr, Thar be ye problem, Cap'n.

At the moment the servercmds just set hilt to 1 or 0. Thats not going to do anything. What you need to do is check if the player has a lightsaber, and if they do - mount the new image to them based on the hilt they choose. Shoving it in the onUse won't have the desired effect.

Code: [Select]
function LightSaberitem::onUse(%this,%a,%b,%c,%d,%e)
{
%Hilt = %client.Hilt;
switch(%Hilt)
{
  case 0:
   %this.image = LightSaber1Image;
  case 1:
   %this.image = LightSaber2Image;
}
Parent::onUse(%this,%a,%b,%c,%d,%e);
}

Probably doesn't help that %client isn't an argument of the onUse function.

I have no idea how to do that Ephi D:. Tri said I could use animations to do the different models, aka just making the animations different models.

Code: [Select]
function LightSaberitem::onEquip(%this, %obj, %slot, %client)
{
if(%client.Hilt = 1)
{
%obj.playthread(Saber1);
}
if(%client.Hilt = 1)
{
%obj.playthread(Saber2);
}
if(%client.Hilt = 3)
{
%obj.playthread(Saber3);
}
}


function serverCmdhilt1(%client)
{
%client.Hilt = 1;
}

function serverCmdhilt2(%client)
{
%client.Hilt = 2;
}

function serverCmdhilt3(%client)
{
%client.Hilt = 3;
}

Heres what I came up with. The animations would be called Saber1,2,3

Tri

Code: [Select]
function LightSaberitem::onUse(%this,%a,%b,%c,%d,%e)
{
%Hilt = %client.Hilt;
switch(%Hilt)
{
  case 0:
   %this.image = LightSaber1Image;
  case 1:
   %this.image = LightSaber2Image;
}
Parent::onUse(%this,%a,%b,%c,%d,%e);
}

Probably doesn't help that %client isn't an argument of the onUse function.
I didn't see that either XD

Tried that, still didn't work... I want to do Ephi's way, but don't know exactly what he is talking about.
« Last Edit: March 17, 2008, 11:57:49 PM by Dr Bling »

He's saying instead of having a lightsaber that changes its model, have a command to change which lightsaber (item) you have.

I know I'm not good at this but heres another try, if you could Ephi clear up the confusion...
Code: [Select]
Function LightSaberItem::onEquip(%client,%this)
{
if(%client.player.getMountedImage(0)$="LightSaber1Image")
{
if(%client.hilt = 1)
{This.image = LightSaber1.Image)
if(%client.hilt = 2)
{This.image = LightSaber2.Image)
if(%client.hilt = 3)
{This.image = LightSaber3.Image)
}
}

function serverCmdhilt1(%client)
{
%client.Hilt = 1;
}

function serverCmdhilt2(%client)
{
%client.Hilt = 2;
}

function serverCmdhilt3(%client)
{
%client.Hilt = 3;
}

Just the %this.image and script layout unless I REALLY need sleep... sleeeeep :D

Code: [Select]
function LightsaberItem::onUse(%this,%player,%slot)
{
        %player.updateArm(LightSaber1Image);
if(%player.client.LSHilt $= 1)
%player.mountImage(LightSaber1Image);
else if(%player.client.LSHilt $= 2)
%player.mountImage(LightSaber2Image);
else if(%player.client.LSHilt $= 3)
%player.mountImage(LightSaber3Image);
else
%player.mountImage(LightSaber1Image);
}

function serverCmdHilt1(%client)
{
%client.LSHilt = 1;
if(%client.player.getMountedImage(0).item.getID() $= LightsaberItem.getID())
LightsaberItem::onUse(LightsaberItem,%client.player,0);
}

function serverCmdHilt2(%client)
{
%client.LSHilt = 2;
if(%client.player.getMountedImage(0).item.getID() $= LightsaberItem.getID())
LightsaberItem::onUse(LightsaberItem,%client.player,0);
}

function serverCmdHilt3(%client)
{
%client.LSHilt = 3;
if(%client.player.getMountedImage(0).item.getID() $= LightsaberItem.getID())
LightsaberItem::onUse(LightsaberItem,%client.player,0);
}

Might work, try and see. I'm assuming that all your lightsaber images use the same item. This will make it so that if you do /hilt3 and then equip a lightsaber, it will set it to the image with hilt 3. It will also make it so if you do /hilt3 while holding hilt 2, you will equip hilt 3.

Code: [Select]
function LightSaberitem::onUse(%this,%a,%b,%c,%d,%e)
{
%client = %a.client;
%Hilt = %client.Hilt;
switch(%Hilt)
{
  case 0:
   %this.image = LightSaber1Image;
  case 1:
   %this.image = LightSaber2Image;
}
Parent::onUse(%this,%a,%b,%c,%d,%e);
}

Ephi, didn't work.  :panda: Thanks for the effort. Space Guy, how would I change the hilt using your way?

Tri

Just do the animations D:  (Sure it might be harder, but you will get your results)
And use %this.playThread(#, NAME); in the onEquip

Also: Use 1 cmd for the hilt.  It is easier.
« Last Edit: March 18, 2008, 11:26:14 AM by Tri »

Like we need it harder then it already is.