ID:2142731
 
(See the best response by Ter13.)
What is the code for a Mob entering a place? plz Halp!!!
Best response
Can you clarify what you mean? Your question is too vague to be understood.
like


Enter(mob/M)
if(M.client)
usr.loc = locate(88,195,27)


Though I didnt write that someone told me that but it isnt working for me.


Did you understand A bit better? xd
This is a very simple version of what I'd normally do, because I suspect you are just starting to learn the language.

First, we need to change some behavior in atom/movable:

atom
movable
var/tmp
teleporting = 0
proc
Teleport(atom/loc)
var/odensity = density
density = 0
++teleporting
Move(loc)
if(--teleporting<0) teleporting = 0
density = odensity


What this function does is make sure that the player's movement doesn't fail to ensure that they get teleported to the proper place. We also never want to set loc manually because we always want to be able to know when a movable has done some movement. Setting variables you want to keep track of manually is bad and causes a lot of problems later.

turf/specialturf
Entered(atom/movable/o)
if(ismob(o)&&!o.teleporting)
var/mob/m = o
if(m.client)
m.Teleport(locate(88,195,27))
..()


Next, we use the teleport function in turf/Entered(). The reason we don't use Enter() is because Enter() checks whether something can enter a location, while Entered() responds to a player actually entering the location.

We also don't want teleporting tiles to trigger when the mob is already teleporting to keep them from getting stuck in an infinite loop and crashing your world. That's why we check the teleporting variable we set up earlier.



Also, in the future, Developer Help is the right forum for code questions. BYOND Help is for problems with the software not related to programming. You can also post your code between HTML tags like this:

<DM>
code goes here
</DM>

To make it show up in a more readable format.

Cheers!
OMG
THANK YOU SO MUCH
IF I WASNT GAY I WOULD SO KISS YOU RIGHT NOW (NO HOMO ) YOUR THE BEST THANKS!!!!
Hmm?
What if I wanted to make a certain person only enter this Place, No on else can?
In response to Ter13
Hmm, When I try repeating it, It doesnt work So I cant repeat it? cause Im trying to make people enter other places to.
What if I wanted to make a certain person only enter this Place, No on else can?

That would depend on how you are determining who that person is. Checking the client's ckey would be one way to do that.

When I try repeating it, It doesnt work So I cant repeat it? cause I'm trying to make people enter other places to.

Not sure what you mean. You need to be more descriptive when you ask questions. I know it's hard when you are new to something to ask strong, descriptive questions, but the better your questions are, the more help others can give you. Just remember that other people don't live in your head, so we can't always know exactly what you mean.
In response to Ter13
Oh Sorry, Im not good at describing things but here's what it said,

atom.dm:5:error: teleporting: duplicate definition
atom2.dm:4:error: teleporting: previous definition
atom2.dm:6:error: Teleport: duplicate definition
atom.dm:7:error: Teleport: previous definition
You don't need to copy and paste the same code over and over again.

The atom/movable modification that we made is already defined, so we don't need to define it a second time. Once defined, you can use that little bit of code over and over again.
In response to Ter13
Mind telling which bit of that code I can use over again? 3:
atom //A
movable //B
var/tmp //C
teleporting = 0 //D
proc //E
Teleport(atom/loc) //F
//G
var/odensity = density
density = 0
++teleporting
Move(loc)
if(--teleporting<0) teleporting = 0
density = odensity


Programming is about using tokens to denote information in a particular format.

The compiler expects a specific format, and the format is important for getting the environment to do what you want it to. This is called "syntax".

I've marked some of the lines in the above code snippet with letters.

A: Path token
B: Path token
C: Variable token
D: Variable definition
E: Proc (function) token
F: Proc/argument definition
G: Proc body

In DM, paths are ways to tell the engine that a certain bit of code belongs to a type of object. This is called prototyping. When you type path tokens, you are informing the compiler that the information beneath the path token is part of that prototype that you are either creating or extending.

Variable tokens are places that you can store data. In DM, prototype variables belong to an INSTANCE of a prototype. Prototypes define the structure of instances. An instance is a copy of a prototype with its own information, but the entire structure of the prototype. This is a theory called polymorphism, which is a subset of object oriented programming.

Procs are groups of instructions that can be called to perform behavior. Procs actually do things. variables just hold things. Procs are the meat and potatoes of game design in DM. Procs consist of three parts, a name, arguments, and a body. The name is the way you use the proc (by invoking its name), and the arguments are temporary data that are passed into the proc so that you can make it do different things in the body. The body is where instructions go that make up what the proc does.



Mobs and objs derive from /atom/movable. By defining the teleporting variable and Teleport() verb, we've permanently created new behavior for all mobs and objs. This is called polymorphism. Any instance of /obj or /mob can now use the Teleport() proc and stores a teleport variable. We don't need to define it again to use it more than once. It just always works now that we've defined it.

Now, types are what you are trying to tackle. Path navigation is how we define different types of objects. Let's say we want two teleporters to exist:

turf
teleporter1
Entered(atom/movable/o)
if(ismob(o)&&!o.teleporting)
var/mob/m = o
if(m.client)
m.Teleport(locate(88,195,27))
..()
teleporter2
Entered(atom/movable/o)
if(ismob(o)&&!o.teleporting)
var/mob/m = o
if(m.client)
m.Teleport(locate(32,190,14))
..()


we now have two types that do teleportation:

/turf/teleporter1 and /turf/teleporter2.

They do roughly the same thing, but they take you to different places.

However, this approach isn't actually a very good one because it doesn't take advantage of polymorphism properly. We can make a better system without having to define two different objects:

turf
teleporter
proc
Transport(mob/m)

Entered(atom/movable/o)
if(!o.teleporting&&ismob(o)&&o:client)
Transport(m)
..()


What we've just done is created a teleporter turf that will serve as the base behavior of all of our future teleporters. This is called polymorphism. Let's define some teleporters under our turf/teleporter type:

turf/teleporter
teleporter1
Transport(mob/m)
m.Teleport(locate(32,190,14))
teleporter2
Transport(mob/m)
m.Teleport(locate(16,40,26))


Once again, we're looking pretty similar to the old code. We can make it better though.

proc
getTurf(atom/o)
if(isturf(o)) return o
if(isarea(o)) return locate(o.x,o.y,o.z)
while(o&&!isturf(o))
o = o.loc
return o

turf
teleporter
var
link
link_x;link_y;link_z
proc
Transport(mob/m)
var/turf/t = getTurf(link ? locate(link) : locate(link_x,link_y,link_z)
if(t)
m.Teleport(t)

Entered(atom/movable/o)
if(!o.teleporting&&ismob(o)&&o:client)
Transport(m)
..()


This new approach to teleporters can be set much more flexibly.

turf/teleporter
teleporter1
link_x = 38; link_y = 16; link_z = 14
teleporter2
link_x = 12; link_y = 44; link_z = 6


You can also use strings!

turf/teleporter
teleporter1
link="sam's house"
teleporter2
link="frodo's house"


This method will look for any object with the tag variable set to "sam's house" and teleport the player there.

Also, you don't even have to define the object prototypes in code, you can do it in the map editor by clicking on the teleporter type, right-clicking in the instance box, and selecting "New instance...". You can then edit the link variables manually to dynamically create teleporter links that aren't hard-coded into the game.

This may seem like a lot, but you really should read the guide. It will give you a clearer vision of what you should be learning as you go forward with DM.