I want to make a sound every time a shell hits something (they bounce).
I wrote this:
Code:
function shellHit(proj,tick)
{
// bounce for 5 seconds
if (tick<(proj.hit.startTick+2500)) {
sound.play('Shell Klink',proj.position.x,proj.position.z,proj.position.y,((utility.random.getInteger(0,10))/10)+0.5);
}
if (tick>(proj.hit.startTick+2500)) {
proj.model.spin.x=0;
proj.model.spin.z=0;
proj.model.spin.y=0;
proj.action.autoReflect=false;
proj.action.autoBounce=false;
}
if (tick>(proj.hit.startTick+5000)) {
proj.action.destroy();
}
}
But seems to wait until the shell stays on the floor then plays it reptedly. If I fire about twice, all sounds stop. 5 times the engine crashes.
What's wrong with my script?
Is it automatic? If so thats going to cause problems with the audio channels.
Is there any otherparts of code just in case.
Ive had a problem similar to that, it ended up being the accual bouncing code.
Out of curiosity, can you post the event func too?
Okay, the problem is that DIM3_EVENT_HIT is repeated from when the projectile hits something to to when the projectile is destroyed.
None of theses are ever called?:
Code:
DIM3_EVENT_PROJECTILE_BOUNCE
DIM3_EVENT_PROJECTILE_REFLECT
DIM3_EVENT_COLLIDE
Is it a bug? When SHOULD the first to be called (when it bounces/reflects I wold assume....)?
I'm using the newest beta....
Still waiting for your complete event function. Preferably the complete script.
Your actually from what it sounds like, making the script a little more complicated than it needs to be.
Orixa: How??
teh1ghool: Sorry, I forgot. Here:
Code:
// ***********************************************************
//
// PROJECTILE: Shell
//
// ***********************************************************
//
// grenade construction
//
function shellConstruct(proj)
{
// model
proj.model.on=true;
proj.model.name="Shell";
proj.model.spin.x=1;
proj.model.spin.z=1;
proj.model.spin.y=1;
// speed
proj.speed.speed=60;
proj.speed.deceleration=10;
proj.speed.decelerationWait=300;
// size and weight
proj.size.x=189;
proj.size.z=189;
proj.size.y=189;
proj.size.weight=100;
proj.action.autoReflect=true;
proj.action.autoBounce=true;
proj.action.autoBounceMinMove=1;
proj.action.autoBounceReduce=0.39;
}
//
// grenade hit
//
function shellHit(proj,tick)
{
// bounce for 5 seconds
sound.play('Shell Klink',proj.position.x,proj.position.z,proj.position.y,((utility.random.getInteger(0,10))/10)+0.5);
if (tick>(proj.hit.startTick+4000)) {
proj.model.spin.x=0;
proj.model.spin.z=0;
proj.model.spin.y=0;
proj.action.autoReflect=false;
proj.action.autoBounce=false;
}
if (tick>(proj.hit.startTick+5000)) {
proj.action.destroy();
}
}
//function shellBounce(proj,tick)
//{
// iface.console.write('HELLO WORLD!');
// sound.play('Shell Klink',proj.position.x,proj.position.z,proj.position.y,((utility.random.getInteger(0,10))/10)+0.5);
//
//}
//
// events
//
function event(proj,mainEvent,subEvent,eventId,tick)
{
switch (mainEvent) {
case DIM3_EVENT_CONSTRUCT:
shellConstruct(proj);
return;
case DIM3_EVENT_HIT:
shellHit(proj,tick);
return;
//case DIM3_EVENT_COLLIDE:
// shellBounce(proj,tick);
// return;
}
}
(I've tried all 3 events I wrote about in my other post, this is just the last way I tried it)
When commenting out multiple lines of code you can do '/* code */' I believe. Looks like a bug to me. Also there's no need to include subEvent and eventID, as far as I can see. Probably just slows it down a bit.
No you can't, I don't think dim3 lets you.
And your right, I should remove those....
No, Ive commented out with /* */ for the weapon scripts and it works.
Thing I noticed you dont have
Klink',proj.position.x,proj.position.z,proj.position.y,((utility.random.getInteger(0,10))/10)+0.5);
commented out