Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Two Cogs
Two Cogs
2005-12-08, 3:51 PM #1
Here are two forcefield cogs that are almost complete but have a few little bugs.

The Dualforcefield cog turns on a two surface forcefield at the activation of a switch. The player that activated the switch is healed and their sheilds are recharged on a pulse untill the feild is turned off after a timer runs out.

The complex forcefield cog turns 24 forcefield surfaces off when a player is in one of six sectors and turns them back on when the player(s) leave the sector.

Both of these cogs work on a server but neither works completely on a guest computer. The dualforcefield cog works except that only the host can be healed when activating the switch. The complex forcefield cog just doesn't turn any of the forcefields off on the guest computer when the host is in one of the trigger sectors.

Code:
# complex_forcefield.cog
#
# Controls 24 forcefield surfaces using 6 sectors as triggers. This cog runs locally without syncing.
# The pulse is run on the server and triggers are used to sync effects.
#
# Created by zagibu@gmx.ch and Centrist
#=================================================  =============#
flags=0x240
#=================================================  =============#
symbols

material  animMaterial

flex      animSpeed=8                       local

int       inside                            local
int       active=1                          local
int       i                                 local
int       j                                 local
int       id                                local
int       numTriggerSectors=0
int       numFieldSurfaces=0

sound     damageSound=forcefieldhit01.wav   local
sound     humSound=ForceFieldHum01.wav      local

sector    triggerSector0=-1                 nolink
sector    triggerSector1=-1                 nolink
sector    triggerSector2=-1                 nolink
sector    triggerSector3=-1                 nolink
sector    triggerSector4=-1                 nolink
sector    triggerSector5=-1                 nolink

surface   soundSurface=-1                   nolink
surface   fieldSurface00=-1                 mask=0x400
surface   fieldSurface01=-1                 mask=0x400
surface   fieldSurface02=-1                 mask=0x400
surface   fieldSurface03=-1                 mask=0x400
surface   fieldSurface04=-1                 mask=0x400
surface   fieldSurface05=-1                 mask=0x400
surface   fieldSurface06=-1                 mask=0x400
surface   fieldSurface07=-1                 mask=0x400
surface   fieldSurface08=-1                 mask=0x400
surface   fieldSurface09=-1                 mask=0x400
surface   fieldSurface10=-1                 mask=0x400
surface   fieldSurface11=-1                 mask=0x400
surface   fieldSurface12=-1                 mask=0x400
surface   fieldSurface13=-1                 mask=0x400
surface   fieldSurface14=-1                 mask=0x400
surface   fieldSurface15=-1                 mask=0x400
surface   fieldSurface16=-1                 mask=0x400
surface   fieldSurface17=-1                 mask=0x400
surface   fieldSurface18=-1                 mask=0x400
surface   fieldSurface19=-1                 mask=0x400
surface   fieldSurface20=-1                 mask=0x400
surface   fieldSurface21=-1                 mask=0x400
surface   fieldSurface22=-1                 mask=0x400
surface   fieldSurface23=-1                 mask=0x400

message   startup
message   touched
message   pulse
message   trigger

end
#=================================================  =============#
code
#------------------------------------------------------
startup:
	// activate the forcefields, start the mat anim, and start pulsing on server. done locally on all comps.
	call activate_field;
	MaterialAnim(animMaterial, animSpeed, 0x1);
	if(IsServer()) SetPulse(0.2);

Return;
#------------------------------------------------------
touched:
	// damage the player and play a damage sound. done locally on one comp.
	// trigger sent so all players will hear the sound.
	DamageThing(GetSourceRef(), 10, 2, GetSourceRef());
	SendTrigger(-1, 1339, GetSourceRef(), 0, 0, 0);

Return;
#------------------------------------------------------
pulse:
	// find out if a player is inside a trigger sector. server only.
	inside = 0;
	for(i = 0; i < GetNumPlayers() && !inside; i = i + 1)
		for(j = 0; j < numTriggerSectors && !inside; j = j + 1)
			if(GetThingSector(GetPlayerThing(i)) == triggerSector0[j]) inside = 1;

	// activate or deactivate the fields if we need to.
	if(!inside && !active) SendTrigger(-1, 1337, 0, 0, 0, 0);
	else if(inside && active) SendTrigger(-1, 1338, 0, 0, 0, 0);

Return;
#------------------------------------------------------
trigger:
	// handle triggers. done locally on all comps.
	if(GetSourceRef() == 1337) call activate_field;
	else if(GetSourceRef() == 1338) call deactivate_field;
	else if(GetSourceRef() == 1339) PlaySoundThing(damageSound, GetParam(0), 1, 0, 10, 0x0);

Return;
#------------------------------------------------------
activate_field:
	// make the fields visible and play the hum sound. done locally on all comps.
	active = 1;
	id = PlaySoundPos(humSound, GetSurfaceCenter(soundSurface), 1.5, 2, 10, 0x1);
	for(i = 0; i < numFieldSurfaces && fieldSurface00 != -1; i = i + 1)
	{
		SetFaceGeoMode(fieldSurface00, 4);
		ClearAdjoinFlags(fieldSurface00, 2);
	}

