Author Topic: getting your custom animations into a script  (Read 1392 times)

ok so heres the deal
newish to scripting and i want to make an animation for a weapon
here i have a model with the animations "flipA" and "flipB"

i want it to play both then end. but when i try in game it doesn't play either animation
obviously i made a mistake. whether that mistake is entering my animation names in the wrong section, or something stupid like requiring the first letter to be capitalized, or even something in blockland that just doesn't let you make your own named animations is up to you.
Code: [Select]
   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.5;
stateTransitionOnTimeout[0]      = "Ready";
stateSound[0]                    = swordDrawSound;


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]     = "Firetwo";
stateTimeoutValue[3]            = 0.2;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "flipA";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;


stateName[4]                    = "Firetwo";
stateTransitionOnTimeout[4]     = "StopFire";
stateTimeoutValue[4]            = 0.2;
stateFire[4]                    = true;
stateAllowImageChange[4]        = false;
stateSequence[4]                = "flipB";
stateScript[4]                  = "onFire";
stateWaitForTimeout[4] = true;


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

Hm, I can't see any mistakes in the states. Does your weapon fire when you click? If yes, it's possible that you made a mistake with the model. If no, its eventually a problem with the function "onPreFire".

with that script it did fire (twice) on a click like i wanted it to. but there was no animation from the weapon. (i believe the arm moved up and down though but that doesn't count)
the animation itself works because i first exported this with one animation named fire... with the goals i mentioned i guess i could combine the two animations into one and call it fire and it would probably work fine
but im not making this to release or anything, this weapon is for learning. and right this second what i want to learn is how the animations interact with the scripts so i can have multiple animations for multiple triggers.

Ah, I think I know the problem, probably. Could you post the whole script?

1. Are you exporting the animations as .dsqs? If so, you shouldn't be.
2. Are you sure that's what the animations are named?
3. Are you sure you animated correctly?
4. Do the animations have enough time to display?

Code: [Select]
//sword.cs
datablock AudioProfile(swordDrawSound)
{
   filename    = "./swordDraw.wav";
   description = AudioClosest3d;
   preload = true;
};
datablock AudioProfile(swordHitSound)
{
   filename    = "./swordHit.wav";
   description = AudioClosest3d;
   preload = true;
};


//effects
datablock ParticleData(swordExplosionParticle)
{
   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.7 0.7 0.9 0.9";
   colors[1]     = "0.9 0.9 0.9 0.0";
   sizes[0]      = 0.5;
   sizes[1]      = 0.25;
};

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

   uiName = "Sword Hit";
};

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

   soundProfile = swordHitSound;

   particleEmitter = swordExplosionEmitter;
   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.0 0.2 0.6";
   lightEndColor = "0 0 0";
};


//projectile
AddDamageType("Sword",   '<bitmap:add-ons/Weapon_Sword/CI_sword> %1',    '%2 <bitmap:add-ons/Weapon_Sword/CI_sword> %1',0.75,1);
datablock ProjectileData(swordProjectile)
{
   directDamage        = 35;
   directDamageType  = $DamageType::Sword;
   radiusDamageType  = $DamageType::Sword;
   explosion           = swordExplosion;
   //particleEmitter     = as;

   muzzleVelocity      = 50;
   velInheritFactor    = 1;

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

   hasLight    = false;
   lightRadius = 3.0;
   lightColor  = "0 0 0.5";

   uiName = "Sword Slice";
};


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

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

//gui stuff
uiName = "Sword";
iconName = "./icon_sword";
doColorShift = true;
colorShiftColor = "0.471 0.471 0.471 1.000";

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

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(swordImage)
{
   // Basic Item properties
   shapeFile = "./sword.dts";
   emap = true;

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

   // 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 = swordItem;
   ammo = " ";
   projectile = swordProjectile;
   projectileType = Projectile;

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

   //casing = " ";
   doColorShift = true;
   colorShiftColor = "0.471 0.471 0.471 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]                    = swordDrawSound;


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]     = "Firetwo";
stateTimeoutValue[3]            = 0.2;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "flipA";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;


stateName[4]                    = "Firetwo";
stateTransitionOnTimeout[4]     = "StopFire";
stateTimeoutValue[4]            = 0.2;
stateFire[4]                    = true;
stateAllowImageChange[4]        = false;
stateSequence[4]                = "flipB";
stateScript[4]                  = "onFire";
stateWaitForTimeout[4] = true;


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


};

function swordImage::onPreFire(%this, %obj, %slot)
{
%obj.playthread(2, armattack);
}

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

modified sword script is swordlike.


1. Are you exporting the animations as .dsqs? If so, you shouldn't be.
2. Are you sure that's what the animations are named?
3. Are you sure you animated correctly?
4. Do the animations have enough time to display?

1.

2. see above
3.
...the animation itself works because i first exported this with one animation named fire. with the goals i mentioned i guess i could combine the two animations into one and call it fire and it would probably work fine...
4. if it wasn't then it would at least show a hyper version of the animation.

Ah, I think I see the mistake. Programming languages are often very exact when it comes to the use of capital/small letters.
In the script you wrote "flipA" and "flipB" but the actions are called "FlipA" and "FlipB". I am not sure if this is the problem, but just try it.

1. It looks like you've tried to make a shape/detail empties hierarchy thing. You don't need it, your exporter takes care of that.
2. Your bones do not appear to be attached to the knife object, and since they are invisible, no animation will appear to be playing.

Setting the names rather fixed it untill I tried adding in more animations. But at first both the model and the script had lowercase f's.


1. My exporter is old and looks for shape as a starting point. I was taught to use emptys and that's what has been working. Statement is irrelevant to question.
2. The mesh is parented to the armature which is parented to the emptys. Exporting works fine. And the invisibility is so you can see how I have them possitioned because the bones are inside the mesh. If I press z then the 3d view goes back solid.

Your sword edit overwrites the default sword's stuff.
« Last Edit: February 05, 2010, 05:16:51 PM by heedicalking »

but im not making this to release or anything, this weapon is for learning.

Your sword edit overwrites the default sword's stuff.

yer point waz?

I see the problem, your script doesn't even load your model!