Author Topic: I'm having an issue with statename files.  (Read 1350 times)

I'm having an issue with this statename. So my pitchfork charges like the default spear except it is not suppose to be thrown (it's suppose to do this). My issue is when I release the spear in the air to attack and hit nothing it still plays the "pitchforkhit" sound. It's only suppose to display this sound when it actually hits something.

Also when I do hit something it appears it plays the sound twice at the same time.

Code: [Select]
   // Initial start up state
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "Ready";
stateSequence[0] = "ready";
stateSound[0] = pitchforkactivateSound;

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

stateName[2]                    = "Charge";
stateTransitionOnTimeout[2] = "Armed";
stateTimeoutValue[2]            = 0.7;
stateWaitForTimeout[2] = false;
stateTransitionOnTriggerUp[2] = "AbortCharge";
stateScript[2]                  = "onCharge";
stateAllowImageChange[2]        = false;

stateName[3] = "AbortCharge";
stateTransitionOnTimeout[3] = "Ready";
stateTimeoutValue[3] = 0.3;
stateWaitForTimeout[3] = true;
stateScript[3] = "onAbortCharge";
stateAllowImageChange[3] = false;

stateName[4] = "Armed";
stateTransitionOnTriggerUp[4] = "Fire";
stateAllowImageChange[4] = false;

stateName[5] = "Fire";
stateTransitionOnTimeout[5] = "Ready";
stateTimeoutValue[5] = 0.5;
stateFire[5] = true;
stateSequence[5] = "fire";
stateScript[5] = "onFire";
stateWaitForTimeout[5] = true;
stateAllowImageChange[5] = false;
stateSound[5] = pitchforkhitSound;
};

function pitchforkImage::onCharge(%this, %obj, %slot)
{
%obj.playthread(2, spearReady);
}

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



function PitchforkImage::onFire(%this, %obj, %slot)
{
%obj.playthread(2, spearThrow);
Parent::onFire(%this, %obj, %slot);
}
function PitchforkImage::onFiretwo(%this,%obj,%slot)
{



%projectile = Pitchforkprojectile;
%spread = 0.00001;
%shellcount = 1;

for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}

You need to put the sound into a packaged onHit, and check if it hits any objects. I'm not sure entirely how the syntax works though.

right now what you have set up will always play the sound when it goes to state 5, not when it hits a player.

I tried this but I still get the same results. statenames are the only stuff I have trouble with.

Code: [Select]
   // Initial start up state
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "Ready";
stateSequence[0] = "ready";
stateSound[0] = pitchforkactivateSound;

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

stateName[2]                    = "Charge";
stateTransitionOnTimeout[2] = "Armed";
stateTimeoutValue[2]            = 0.7;
stateWaitForTimeout[2] = false;
stateTransitionOnTriggerUp[2] = "AbortCharge";
stateScript[2]                  = "onCharge";
stateAllowImageChange[2]        = false;



      stateName[3] = "AbortChargefire";
stateTransitionOnTimeout[3] = "stopfire";
//stateTransitionOntriggerup[3] = "stopfire";
stateTimeoutValue[3] = 0.2;
stateFire[3] = true;
stateSequence[3] = "ready";
stateScript[3] = "onFiretwo";
stateWaitForTimeout[3] = true;
stateAllowImageChange[3] = false;
stateSound[3] = pitchforkhitSound;

stateName[4] = "Armed";
stateTransitionOnTriggerUp[4] = "Fire";
stateAllowImageChange[4] = false;

stateName[5] = "Fire";
stateTransitionOnTimeout[5] = "Ready";
stateTimeoutValue[5] = 0.5;
stateFire[5] = true;
stateSequence[5] = "fire";
stateScript[5] = "onFire";
stateWaitForTimeout[5] = true;
stateAllowImageChange[5] = false;
stateSound[5] = pitchforkhitSound;
};

remove this
Code: [Select]
stateSound[5] = pitchforkhitSound;

add this
Code: [Select]
function Pitchforkprojectile::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)
{
        Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)

        ServerPlay3D(pitchforkhitSound, %pos);
}

You could also use an explosion that triggers the sound, but with this way you can make different sound effects depending on what you actually hit and a few other things.

I tried this but I still get the same results. statenames are the only stuff I have trouble with.
ah alright

Code: [Select]
      stateName[3] = "AbortChargefire";
stateSound[3] = pitchforkhitSound;

stateName[5] = "Fire";
stateSound[5] = pitchforkhitSound;
};
this will always play your pitchfork hit sound whenever you enter this state. basically what goth said.


Code: [Select]
function Pitchforkprojectile::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)
{
        Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)

        ServerPlay3D(pitchforkhitSound, %pos);
}
I didn't realize you can call parents outside of packages. Are packages just used for "engine" functions?

remove this
Code: [Select]
stateSound[5] = pitchforkhitSound;

add this
Code: [Select]
function Pitchforkprojectile::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)
{
        Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)

        ServerPlay3D(pitchforkhitSound, %pos);
}

You could also use an explosion that triggers the sound, but with this way you can make different sound effects depending on what you actually hit and a few other things.
ah alright

Quote
Loading Add-On: Weapon_Pitchfork (CRC:-921597475)
Add-Ons/Weapon_Pitchfork/server.cs Line: 240 - Syntax error.
>>> Some error context, with ## on sides of error halt:
^stateWaitForTimeout[5]^^= true;

