PDA

View Full Version : breaking glass cog help



Han5678
03-19-2003, 04:23 AM
ok i have modified the breaking glass cog and its not working. I want the pane of glass to break if it is damaged or if two other panes of glass and get broken. The only problem is, is my cog does nothing so find my mistakes someone.



# Jedi Knight Cog Script
#
# 00_BREAKINGGLASS.COG
#
# Generic breaking glass script to be linked to both sides
# of a breakable glass pane.
#
# Note: the template used is shard00, NOT shard0 !
#
# [YB]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved

symbols
surface glass mask=0x448 desc=glass
surface glass2 mask=0x448 desc=glass_adjoin
surface adj1
surface adj2
int spawnpoints=2 desc=spawn_points
int density=5 desc=density

vector surface_center local
int surface_sector local
int surface_vertices local
vector vertex local
vector where local
int i local
int j local
int k local
int a_shard local
int dummy local
int modeflag local
int modeflag2 local

template shard_tpl=shard00 local
sound glass_break=GlassBreak1.WAV local
message startup
message damaged
message pulse

end

code

startup:
setpulse(.1);
return;

damaged:
Print("Ouch I've been damaged!");
// Add 10 cm along the normal to solve some rounding error or non planar face...
surface_center = VectorAdd(SurfaceCenter(GetSenderRef()), VectorScale(GetSurfaceNormal(GetSenderRef()), 0.01));
surface_sector = GetSurfaceSector(GetSenderRef());
surface_vertices = GetNumSurfaceVertices(GetSenderRef());

dummy = PlaySoundPos(glass_break, surface_center, 1.0, 10.0, 20.0, 0);

// First spawn 'density' shards with random velocities at the center of the face.
for(k=0; k<density; k=k+1)
{
a_shard = CreateThingAtPos(shard_tpl,
surface_sector,
surface_center,
'0.0 0.0 0.0');
SetThingVel(a_shard, VectorSet( 1.4*(Rand()-0.5), 1.4*(Rand()-0.5), 1.4*(Rand()-0.5) + 0.75 ));
SetThingRotVel(a_shard, VectorSet(500*(Rand()-0.5), 500*(Rand()-0.5), 500*(Rand()-0.5) ));
}

// Then spawn 'density' shards with random velocities at 'spawnpoints' points
// between the center of the face and the face's vertices.

for(i=0; i<surface_vertices; i=i+1)
{
vertex = GetSurfaceVertexPos(glass, i);
for(j=1; j<=spawnpoints; j=j+1)
{
where = VectorAdd(surface_center,
VectorScale(VectorSub(surface_center, vertex), j/(spawnpoints+1))
);
for(k=0; k<density; k=k+1)
{
a_shard = CreateThingAtPos(shard_tpl,
surface_sector,
where,
'0.0 0.0 0.0');
SetThingVel(a_shard, VectorSet( 1.4*(Rand()-0.5), 1.4*(Rand()-0.5), 1.4*(Rand()-0.5) + 0.75 ));
SetThingRotVel(a_shard, VectorSet(500*(Rand()-0.5), 500*(Rand()-0.5), 500*(Rand()-0.5) ));
}
}
}

SetFaceGeoMode(glass, 0); // GEOMETRY_NONE
SetFaceGeoMode(glass2, 0);
SetAdjoinFlags(glass, 2); // Set ADJOIN_MOVE (allow passage)
SetAdjoinFlags(glass2, 2);

Return;

pulse:
modeflag = GetFaceGeoMode(adj1);
modeflag2 = GetFaceGeoMode(adj2);
if(modeflag & modeflag2 = 0)
{
Print("Destroying");
call damaged;
}
else
{
Print("Not this time!");
}
return;

end





------------------
roses are red, violets are blue, I am schizophrenic, and so am I!

SaberMaster
03-19-2003, 12:51 PM
Just by scanning it for syntax, change
if(modeflag & modeflag2 = 0)
to

if(modeflag & modeflag2 == 0)

Fix that and then try debugging...

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/fileframe.html), Parsec (http://www.geocities.com/sabersdomain/fileframe.html), Scribe (http://www.geocities.com/sabersdomain/fileframe.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/fileframe.html).

Han5678
03-19-2003, 07:06 PM
yeah i noticed that but its not the prob, it doesn't even get there, for some reason the cog won't do anything, i put a print in the startup and it didn't print. and i've checked like 8 times to make sure i had the cog in the level corectly, i even gobbed the thing! but i've been away from jk editing for a long long time, so just to make sure i am doing it right, how do you implement custom cogs?

------------------
roses are red, violets are blue, I am schizophrenic, and so am I!

zagibu
03-20-2003, 02:07 AM
Did you notice who you were talking to, son?

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

SaberMaster
03-20-2003, 06:48 AM
Do the adj1 and adj2 surfaces have their own breakingglass cog? And the pulse message added to your cog is to check to see if the damaged message in the other breakingglass cog has run? Then it would be alot more elegant if the other breakingglass cog, sent a message to your cog to break the glass.

But that's aside from the problem. Make sure your cog is set up correctly in the level - your syntax looks alright. If all else fails, send me the level. http://forums.massassi.net/html/wink.gif


but i've been away from jk editing for a long long time

I know the feeling. It's great to be back. http://forums.massassi.net/html/smile.gif Though I admit I no longer have 8 hours a day to spend on JK... http://forums.massassi.net/html/frown.gif

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/fileframe.html), Parsec (http://www.geocities.com/sabersdomain/fileframe.html), Scribe (http://www.geocities.com/sabersdomain/fileframe.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/fileframe.html).

zagibu
03-20-2003, 08:59 AM
He's back...HE'S BACK!!!

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

[SF]pjb
03-20-2003, 11:57 AM
hi welcom back, i think i forght you on MSM zone, or was that another sabermaster?

------------------
I am pjb.
Another post......
another moment of my life wasted.....

Sylvicolus
03-20-2003, 02:22 PM
One thing you can add (when it's working) is to have the pulse message stopped once the glass is damaged.

------------------
Sylvicolus JK homepage (http://www.lactarius.com/sylvicolus/jk/intro.htm)
If I have ever made any valuable discoveries, it has been owing more to
patient observation than to any other reason. -Isaac Newton

Han5678
03-20-2003, 05:19 PM
thanks sylv good idea. yeah i have the other two with breakingglass00 or whatever. the reason i don't have the other cogs send it and be more elegant is.... because.... i sort of can't remember how to do triggers for jk. i tried and horribly messed up so i decided to try and easier route. maybe i'll try again

------------------
roses are red, violets are blue, I am schizophrenic, and so am I!