I am working on this cog right now but I have one bug that I haven't been able to work out.
The cog is supposed to activate a forcefield at the activation of a switch, heal and recharge the shields of the player that activated the switch, sleep while healing and the forcefield is on and then deactivating the the healing and the forcefield, with a delay afterward preventing the switch from being activated too soon. It works fine but if you activate the switch during the delay after it still heals you. I have tried to counter this with an if else statement regarding to the ajoinflags but it doesn't seem to work. I'm sorry if that didn't make sense. It would be great to have some tips. I am a beggining cogger so I don't know a way to counter this problem even though it should have a simple solution.
here it is (It is a modified version of 00_DUALFORCEFIELD.COG in the cog section of Massassi)
The cog is supposed to activate a forcefield at the activation of a switch, heal and recharge the shields of the player that activated the switch, sleep while healing and the forcefield is on and then deactivating the the healing and the forcefield, with a delay afterward preventing the switch from being activated too soon. It works fine but if you activate the switch during the delay after it still heals you. I have tried to counter this with an if else statement regarding to the ajoinflags but it doesn't seem to work. I'm sorry if that didn't make sense. It would be great to have some tips. I am a beggining cogger so I don't know a way to counter this problem even though it should have a simple solution.
here it is (It is a modified version of 00_DUALFORCEFIELD.COG in the cog section of Massassi)
Code:
symbols
surface switch desc=switch mask=0x408
surface forcefield1 desc=forcefld1 mask=0x408
surface forcefield2 desc=forcefld2 mask=0x408
surface forcefield3 desc=forcefld3 mask=0x408
surface forcefield4 desc=forcefld4 mask=0x408
thing player local
thing powerupspot
template poweruptemp
flex time_on=5.0 desc=time_on
flex delay=10 desc=delay
int field_is_on=0 local
int shields local
flex maxDamage=10.0 local
flex minDamage=5.0 local
flex dmg=0.0 local
int ff_sound local
int ffd_sound local
int dummy local
sound on_snd=set_hi2.wav local
sound off_snd=lgclick1.wav local
sound forcefield_snd=ForceFieldHum01.WAV local
sound ffdamage_snd=ForceFieldHit01.WAV local
flex healspeed=.2
flex healammount=1
flex currenttime local
flex oldtime1=0 local
flex oldtime2=0 local
flex oldtime3=0 local
flex oldtime4=0 local
int dodamage=0 local
int sourceRef=-1 local
int senderRef=-1 local
int lock_touched=0 local
message startup
message activated
message pulse
message touched
message timer
end
# ========================================================================================
code
startup:
SetFaceGeoMode(forcefield1, 0); // GEOMETRY_NONE (don't draw the face)
SetFaceGeoMode(forcefield2, 0);
SetFaceGeoMode(forcefield3, 0);
SetFaceGeoMode(forcefield4, 0);
SetWallCel(switch, 1);
Return;
# ........................................................................................
activated:
if(GetAdjoinFlags(forcefield1) = 7)
{
setPulse(healspeed);
}
else
{
setPulse(0);
}
if(field_is_on == 0)
{
field_is_on = 1;
// Center the sound on the switch
ff_sound = PlaySoundPos(forcefield_snd, SurfaceCenter(forcefield1), 1.0, -1, -1, 0x41);
// SetFaceGeoMode(forcefield1, 5); // GEOMETRY_FULL (draw the face)
// SetFaceGeoMode(forcefield2, 5);
// SetFaceGeoMode(forcefield3, 5);
// SetFaceGeoMode(forcefield4, 5);
// Switched to a solid material, this gives
// MUCH more efficient translucency
SetFaceGeoMode(forcefield1, 4); // GEOMETRY_SOLID
SetFaceGeoMode(forcefield2, 4);
SetFaceGeoMode(forcefield3, 4);
SetFaceGeoMode(forcefield4, 4);
SetFaceLightMode(forcefield1, 0); // LIGHTING_LIT (light fully)
SetFaceLightMode(forcefield2, 0);
SetFaceLightMode(forcefield3, 0);
SetFaceLightMode(forcefield4, 0);
ClearAdjoinFlags(forcefield1, 2); // Clear ADJOIN_MOVE (disallow passage)
ClearAdjoinFlags(forcefield2, 2);
ClearAdjoinFlags(forcefield3, 2);
ClearAdjoinFlags(forcefield4, 2);
SetSurfaceFlags(forcefield1,16384); // Set SURFACE_MAGSEALED
SetSurfaceFlags(forcefield2,16384);
SetSurfaceFlags(forcefield3,16384);
SetSurfaceFlags(forcefield4,16384);
SetWallCel(switch, 0);
dummy = PlaySoundPos(on_snd, SurfaceCenter(switch), 0.8, 5.0, 10.0, 0);
SetTimer(time_on); // Let the force field active
pulse:
player = GetSenderRef();
if((GetThingHealth(player) > 0) && (GetThingHealth(player) < 100))
{
HealThing(player, healammount);
}
if((GetThingHealth(player) == 100) && (GetInv(player,60) < 200))
{
ChangeInv(player, 60, healammount);
}
Return;
//........................................................................................
timer:
SetPulse(0);
SetFaceGeoMode(forcefield1, 0); // GEOMETRY_NONE (don't draw the face)
SetFaceGeoMode(forcefield2, 0);
SetFaceGeoMode(forcefield3, 0);
SetFaceGeoMode(forcefield4, 0);
SetFaceLightMode(forcefield1, 3); // LIGHTING_GOURAUD (normal lighting)
SetFaceLightMode(forcefield2, 3);
SetFaceLightMode(forcefield3, 3);
SetFaceLightMode(forcefield4, 3);
SetAdjoinFlags(forcefield1, 2); // Set ADJOIN_MOVE (allow passage)
SetAdjoinFlags(forcefield2, 2);
SetAdjoinFlags(forcefield3, 2);
SetAdjoinFlags(forcefield4, 2);
ClearSurfaceFlags(forcefield1,16384); // Clear SURFACE_MAGSEALED
ClearSurfaceFlags(forcefield2,16384);
ClearSurfaceFlags(forcefield3,16384);
ClearSurfaceFlags(forcefield4,16384);
StopSound(ff_sound, 0);
Sleep(delay); // Delay before the force field is usable again
SetWallCel(switch, 1);
dummy = PlaySoundPos(off_snd, SurfaceCenter(switch), 0.8, 5.0, 10.0, 0);
field_is_on = 0;
}
Return;
// ........................................................................................
//
// touched: is very framerate dependant, so we'll apply damage only
// when 0.5 second have elapsed. Note that we have to remember the
// time for each of the forcefields.
touched:
if(GetSenderRef() == switch) Return;
if(lock_touched == 1) Return;
lock_touched = 1;
senderRef = GetSenderRef();
sourceRef = GetSourceRef();
if (field_is_on == 1)
{
currenttime = GetLevelTime();
dodamage = 0;
if((senderRef == forcefield1) && (currenttime > oldtime1 + 0.50))
{
oldtime1 = currenttime;
dodamage = 1;
}
else
if((senderRef == forcefield2) && (currenttime > oldtime2 + 0.50))
{
oldtime2 = currenttime;
dodamage = 1;
}
else
if((senderRef == forcefield3) && (currenttime > oldtime3 + 0.50))
{
oldtime3 = currenttime;
dodamage = 1;
}
else
if((senderRef == forcefield4) && (currenttime > oldtime4 + 0.50))
{
oldtime4 = currenttime;
dodamage = 1;
}
if(dodamage == 1)
{
dummy = PlaySoundPos(ffdamage_snd, GetSurfaceCenter(senderRef), 1.0, -1, -1, 0);
dummy = DamageThing(sourceRef, 10, 0x2, sourceRef);
}
}
lock_touched = 0;
Return;
endIf curiosity killed the cat then perhaps Curious George killed the cat.
But Cat's do have nine lives so who knows?
But Cat's do have nine lives so who knows?