^stateAllowImageChange[5]^= false;



};



function Pitchforkprojectile::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)

{

        Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)



        ServerPlay3D(##p##itchforkhitSound, %pos);

}



function pitchforkImage::onCharge(%this, %obj, %slot)

{

^%obj.playthread(2, spearReady);

}



function pitchforkImage::onAbortCharge(%this, %obj, %slot)

{

^%obj.playthread(2, root);

}







function PitchforkImage::onFire(%this, %obj, %slot)
>>> Error report complete.

ADD-ON "Weapon_Pitchfork" CONTAINS SYNTAX ERRORS


I didn't realize you can call parents outside of packages. Are packages just used for "engine" functions?
Parents call the parent class function. Packages are basically child classes.

Pitchforkprojectile function calling parent will call projectiledata function, and then calling the parent on that is another, etc.

Basically...
object name -> superclass value (only certain types of objects) -> class (only certain types of objects) -> object class -> parent class - > parent class... etc

And then packages can be stuck somewhere in there, like

[object name package] -> object name -> [object class package] -> object class

example...

function projectileData::test(%t)
{
echo("woh");
}

function testprojectile::test(%t)
{
Parent::test(%t);
}

package test
{
function projectileData::test(%t)
{
Parent::test(%t);
}

function testprojectile::test(%t)
{
Parent::test(%t);
}
};
activatepackage(test);

this will echo the 'woh' when test is called on the projectile
« Last Edit: February 11, 2016, 04:03:35 PM by Shift Kitty »

He forgot a ; at the end of Parent::OnCollision();
Shhh. Tony is supposed to figure this stuff out himself ;3

I always forget the damn semi-colons

Quote
Loading Add-On: Weapon_Pitchfork (CRC:1090917709)
Executing Add-Ons/Weapon_Pitchfork/server.cs.
ShapeBaseImageData:: Could not resolve state "AbortCharge" for image "PitchforkImage"
8 datablocks added.

Code: [Select]
      // Initial start up state
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "Ready";
stateSequence[0] = "ready";
stateSound[0] = pitchforkactivateSound;

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

stateName[2]                    = "Charge";
stateTransitionOnTimeout[2] = "Armed";
stateTimeoutValue[2]            = 0.7;
stateWaitForTimeout[2] = false;
stateTransitionOnTriggerUp[2] = "AbortCharge";
stateScript[2]                  = "onCharge";
stateAllowImageChange[2]        = false;

stateName[3] = "AbortCharge";
stateTransitionOnTimeout[3] = "Ready";
stateTimeoutValue[3] = 0.3;
stateWaitForTimeout[3] = true;
stateScript[3] = "onAbortCharge";
stateAllowImageChange[3] = false;
        stateName[3] = "AbortChargefire";
stateSound[3] = pitchforkhitSound;

stateName[4] = "Armed";
stateTransitionOnTriggerUp[4] = "Fire";
stateAllowImageChange[4] = false;

stateName[5] = "Fire";
stateTransitionOnTimeout[5] = "Ready";
stateTimeoutValue[5] = 0.5;
stateFire[5] = true;
stateSequence[5] = "fire";
stateScript[5] = "onFire";
stateWaitForTimeout[5] = true;
stateAllowImageChange[5] = false;
stateSound[5] = pitchforkhitSound;
        stateName[5] = "Fire";
stateSound[5] = pitchforkhitSound;
};

function Pitchforkprojectile::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity)
{
        Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %velocity);

        ServerPlay3D(pitchforkhitSound, %pos);
}

function pitchforkImage::onCharge(%this, %obj, %slot)
{
%obj.playthread(2, spearReady);
}

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



function PitchforkImage::onFire(%this, %obj, %slot)
{
%obj.playthread(2, spearThrow);
Parent::onFire(%this, %obj, %slot);
}
function PitchforkImage::onFiretwo(%this,%obj,%slot)
{



%projectile = Pitchforkprojectile;
%spread = 0.00001;
%shellcount = 1;

for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 2 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}


stateName[3]         = "AbortCharge";////////////////////
stateTransitionOnTimeout[3]   = "Ready";
stateTimeoutValue[3]      = 0.3;
stateWaitForTimeout[3]      = true;
stateScript[3]         = "onAbortCharge";
stateAllowImageChange[3]   = false;
stateName[3]         = "AbortChargefire";/////////////////////
stateSound[3]            = pitchforkhitSound;

you have statename in there twice. remove the second instance.


stateName[3]         = "AbortCharge";////////////////////
stateTransitionOnTimeout[3]   = "Ready";
stateTimeoutValue[3]      = 0.3;
stateWaitForTimeout[3]      = true;
stateScript[3]         = "onAbortCharge";
stateAllowImageChange[3]   = false;
stateName[3]         = "AbortChargefire";/////////////////////
stateSound[3]            = pitchforkhitSound;

you have statename in there twice. remove the second instance.

I did that but I still hear the hit sound in mid air.


I did that but I still hear the hit sound in mid air.
Instead of blindly posting each error, how about scoping the problem. Are you not learning anything when you modify code?


remove
Code: [Select]
stateSound[3]            = pitchforkhitSound;

I can't figure out states.