insane_metalhead, on 21 September 2011 - 02:13 PM, said:
Can somebody help me to code a new sort of teleportation method? What I want to do is when standing in a sector (SE7) you have to hit space to teleport. Is this difficult to do?
It'll be a lot easier if you just create two user actors to execute the code instead of trying to mess around with an SE. Attached is a rough version of the effect. The code's all at the bottom of the game.con therein, but I'll post it here for the sake of explaining it. Course, if someone else has a more efficient way of doing it, feel free to tell me; this is just something I whipped up in about five minutes.
gamevar hitagsaved 0 2 // var used for grabbing the hitag from the actor right when it's loaded into the map
gamevar temphitag 0 2 // temporary var used for storing the hitag as an actorvar
gamevar fakehitag 0 2 // var used for the storing the hitag value so it can be read in actor code.
gamevar GLOBALHITAG -1 0 // a global var that will be set when the "START" teleport actor is engaged.
gamevar x 0 2
gamevar y 0 2
gamevar z 0 2
gamevar sector_actor 0 2
gamevar sector_player 0 2 // just position/sector variables.
define TELEPORTSTART 3328 // the actor that the player engages
define TELEPORTEND 3329 // the actor that changes the player's coordinates
eventloadactor TELEPORTSTART // when the TELEPORTSTART actor is loaded into the map...
getactor[THISACTOR].hitag hitagsaved // get its hitag value
setactorvar[THISACTOR].temphitag hitagsaved // and set the "temphitag" variable to whatever that value is
setactor[THISACTOR].hitag 0 // then set the hitag to zero.
enda
eventloadactor TELEPORTEND // and do the same thing for the TELEPORTEND actor
getactor[THISACTOR].hitag hitagsaved
setactorvar[THISACTOR].temphitag hitagsaved
setactor[THISACTOR].hitag 0
enda
useractor notenemy TELEPORTSTART 0
cstat 32768 // make it invisible
getactorvar[THISACTOR].temphitag fakehitag // set the "fakehitag" variable equal to the value of the "temphitag" variable
getactor[THISACTOR].sectnum sector_actor
getplayer[THISACTOR].cursectnum sector_player // get the sector number of both the player, and the TELEPORTSTART actor...
ifvarvare sector_actor sector_player // if they're equal (i.e the player is in the same sector as the TELEPORTSTART actor)...
{
ifhitspace { // if the player hits space...
ifcount 15 {
setvarvar GLOBALHITAG fakehitag resetcount // set the "GLOBALHITAG" variable equal to the value of the "fakehitag" variable.
}
}
}
enda
useractor notenemy TELEPORTEND 0
cstat 32768
getactorvar[THISACTOR].temphitag fakehitag // again, set the "fakehitag" variable
getactor[THISACTOR].sectnum sector_actor
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z // grab the "TELEPORTEND" actor's x, y, z coordinates and sector number
ifvarvare GLOBALHITAG fakehitag { // if the "GLOBALHITAG" variable is equal the the "TELEPORTEND" actor's "fakehitag" variable...
setplayer[THISACTOR].cursectnum sector_actor
setplayer[THISACTOR].posx x
setplayer[THISACTOR].posy y // set the player's sector, x and y coordinates equal to the "TELEPORTEND" actor's...
subvar z 6500 // subtract 6500 from the "TELEPORTEND" actor's z-coordinate. (If this isn't done, the screen will briefly flicker towards the floor upon teleporting)
setplayer[THISACTOR].posz z // set the player's z-coordinate equal to the new z-coordinate.
setvar GLOBALHITAG -1 } // and reset the "GLOBALHITAG" so it can be done all over again.
enda
The map makes it clear-cut enough, but basically all you do is take a "TELEPORTSTART" actor and a "TELEPORTEND" actor, put them at two different parts of the map, then give them matching hitags.