ID:139051
 
ignore tabbing, its tabbed correctly in my code....for some reason it wont line up on this post.

stairs
icon='Interior.dmi'
icon_state="stairs"
verb
Climb()
set src in view(1)
usr.loc=locate(183,224,2)
usr << "You Climbed the Stairs!"
stairs2
icon='Interior.dmi'
icon_state="stairs"
verb
//Climb()
// usr.loc=locate(183,224,2)
Descend()
set src in view(1)
usr.loc=locate(183,224,1)


Well i was always told "if you find yourself repeating code, your doing it wrong" - So keeping that in mind, is there a way to alter what i've written up here to just make the player Z level change? when a player is climbing or descending stairs? That way i dont have to code billions of lines of code for every stair...

Yes, actually. I believe Ter taught me the trick a while ago.

    Door
var
Portal // Where you want to go to
ExDir // Extra Direction

Entered(mob/A)
for(var/turf/T in world) // For all turfs in world
if(src.Portal == T.tag) // If the Portal of the current object is the tag of another turf in world
var/turf/O = T // Define O the be the Selected turf
A.loc = locate(O) // Teleport to the new location.
step(A,O.ExDir) // Take an extra step away


Bear in mind you have to modify the tags in the Mapping utility to use this. Make sure the direction is NORTH over "NORTH" when you do it. Check out "tag" in DM as well!

Note that I did not use Move() to the portal. This is because the portal is going to be the other door (in my example) so if I used Move() to go to it, I would call the Entered() of the door and just go back and forth forever!
In response to Lugia319
wouldnt this allow users to choose where they wanted to go?

I wanted set stairs.


Or am i mistaken?
In response to Komuroto
It will not allow users to choose where they wanted to go unless you modified the variables. So long as you only permit 1 tag per door, and you keep them straight, you will only have 1 stair go to 1 other stair.

I can, however, offer you an example in which they could choose where they wanted to go.
In response to Lugia319
na thats fine, thanks.
In response to Komuroto
You could also try doing
usr.z++
I'm at work right now so I can't test this but it may work. or a proc that is called when you enter stairs.

turf/Stairs
Entered(mob/A)
if(A.client)
alert(A,"Walk up or down the stairs?",,"Up","Down")
if("Up")
A.loc=locate(A.x,A.y,A.z++)
if("Down")
A.loc=locate(A.x,A.y,A.z--)

Now obviously this is simple and you will need to change it to suit your needs, but this should work. You could even define 2 types of stairs "StairsUp","StairsDown" and change the Entered() proc as needed. Hell you could use Enter() if you want to (It'll behave slightly differently) But this should give you an idea of what to do. You would have to make the next floor on the Z level above it and make the entrance exactly where the player was standing, but that seemed to be what you wanted anyway.
In response to Kenpachi12
That's way too map reliant. It's better to have tags so you go right to the desired exit.
In response to Lugia319
Of course it's map reliant but it was the way he was doing it above so I tried to make it as close as possible to what he seemed to want


EDIT: What lugia is saying is true however. Tags would be the best way to handle this sort of thing and it'd be good for you to get to know them. You should choose my method if you want it to behave exactly like you have it coded currently but with less hassle of creating new stairs for every building. His way would work slightly differently, but in the end is the better solution.

Better Practice vs Redo Of Bad Practice.
^ You Decide