ID:1608556
 
(See the best response by LordAndrew.)
Code:
var/map_names[] = list('001.dmm','002.dmm','003.dmm')    //Global list to hold map_names, so we don't have to search the world.

obj/map_name
icon = 'map object.dmi' //This is so you can see the map_name in the mapper
invisibility = 101 //Set to maximum invisibility, so it cannot be seen in game
New(loc, set_tag)
tag = set_tag
spawn(1)
map_names += src
return ..(loc)
Del()
map_names -= src
return ..()

proc/map_Locate(x, y, z_name) //Upgraded locate() that lets you specify a map_name instead of a z level ie. Locate(5,9,"forest")
if(istext(z_name))//Uses a name
var/obj/map_name/O = locate(z_name) in map_names
if(O)
return locate(x, y, O.z)
else
return null
else //Uses old-style number
return locate(x, y, z_name)

proc/map_zname(num) //Returns the name of the z level num
for(var/obj/map_name/O in map_names)
if(O.z == num)
return O.name
return null //This z level is not named!


Problem description: I'm trying to make it so when players enter an object they're teleported to another map.

I'm making a Silent Hill fan-game and would love to have buildings that once players enter they're sent to the interior map.

area
HappyBurger
Enter()
usr.loc = map_Locate(5, 2, "003")


I can't figure out how to get this code to work for me.

Make a new /obj/map_name on each 'map' you want to warp to, like so:

new /obj/map_name(locate(1, 1, 7), "happy burger") // or whatever the z level is 


then call map_Locate(some x value, some y value, "happy burger").

Incidental: Don't use usr in procs, /especially/ movement procs. What do you think usr is if an NPC walks into the area? Also, you should use Entered(), not Enter().

area/HappyBurger
Entered(atom/movable/m)
m.Move(map_Locate(5, 2, "happy burger"))
In response to Jp


Where should I put the code?
> new /obj/map_name(locate(1, 1, 7), "happy burger") // or whatever the z level is
>


buddy i will make u easy
turf/HappyBurger
Entered()
usr.loc=locate(x,y,z)

add this on map where person has to enter and he will go to tht place
at place of xyz enter map location
In response to Tarundbz
Best response
This example is downright wrong in many ways. You should be using Entered() over Enter(), you shouldn't be using usr in Entered(), and you shouldn't be using the verbose locate(x, y, z) form of locate().
In response to LordAndrew
LordAndrew wrote:
This example is downright wrong in many ways. You should be using Entered() over Enter(), you shouldn't be using usr in Entered(), and you shouldn't be using the verbose locate(x, y, z) form of locate().

I've gotten it all sorted out.

In response to LordAndrew
LordAndrew wrote:
This example is downright wrong in many ways. You should be using Entered() over Enter(), you shouldn't be using usr in Entered(), and you shouldn't be using the verbose locate(x, y, z) form of locate().

sire he wanted the usr to switch maps as he enters except of tht i gave him just a simple and easy way
In response to Tarundbz
Tarundbz wrote:
LordAndrew wrote:
This example is downright wrong in many ways. You should be using Entered() over Enter(), you shouldn't be using usr in Entered(), and you shouldn't be using the verbose locate(x, y, z) form of locate().

sire he wanted the usr to switch maps as he enters except of tht i gave him just a simple and easy way


Simple and easy should not be an excuse for knowingly showing bad programming methods.

You could have just summed it up by telling the person to look up Entered().

Just to expand on why that snippet was frowned upon, you must realize that usr is defined in very few instances, typically where the client must do something (ex: Click(), DblClick() are fine as the usr is correctly defined to the client who clicked).

The issue with Move() and it's related movement procedures is that the usr may NOT be correctly defined as it is an indirectly called function (relative to the user invoking something that is).

An instance where this script can/will break is when an NPC or even a /obj managed to enter that tile. As there was no safety check used in the snippet, and assume an /obj did enter, you will get either a runtime or some unfortunate person being suddenly wisped away.

As can be seen in Jp's snippet, usr is not called. Rather any /atom/movable who calls Entered() the turf is Move()d.


And because you modified the loc to the new location rather than Moving the person, none of the Entry/Exit procedures are called which may impact the design of the game later on (which has happened to me before).