I am working on a new elevator that teleports the player and other sprites to a floor of the players choice. Moving sprites seems to work just fine but moving the player proves to be problematic, the first time the player is moved just fine but after that it seems to randomly work.
I have to following:
All sprites are moved relatively to the elevator switch.
The location and sector of the switch the player is using are stored in:
MX,MY,MZ, MSECTOR
And the location and sectore of the destination switch are stored in:
x, y, z, sect
What I do is get the position of the player and make it relative to the current switch then I add the location of the destination switch (this should give the right coordinates). The first time I use the switch the player is moved and if there are sprites in the elevator they are moved as well. But the second time only the sprites get moved and the player acts randomly. Sometimes you can see a flash of the destination and then are immediately moved back to the old sector and position. Sometimes it just works. I have no idea and am now also changing the old position of the player but no luck so far.
This is my code. Some help would be appreciated, this thing is driving me nuts and I have been changing shit around even looking at the teleporter code in the source of EDuke.
gamearray TEMPARRAY 1 state binary_elevator_switch_teleport { setvar target -1 ifactor ELEVATORSWITCHDOWN // find ELEVATORSWITCHUP to teleport to { for GTEMP1 allsprites { ifvare sprite[GTEMP1].picnum ELEVATORSWITCHUP { ifvarvare actorvar[GTEMP1].HITAGSAVED HITAGSAVED { setvarvar target GTEMP1 } } } } else ifactor ELEVATORSWITCHUP // find ELEVATORSWITCHDOWN to teleport to { for GTEMP1 allsprites { ifvare sprite[GTEMP1].picnum ELEVATORSWITCHDOWN { ifvarvare actorvar[GTEMP1].HITAGSAVED HITAGSAVED { setvarvar target GTEMP1 } } } } setvar GTEMP2 0 // Count all sprites ifvarn target -1 { for GTEMP1 spritesofsector sprite[THISACTOR].sectnum { ifvarvarn GTEMP1 THISACTOR { ifvarn sprite[GTEMP1].picnum APLAYER { addvar GTEMP2 1 } } } } // Only if we got any sprites ifvarg GTEMP2 0 { resizearray TEMPARRAY GTEMP2 setvar GTEMP2 0 for GTEMP1 spritesofsector sprite[THISACTOR].sectnum { ifvarvarn GTEMP1 THISACTOR { ifvarn sprite[GTEMP1].picnum APLAYER { setarray TEMPARRAY[GTEMP2] GTEMP1 addvar GTEMP2 1 } } } } // Teleport all sprites in ifvarn target -1 { // Get this switch pos getactor[THISACTOR].x MX getactor[THISACTOR].y MY getactor[THISACTOR].z MZ getactor[THISACTOR].sectnum MSECTOR // Get target switch pos getactor[target].x x getactor[target].y y getactor[target].z z getactor[target].sectnum sect setvar GTEMP5 0 getarraysize TEMPARRAY GTEMP6 // for GTEMP1 spritesofsector sprite[THISACTOR].sectnum whilevarvarn GTEMP5 GTEMP6 { // Get sprite setvarvar GTEMP1 TEMPARRAY[GTEMP5] addvar GTEMP5 1 // Get actor position getactor[GTEMP1].x GTEMP2 getactor[GTEMP1].y GTEMP3 getactor[GTEMP1].z GTEMP4 // Make relative to this switch position subvarvar GTEMP2 MX subvarvar GTEMP3 MY subvarvar GTEMP4 MZ // Add other switch position addvarvar GTEMP2 x addvarvar GTEMP3 y addvarvar GTEMP4 z // Set actor position setactor[GTEMP1].x GTEMP2 setactor[GTEMP1].y GTEMP3 setactor[GTEMP1].z GTEMP4 // Update old position ( getting desperate) setactor[GTEMP1].htbposx GTEMP2 setactor[GTEMP1].htbposy GTEMP3 setactor[GTEMP1].htbposz GTEMP4 // Set sector setactor[GTEMP1].sectnum sect } // Teleport the player (todo: add sector check) getplayer[THISACTOR].i GTEMP1 // Get player position getplayer[THISACTOR].posx GTEMP2 getplayer[THISACTOR].posy GTEMP3 getplayer[THISACTOR].posz GTEMP4 // Make relative to this switch position subvarvar GTEMP2 MX subvarvar GTEMP3 MY // Add other switch position addvarvar GTEMP2 x addvarvar GTEMP3 y // Get old sector hight getflorzofslope MSECTOR MX MY MZ // Get new sector hight getflorzofslope sect GTEMP2 GTEMP3 z // subtract old sector height subvarvar GTEMP4 MZ // Add new sector height addvarvar GTEMP4 z // Set player position setplayer[THISACTOR].posx GTEMP2 setplayer[THISACTOR].posy GTEMP3 setplayer[THISACTOR].posz GTEMP4 setplayer[THISACTOR].oposx GTEMP2 setplayer[THISACTOR].oposy GTEMP3 setplayer[THISACTOR].oposz GTEMP4 // Set sector setplayer[THISACTOR].cursectnum sect // Set actor position setactor[GTEMP1].x GTEMP2 setactor[GTEMP1].y GTEMP3 setactor[GTEMP1].z GTEMP4 setactor[GTEMP1].htbposx GTEMP2 setactor[GTEMP1].htbposy GTEMP3 setactor[GTEMP1].htbposz GTEMP4 // Set sector setactor[GTEMP1].sectnum sect sound MONITOR_ACTIVE } } ends