PDA

View Full Version : 2 COG problems



Edward
08-04-2004, 09:39 AM
Hi!
1. I have this custom door COG, where if you hit a switch, the door will open or close. Now, I've set so that if you activate the door, it will play a locked sound indicating you'll need to activate a switch. Problem is that when I activate the door, the door opens... Why is that?



# Door Set 2
#
# By Edward
symbols

message startup
message activated

surface switch1
surface switch2

thing door
thing doorthing
thing bolt1
thing bolt2

int ch1=1 local
int open=0 local
flex speed

sound rotation
sound moving
sound bump

end
#
code
startup:
MoveToFrame(door,0,100);
SetWallCel(switch1,0);
SetWallCel(switch2,0);
return;
activated:
if((GetSenderRef()==switch1) || (GetSenderRef()==switch2))
{
if(open==0)
{
open=2;
SetWallCel(switch1,1);
SetWallCel(switch2,1);
ch1=PlaySoundThing(rotation,bolt1,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
ch1=PlaySoundThing(rotation,bolt2,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
SetThingRotVel(bolt1,'0 0 -90');
SetThingRotVel(bolt2,'0 0 90');
sleep(1);
StopThing(bolt1);
StopThing(bolt2);
ch1=PlaySoundThing(moving,bolt1,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
ch1=PlaySoundThing(moving,bolt2,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
SetThingVel(bolt1,'.2 0 0');
SetThingVel(bolt2,'-.2 0 0');
sleep(1);
StopThing(bolt1);
StopThing(bolt2);
AttachThingToThing(doorthing,door);
MoveToFrame(door,1,speed);
WaitForStop(door);
SetWallCel(switch1,0);
SetWallCel(switch2,0);
open=1;
}
else if(open==1)
{
open=2;
SetWallCel(switch1,1);
SetWallCel(switch2,1);
AttachThingToThing(doorthing,door);
MoveToFrame(door,0,speed);
WaitForStop(door);
ch1=PlaySoundThing(moving,bolt1,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
ch1=PlaySoundThing(moving,bolt2,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
SetThingVel(bolt1,'-.2 0 0');
SetThingVel(bolt2,'.2 0 0');
sleep(1);
StopThing(bolt1);
StopThing(bolt2);
ch1=PlaySoundThing(rotation,bolt1,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
ch1=PlaySoundThing(rotation,bolt2,1,-1,-1,0x80);
ChangeSoundPitch(ch1,0.75+rand()*0.50,0.1);
SetThingRotVel(bolt1,'0 0 90');
SetThingRotVel(bolt2,'0 0 -90');
sleep(1);
StopThing(bolt1);
StopThing(bolt2);
SetWallCel(switch1,0);
SetWallCel(switch2,0);
open=0;
}
}
else if(GetSenderRef()==doorthing)
{
PlaySoundThing(bump,doorthing,1,-1,-1,0x80);
}
return;
end


2. I have this draw bridge, and I wanted to add a little bounce effect when it comes to its level position. I managed to make that bounce effect, only, it's never straight after it bounces. So I try to set the origentation with a SetThingLook. Result: it disappears. Are there any other ways of solving this?



# The Bridge
#
# By Edward
symbols

message startup
message activated
message pulse

thing bridge1
thing bridge2

surface switch1
surface switch2

sound bridge1start
sound bridge1move
sound bridge1stop

sound bridge2start
sound bridge2move
sound bridge2stop

int drawn1=0 local
int drawn2=0 local
int ch1=1 local
int ch2=2 local
int i local

end
#
code
startup:
sleep(.5);
SetPulse(0.1);
MoveToFrame(bridge2,0,100);
WaitForStop(bridge2);
sleep(.5);
RotatePivot(bridge1,1,1);
SetPulse(0.1);
return;
activated:
if(GetSenderRef()==switch1)
{
If(drawn2!=0) return;
if(drawn1==0)
{
drawn1=2;
ch2=PlaySoundThing(bridge1start,bridge1,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
ch1=PlaySoundThing(bridge1move,bridge1,1,-1,-1,0x81);
RotatePivot(bridge1,1,-10);
WaitForStop(bridge1);
StopSound(ch1,1);
ch2=PlaySoundThing(bridge1stop,bridge1,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
// for(i=10; i<50; i=i+1)
// {
// RotatePivot(bridge1,1,i);
// sleep(0.01);
// }
// for(i=50; i>6; i=i-1)
// {
// RotatePivot(bridge1,1,-i);
// sleep(0.01);
// }
// StopThing(bridge1);
sleep(1);

drawn1=1;
}
else if(drawn1==1)
{
drawn1=2;
ch2=PlaySoundThing(bridge1start,bridge1,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
ch1=PlaySoundThing(bridge1move,bridge1,1,-1,-1,0x81);
RotatePivot(bridge1,1,15);
WaitForStop(bridge1);
StopSound(ch1,1);
ch2=PlaySoundThing(bridge1stop,bridge1,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
// for(i=15; i<50; i=i+1)
// {
// RotatePivot(bridge1,1,-i);
// sleep(0.01);
// }
// for(i=50; i>9; i=i-1)
// {
// RotatePivot(bridge1,1,i);
// sleep(0.01);
// }
// StopThing(bridge1);
sleep(1);

drawn1=0;
}
}
else if(GetSenderRef()==switch2)
{
if(drawn1!=1) return;
if(drawn2==0)
{
drawn2=2;
ch2=PlaySoundThing(bridge2start,bridge2,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
ch1=PlaySoundThing(bridge2move,bridge2,1,-1,-1,0x81);
MoveToFrame(bridge2,1,4);
WaitForStop(bridge2);
StopSound(ch1,1);
ch2=PlaySoundThing(bridge2stop,bridge2,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
drawn2=1;
}
else if(drawn2==1)
{
drawn2=2;
ch2=PlaySoundThing(bridge2start,bridge2,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
ch1=PlaySoundThing(bridge2move,bridge2,1,-1,-1,0x81);
MoveToFrame(bridge2,0,4);
WaitForStop(bridge2);
StopSound(ch1,1);
ch2=PlaySoundThing(bridge2stop,bridge2,1,-1,-1,0x80);
ChangeSoundPitch(ch2,.25,0.1);
drawn2=0;
}
}
return;
pulse:
SetWallCel(switch1,drawn1);
SetWallCel(switch2,drawn2);
ChangeSoundPitch(ch1,.75+(rand()*.5),0.1);
AttachThingToThing(bridge2,bridge1);
return;
end


/Edward

Ace1
08-04-2004, 11:15 AM
For the switch thing, I have no idea and this is why I'm no good at level cogs, but I'm guessing it has something to do with masks=whatever that goes in your symbols section with your things. I never bothered to learn about them though.

The SetThingLook disapearing problem I've run into before, and I think it does it because it's being set to an invalid vector or something, so it can't display the object because it's in an impossible position.

------------------
I am __Ace_1__ , and I approve this message.

[This message has been edited by Ace1 (edited August 04, 2004).]

Edward
08-04-2004, 01:13 PM
Impossible possition?
(0/7.6/-.1:0/0/0)
(0/7.6/-.1:90/0/0)
Doesn't seem like it...

And I don't think the Masks will help. Hasn't been a problem before...

/Edward

F-Body
08-04-2004, 04:59 PM
From what I understand, this should work for the first. (you need linkid's for doors and switches and (getsenderID). L@@ky l@@ky:
/edit: this cog is based on your wording but your cog looks like it has other elements to it.


# Jedi Knight Missions Cog Script
#
# For-Edward.cog
#
# [F-Body]
#
# This cog is not made or endorsed by LucasArts Entertainment Co.
#================================================= ========

symbols

message activate
message arrived
message blocked

thing door0 linkid=1

surface switch linkid=2

flex movespeed=8.0

int doorsector=-1 local

sound wav0=beep1.wav
sound locksound=df_door2-3.wav local

end

# ================================================== ======
code

activate:
if (GetSenderId() == 1)
{
PlaySoundThing(locksound, door0, 1.0, -1, -1, 0);
}
else if (GetSenderId() == 2)
{
if (GetCurFrame(door0) == 0)
{
call open_door;
}
else if (GetCurFrame(door0) == 1)
{
call close_door;
}
}
return;

# .................................................. ....
arrived:
if (GetCurFrame(door0) == 0)
{
SetWallCel(switch, 0);
}
return;

# .................................................. ....

blocked:
call open_door;
return;

# .................................................. ....
open_door:
SetWallCel(switch,1);
PlaySoundPos(wav0, SurfaceCenter(switch), 1, -1, -1, 0);
SectorAdjoins(doorsector, 1);
MoveToFrame(door0, 1, movespeed);
return;

# .................................................. ......

close_door:
SetWallCel(switch,0);
PlaySoundPos(wav0, SurfaceCenter(switch), 1, -1, -1, 0);
MoveToFrame(door0, 0, movespeed);
return;

end



[This message has been edited by F-Body (edited August 04, 2004).]

Edward
08-05-2004, 02:30 AM
LinkID worked!!! Yeah, thanks.

Now then... This bouncing bridge...

/Edward

Edward
08-08-2004, 03:05 AM
Now then... This bouncing bridge?

Edward
08-11-2004, 10:57 AM
Bouncy bounce bounce bounce?