Return;
#------------------------------------------------------
deactivate_field:
	// make the fields invisible and stop the hum sound. done locally on all comps.
	active = 0;
	StopSound(id, 0);
	for(i = 0; i < numFieldSurfaces && fieldSurface00 != -1; i = i + 1)
	{
		SetFaceGeoMode(fieldSurface00, 0);
		SetAdjoinFlags(fieldSurface00, 2);
	}

Return;
#------------------------------------------------------
end


Code:
# Jedi Knight Cog Script
#
# 00_DUALFORCEFIELD.COG
#
# This script handles the dual forcefields in C2
#
# This pair of forcefields (four faces) is powered on by a (shootable) switch.
# The forcefields remain on for 'time_on' seconds, then are set off.
# They cannot be set on again before 'delay' seconds have passed.
#
# [YB]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved


#=================================================  =============#
symbols

surface   switch                               mask=0x408
surface   forcefield0                          mask=0x408
surface   forcefield1                          mask=0x408
surface   forcefield2                          mask=0x408
surface   forcefield3                          mask=0x408

int       numFields
int       field_is_on=0                        local
int       ff_sound                             local
int       i                                    local

thing     player                               local

flex      time_on=5
flex      delay=10
flex      healspeed=0.2
flex      healammount=1
flex      oldtime0=0                           local
flex      oldtime1=0                           local
flex      oldtime2=0                           local
flex      oldtime3=0                           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

message   startup
message   activated
message   pulse
message   touched
message   timer

end
#=================================================  =============#
code
#------------------------------------------------------
startup:
	for(i = 0; i < numFields; i = i + 1) SetFaceGeoMode(forcefield0, 0);
	SetWallCel(switch, 1);

Return;
#------------------------------------------------------
activated:
	if(field_is_on) Return;
	field_is_on = 1;
	player = GetSourceRef();
	SetPulse(healspeed);
	// sound played only at field 0.
	ff_sound = PlaySoundPos(forcefield_snd, SurfaceCenter(forcefield0), 1, -1, -1, 0x1);
	for(i = 0; i < numFields; i = i + 1)
	{
		SetFaceGeoMode(forcefield0, 4);
		SetFaceLightMode(forcefield0, 0);
		ClearAdjoinFlags(forcefield0, 2);
		SetSurfaceFlags(forcefield0, 16384);
	}
	SetWallCel(switch, 0);
	PlaySoundPos(on_snd, SurfaceCenter(switch), 0.8, 5, 10, 0x0);
	SetTimer(time_on);

Return;
#------------------------------------------------------
pulse:
	if(GetThingHealth(player) > 0 && GetThingHealth(player) < 100) HealThing(player, healammount);
	else if(GetThingHealth(player) == 100 && GetInv(player, 60) < 200) ChangeInv(player, 60, healammount);

Return;
#------------------------------------------------------
timer:
	SetPulse(0);
	for(i = 0; i < numFields; i = i + 1)
	{
		SetFaceGeoMode(forcefield0, 0);
		SetFaceLightMode(forcefield0, 3);
		SetAdjoinFlags(forcefield0, 2);
		ClearSurfaceFlags(forcefield0, 16384);
	}
	StopSound(ff_sound, 0);
	Sleep(delay);
	SetWallCel(switch, 1);
	PlaySoundPos(off_snd, SurfaceCenter(switch), 0.8, 5, 10, 0x0);
	field_is_on = 0;

Return;
#------------------------------------------------------
touched:
	if(GetSenderRef() == switch || !field_is_on) Return;
	for(i = 0; i < numFields; i = i + 1)
	{
		if(GetSenderRef() == forcefield0 && GetLevelTime() > oldtime0 + 0.5)
		{
			oldtime0 = GetLevelTime();
			PlaySoundPos(ffdamage_snd, GetSurfaceCenter(forcefield0), 1, -1, -1, 0x0);
			DamageThing(GetSourceRef(), 10, 0x2, GetSourceRef());
		}
	}

Return;
#------------------------------------------------------
end 
  


I am starting to get nervous about not meeting the deadline for the Hub's contest, and my level depends on these two cogs, so it would be great if someone could help me work out these last few bugs so I can get the last few details of my level finished.
If curiosity killed the cat then perhaps Curious George killed the cat.
But Cat's do have nine lives so who knows?
2005-12-11, 3:00 PM #2
I'll take a look at them again. I have no idea why the complex cog isn't sending/acting on the trigger, but I think I see the problem with the dualforcefield cog.

This time, can you upload (or email me) your JED project instead of a gob file? I'll look at it today if there's time.
Historians are the most powerful and dangerous members of any society. They must be watched carefully... They can spoil everything. - Nikita Khrushchev.
Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god. - Jean Rostand.

↑ Up to the top!