SOLVED!     (Moderator: Edward) Previous Topic | Next Topic
Page 1 of 1
 Author 
 Post 
Post 04-Jun-2008 18:49        

SOLVED! FireProjectile with offset Does Stop if anything is in its path.


Number 1
Got a Platform Elevator here with 2 attached switches that, if you stand too close to them, you get teleported to the reset positions and one switch ends up in the center.


# Platform Elevator with up-down and call switches. Support for 8 floors.
#
# By Edward
flags=0x240
symbols

message      startup
message      activated
message      trigger
message      pulse
message      arrived

thing      elev      linkid=5,mask=0xFFF
thing      upswitch   linkid=5,mask=0xFFF
thing      downswitch   linkid=5,mask=0xFFF

surface      callswitch0   linkid=5
surface      callswitch1   linkid=5
surface      callswitch2   linkid=5
surface      callswitch3   linkid=5
surface      callswitch4   linkid=5
surface      callswitch5   linkid=5
surface      callswitch6   linkid=5
surface      callswitch7   linkid=5

vector      floor0
vector      floor1
vector      floor2
vector      floor3
vector      floor4
vector      floor5
vector      floor6
vector      floor7

flex      startspeed
flex      rate      local
flex      inc
flex      maxspeed
flex      speed      local
flex      vdist      local
int      vdistI      local

int      numfloors=7

int      startfloor=0

sound      switchit
sound      startmove
sound      contimove
sound      stopmove

int      ch1=-1      local
thing      temp=-1      local

int      frame      local
int      startframe   local

vector      offset0      local
vector      offset1      local
vector      looking0   local
vector      looking1   local

int      i      local
int      outofcom=0   local

end
#
code
startup:
   sleep(rand());
   outofcom=1;
   AttachThingToThing(upswitch,elev);
   AttachThingToThing(downswitch,elev);
   offset0=VectorSub(GetThingPos(upswitch),GetThingPos(elev));
   offset1=VectorSub(GetThingPos(downswitch),GetThingPos(elev));
   looking0=GetThingLVec(upswitch);
   looking1=GetThingLVec(downswitch);
   MoveToFrame(elev,0,100);
return;
activated:
   If(GetSenderID()==5)
   {
      If(IsMoving(elev)) return;
      SendTrigger(-1,GetSelfCog(),callswitch0,GetSenderRef(),-1,-1);
   }
   if(GetParam(0)==128)
   {
      If(IsMoving(elev)) return;
      SendTrigger(-1,GetSelfCog(),callswitch0,callswitch5,-1,-1);
   }
   else if(GetParam(0)==129)
   {
      If(IsMoving(elev)) return;
      SendTrigger(-1,GetSelfCog(),callswitch0,upswitch,-1,-1);
   }
return;
trigger:
   If(GetSourceRef()!=GetSelfCog()) return;
   if(GetParam(0)!=callswitch0) return;
   ParseArg(elev,"soundclass=none");
   ParseArg(upswitch,"move=none");
   ParseArg(downswitch,"move=none");
   for(i=0; i<8; i=i+1)
      SetWallCel(callswitch0[i], 0);
   if(GetParam(1)==upswitch)
   {
      PlaySoundThing(switchit,upswitch,1,-1,-1,0x80);
      if(GetCurFrame(elev)+1>numfloors)
      {
         PlaySoundThing(stopmove,elev,1,-1,100,0x80);
         return;
      }
      PlaySoundThing(startmove,elev,1,-1,100,0x80);
      ch1=PlaySoundThing(contimove,elev,0,-1,100,0x81);
      ChangeSoundPitch(ch1,.01,.01);
      ChangeSoundVol(ch1,1,1);
      startframe=GetCurFrame(elev);
      frame=GetCurFrame(elev)+1;
   }
   else if(GetParam(1)==downswitch)
   {
      PlaySoundThing(switchit,downswitch,1,-1,-1,0x80);
      if(GetCurFrame(elev)-1<0)
      {
         PlaySoundThing(stopmove,elev,1,-1,100,0x80);
         return;
      }
      PlaySoundThing(startmove,elev,1,-1,100,0x80);
      ch1=PlaySoundThing(contimove,elev,0,-1,100,0x81);
      ChangeSoundPitch(ch1,.01,.01);
      ChangeSoundVol(ch1,1,1);
      startframe=GetCurFrame(elev);
      frame=GetCurFrame(elev)-1;
   }
   else
   {
      for(i=0; i<=numfloors; i=i+1)
      {
         if(GetParam(1)==callswitch0[i])
         {
            PlaySoundPos(switchit,GetSurfaceCenter(callswitch0[i]),1,-1,-1,0x0);
            PlaySoundThing(startmove,elev,1,-1,100,0x80);
            ch1=PlaySoundThing(contimove,elev,0,-1,100,0x81);
            ChangeSoundPitch(ch1,.01,.01);
            ChangeSoundVol(ch1,1,1);
            startframe=GetCurFrame(elev);
            frame=i;
         }
      }
   }
