ID:178410
 
i need some help on teleporting things, actully i have no clue where to start! If someone could give me a couple little pointers, that would help out alot! ^_^

P.S. - Don't tell me to look at the teleporting things demo, it says it can't find the page...
Well if you would want to go to a mob's location then you could,

mob/verb/Go_To_Mob(mob/M as mob in world)
src.Move(M.loc)

mob/verb/Send_Person_To_You(mob/M as mob in world)
M.Move(src.loc)

mob/verb/Go_By_Coordinates(X as num,Y as num,Z as num)
if(X > 1 && X <= world.maxx|| Y > 1 && Y <= world.maxy|| Z > 1 && Z <= world.maxz)
var/relocate = locate(X,Y,Z)
src.Move(relocate)
else
return
If you want the object you're moving to pay attention to the Enter, Entered, Exit, and Exited procs that are already included in DM, then you should move it like this:

<code>object.Move(locate(x,y,z)) </code>

// z,y,z being the coords you're sending it to.

Using Move() you have more control over things, such as disallowing movement if the object's loc's Exit() proc returns 0, then the object will be unable to move out of its location. If you want things to just move regardless of anything at all, just relocate them like this:

<code>object.loc = locate(x,y,z)</code>

For more information, look up "Motion" in the Guide.
In response to Super16
im not understanding foobar, and super16 thats not exactly what i wanted... what i ment would be like... someone walks to a specific spot and they get teleported... could you help me out with that? thx 0.o
In response to Redslash
turf
specialport //change name to what you like
Enter()
usr.loc=(1,1,1) //put the location to what you want
usr<<"You have teleported."

thats about it
In response to Richter
its not working, it comes up with this error:

FFChat.dm:24:error::invalid expression

plz help
In response to Redslash
Try comparing it with my post.

<code>obj.loc = locate(x,y,z)</code>
In response to Foomer
it doesn't give me a error, but it doesn't do anything, heres my code for it:

area
STW
Enter()
usr.loc = locate(x,y,z)
please help :)
In response to Redslash
Red, go to www.byond.com instead of the www.dantom/byond.com or whatever.
You might also have a look in the FAQ. I hear some guy wrote an answer for this, but he may not have known what he was talking about.
In response to Richter
Richter wrote:
turf
specialport //change name to what you like
Enter()
usr.loc=(1,1,1) //put the location to what you want
usr<<"You have teleported."

thats about it

That's about the worst way to do it, too. Don't give people advice if you don't know what you're doing yourself.

  • Enter() is the wrong way to handle teleporting. This should be done with Entered().
  • Using usr in Enter() or Entered() is absolutely moronic. I have no kinder way to say that.
  • Enter() takes an argument--the thing that's trying to enter--and returns a 0 or 1 value to say whether the object can (1) or can't (0) enter via a normal Move(). Entered() takes two arguments and returns nothing; the first argument is the thing that entered, and the second is that thing's old location.

    Egads. When will people stop giving putzy half-baked advice? Learn what you're doing before you try to help others, or you'll only screw them up worse.

    Lummox JR
In response to Redslash
Redslash wrote:
it doesn't give me a error, but it doesn't do anything, heres my code for it:

area
STW
Enter()
usr.loc = locate(x,y,z)
please help :)

That doesn't work because Richter happens to have given you the worst advice imaginable. Don't use his code or anything that looks remotely like it. Using Enter() is wrong, ignoring its argument is wrong, and using usr here is dead wrong. He should have known better.

Lummox JR
In response to Lummox JR
Now now, it doesn't do any good to complain unless you suggest a useful alternative.
In response to Foomer
Foomer wrote:
Now now, it doesn't do any good to complain unless you suggest a useful alternative.

I did suggest such an alternative, in another post on this thread. I stated exactly what's wrong with the code as posted.

Lummox JR
In response to Lummox JR
Yeah, but you didn't state it until after I posted that.
In response to Foomer
Foomer wrote:
Yeah, but you didn't state it until after I posted that.

I'm not sure I follow you. The post where I dissected everything that was wrong with his code was made before the one you responded to.

Lummox JR
In response to Lummox JR
Oh hey sorry Mr. Perfect. but the way i showed works perfectly fine for me. unlike some people i like to make my code short and done. thats the quickest way for teleport.(well that i know of any ways.)
In response to Richter
Richter wrote:
Oh hey sorry Mr. Perfect. but the way i showed works perfectly fine for me. unlike some people i like to make my code short and done. thats the quickest way for teleport.(well that i know of any ways.)

No, it doesn't work fine. It's broken about nine ways from Sunday and will only work in a single-player game, and only when no other objs or mobs are moving around.

There are quick ways to code teleportation that aren't broken, so don't give people advice until you learn what you're doing yourself. Your code may be short, but it's not much shorter than a semi-robust version that actually works. You need to learn the difference between short code and elegant code; the latter is as short as possible while also being as robust (for simple use) as possible. A prerequisite to elegant code is that it not cause bugs, particularly flaky bugs like the kind that would happen in your code if it was used in any other situation.

Just to show you what I'm talking about, since based on your response I doubt you're going to comprehend this any other way, the following is a simple snippet of code for teleportation that is short, and works:
turf/teleport
Entered(atom/movable/A)
if(ismob(A)) A.loc = locate(1,1,1)

That's every bit as short as your code, but it won't blow up in multiplayer cases or when objs or monsters move around.

Lummox JR