# Jedi Knight Cog Script # # prl_door_auto.cog # Sylvicolus [PRL] 13 August 2001 # http://www.lactarius.com/sylvicolus/jk/ # # ===This cog is for single player levels only.========================== # Based on 00_elev_switch.cog and 00_door.cog with functions and adjoin code added. # FOR USE WITH ONLY ONE DOOR. Do not use see-through doors # Cog affects the adjoins of the door sector but does not affect light value. # Door will react to "blocked" message (player is blocking door movement). # Door opens, sleeps, and closes. # # Five methods to open door, depends on which variables you supply values for. # The mask=0x405 allows both player and AI to open door by these methods. # AI can always open door from either side. # # Give a value for ANY of the following variables to get the door to open. # # outer_adjoin0, outer_adjoin1, outer_adjoin2 -- crossing these adjoin surfaces. # # button -- surface is a switch you can put anywhere to open the door. # # floor_by_door -- floor surface is stepped on. # # Door opens if player is in sector_by_door and activates the door (spacebar). # Sector_by_door0 -- Entering this sector (use for onlocked side of door). # Sector_by_door1 -- the next adjacent sector if the first sector is small. # # If sector_active=1 then entering a sector_by_door will also open the door. # # If alarm_active=1 then alarm will briefly sound when activating locked door. # # This cog is not supported by LucasArts Entertainment Co. symbols message startup message crossed message entered message activated message touched message arrived message blocked thing door0 linkid=2 mask=0x405 flex sleeptime=2.0 flex speed=4.0 surface outer_adjoin0 linkid=1 mask=0x405 surface outer_adjoin1 linkid=1 mask=0x405 surface outer_adjoin2 linkid=1 mask=0x405 surface button linkid=1 mask=0x405 surface floor_by_door linkid=1 mask=0x405 sector sector_by_door0 linkid=3 mask=0x405 sector sector_by_door1 linkid=3 mask=0x405 int sector_active=0 int alarm_active=0 sound wav0=beep1.wav local sound wav1=lvrclik2.wav local sound wav2=00alarmloop03.wav local sector doorSector local int sector local int cog_active=0 local thing player local end # =================================================================== code startup: doorSector = GetThingSector(door0); SetSectorAdjoins(doorSector, 0); player = jkGetLocalPlayer(); return; crossed: // outer adjoin(s) entered: // floor_by_door or sector_by_door if (cog_active==1) return; if (GetSourceRef() != player) { // AI opens door cog_active=1; call OpenDoors; return; } if (sector_active == 0 && GetSenderId() == 3) return; // sector does not trigger door cog_active=1; call OpenDoors; return; touched: if (GetSourceRef() == player) return; //AI can activate doors with touch activated: // press button or door if (cog_active==1) return; cog_active=1; if (GetSourceRef() != player && GetSenderId() == 2) { // AI opens door call OpenDoors; return; } sector = GetThingSector(player); if (GetSenderId() == 2 && sector != sector_by_door0 && sector != sector_by_door1) { // message came from door and player not on inside sector. PlaySoundThing(wav1, door0, 1.0, -1, -1, 0); // door sound if (alarm_active == 1) PlaySoundThing(wav2, door0, 1.0, -1, -1, 0); // alarm sound sleep(0.3); cog_active=0; return; } call OpenDoors; return; OpenDoors: if (GetCurFrame(door0) != 0) return; // no effect if door is open or moving sleep(0.1); if (button) { SetWallCel(button, 1); PlaySoundPos(wav0, SurfaceCenter(button), 0.6, -1, -1, 0); } SetSectorAdjoins(doorSector, 1); MoveToFrame(door0, 1, speed); // open door return; arrived: if (GetCurFrame(door0) == 0) { SetSectorAdjoins(doorSector, 0); if (button) { SetWallCel(button, 0); PlaySoundPos(wav0, SurfaceCenter(button), 0.6, -1, -1, 0); } cog_active=0; } else // door open, so sleep then close { Sleep(sleeptime); MoveToFrame(door0, 0, speed); } return; blocked: MoveToFrame(door0, 1, speed); return; end