ID:165414
 
hi, i need to know how i would make a teleport tile so when the player walks/flys into the tile they will automatically be teleported to another loction on the map,

thanks.
turf
teleporter
icon = 'water.dmi' // if you want to add icon
icon_state = "watever" // if needed
Enter()
usr.loc = locate(1,1,1) //change the location using xyz cordinates

- Miran94
In response to Miran94
You really need to stop giving people advice that will screw they're game up.
turf
tele
Enter(mob/O)
if(ismob(O) && O.client))
O.loc = locate(x,y,z)
In response to Miran94
Miran94 wrote:
> turf
> teleporter
> icon = 'water.dmi' // if you want to add icon
> icon_state = "watever" // if needed
> Enter()
> usr.loc = locate(1,1,1) //change the location using xyz cordinates
>

- Miran94

No, please don't post code help when you don't completly understand what you're doing. The code is wrong, and you will just get many potential errors.

In order to teleport, you must use the Entered() proc, and get the object that entered the teleporter by looking at the first argument of Entered. You cannot just rely on 'usr', because it isn't always the enterer of the teleporter.

turf/teleporter
Entered(atom/movable/A) // rely on 'A' to find out who entered the teleporter
A.loc = locate(1,1,1) // or whatever coordinates you would like
return ..() // call and return parent implementations if applicable


If you would like only players to enter, you will have to do special checks. First, you must check if the enterer 'A' is a mob, and check if the mob has a client controlling it.

turf/teleporter
Entered(atom/movable/A)
if(ismob(A)) // check if the enterer is a mob
var/mob/M = A // type cast
if(M.client) // check if the enterer has a client controlling it (ie. a player)
M.loc = locate(1,1,1)
return ..()
In response to Unknown Person
My code works fine I tested it out myself so stop nagging its so irritating.
In response to Unknown Person
Wouldn't that be A.client ?
In response to Miran94
Miran94 wrote:
My code works fine I tested it out myself so stop nagging its so irritating.

Sure it works fine for mobs with a client, wait till a projectile hits it.
In response to Xx Dark Wizard xX
That code is only usrers not projectiles and things.
In response to Miran94
But a projectile or NPC can enter it, you need to read the DM guide.
In response to Xx Dark Wizard xX
If projectiles and npcs can enter it just add an
turf
wereugo
turf
teleporter
icon = 'water.dmi' // if you want to add icon
icon_state = "watever" // if needed
Enter()
var/mob/M = A
if(M.client)
A.loc = locate(/turf/wereugo)
In response to Miran94
What the hell is 'A'? That'll give you errors.. and how the hell you got the idea of using M? If you defined 'A' properly, you wouldn't need M...

- GhostAnime
In response to GhostAnime
GhostAnime wrote:
What the hell is 'A'? That'll give you errors.. and how the hell you got the idea of using M? If you defined 'A' properly, you wouldn't need M...

- GhostAnime

He just edited UP's code.
In response to Miran94
Miran94 wrote:
My code works fine I tested it out myself so stop nagging its so irritating.

No, the code is not fine. It works fine when you test it in your suitable and perfect situations when you move your player onto the warp tile. But when it's in a real game situation, these "perfect situations" do not happen all the time.

The problem with the code you supplied is your bad and blatantly wrong usage of 'usr'. It's a misconception for new programmers to think 'usr' is "the user," which is wrong and not always the case. usr simply is the object that called the proc. If you had a verb that controlled another player's movement, and wanted to move the player inside of the warp, 'usr' would be the player who is controlling the one who actually entered the warp. To fix this, you need to rely on the proc's first argument, which is always the object that entered it. There are many other situations where this would happen, which is the reason why you should never use usr in procs.

You should only be using Enter() if you want to disallow entrance into the object. In this case, Entered() would be more suitable. You would want to use Entered() because it is called if the object successfully entered the tile.

I'm sorry for nagging at you, but it's much more beneficial when a new programmer doesn't learn wrong things from another new programmer.
In response to Unknown Person
Unknown Person wrote:
You should only be using Enter() if you want to disallow entrance into the object. In this case, Entered() would be more suitable. You would want to use Entered() because it is called if the object successfully entered the tile.

So true. Both using Enter() instead of Entered() and using 'usr' wrong are common DM mistakes.

A little note; on your posted code, you typecasted the argument as atom/movable, then when checking if it's a mob with a client, you created another var and typecasted it as /mob... that is not necessarily, you can just typecast the argument as /mob in the first place - it does no problems, and in this case, it's the most beneficial.
In response to Kaioken
Kaioken wrote:
A little note; on your posted code, you typecasted the argument as atom/movable, then when checking if it's a mob with a client, you created another var and typecasted it as /mob... that is not necessarily, you can just typecast the argument as /mob in the first place - it does no problems, and in this case, it's the most beneficial.

I left that out intentionally to show him how to type cast from an argument. If the programmer only wanted to do something if a player entered the warp, then that would indeed be the way to go, though it doesn't matter that much.