return;
pulse:
   AttachThingToThing(upswitch,elev);
   AttachThingToThing(downswitch,elev);
   if(frame==-1)
   {
      speed=startspeed;
   }
   else
   {
      SetWallCel(callswitch0[frame],1);
      if((speed<maxspeed) && (vdistI==0))
      {
         speed=speed+inc;
      }
      else if(speed>=maxspeed)
      {
         speed=maxspeed;
         if(vdistI==0)
         {
            vdist=VectorDist(GetThingPos(elev),floor0[startframe]);
            vdistI=1;
         }
      }
      if((VectorDist(GetThingPos(elev),floor0[frame])<vdist) && (vdistI==1))
      {
         speed=speed-inc;
      }
      if(speed<startspeed)
      {
         speed=startspeed;
         frame=-1;
      }
      ChangeSoundPitch(ch1,speed/10,0.01);
      MoveToFrame(elev,frame,speed);
   }
return;
arrived:
   If(GetSenderRef()!=elev) return;
   If(outofcom==1)
   {
      floor0[GetCurFrame(elev)]=GetThingPos(elev);
      if(GetCurFrame(elev)<numfloors)
      {
         MoveToFrame(elev,GetCurFrame(elev)+1,100);
      }
      else
      {
         outofcom=0;
         MoveToFrame(elev,startfloor,100);
         frame=-1;
         vdistI=0;
         for(i=0; i<8; i=i+1)
            SetWallCel(callswitch0[i],0);
         SetWallCel(callswitch0[startfloor],1);
         SetPulse(0.02);
      }
   }
   else
   {
      StopSound(ch1,1);
#      StopThing(elev);
      PlaySoundThing(stopmove,elev,1,-1,100,0x80);
      vdistI=0;
      frame=-1;
      temp=-1;
      while(temp==-1)
         temp=FireProjectile(elev,GetThingTemplate(upswitch),-1,-1,VectorSet(VectorX(offset0),VectorY(offset0),VectorZ(offset0)),GetThingLVec(upswitch),0,0,0,0);
      If(upswitch>1)
         TeleportThing(upswitch,temp);
      DestroyThing(temp);
      temp=-1;
      while(temp==-1)
         temp=FireProjectile(elev,GetThingTemplate(downswitch),-1,-1,VectorSet(VectorX(offset1),VectorY(offset1),VectorZ(offset1)),GetThingLVec(downswitch),0,0,0,0);
      if(downswitch>1)
         TeleportThing(downswitch,temp);
      DestroyThing(temp);
      SetThingLook(upswitch,looking0);
      SetThingLook(downswitch,looking1);
   }
return;
end

Templates used: Elev: 8x8elev, switches: console1

Please help soon and I can get this done this month.
/Edward

Last edited by Edward on 14-Sep-2008 18:38; edited 2 times in total
Post 04-Jun-2008 19:20        

Is something wrong with the cogs?
Post 05-Jun-2008 17:02        

I believe so. Whenever I am within a few feet of the consoles and the elevator reaches its destination, I (the player) get teleported to the consoles location and the console gets teleported to the elevator's center. Can't think of anything else but COG problems.
Post 05-Jul-2008 11:49        

i was going to try and help with your cog issues, but after seeing how long winded and complicated it is, my brain melted sorry
ZeqMacaw
Site Admin
Post 05-Jul-2008 22:42        

I have looked over the cog and see nothing that would cause the problem. Perhaps there is some issue with collide sizes or special circumstance with the level causing the problem.

If you upload a test level that shows the problem, I could help further.

Post 11-Jul-2008 14:33        

Ok, I got around to making a test level with the elevator (using above COG). And yes, the problem is in the test level. I've uploaded it to the download section (in Source form, not GOB, JKL not included) and I hope people can find what's wrong with it.

/Edward
*** Post commands are unavailable for guests. ***