ID:147557
 
i want a code so if u enter a turf u r transported to another place and when u leave that plae thru a turf u appear where u left from.

the problem is that u can enter this place from dif locations on the map so i cant just ask it to transport u to a certain place when u leave coz u wouldnt necessarily appear in the place u went in from.

i thought of using a variable that stores ur location just before u enter the turf...

turf
enterplace
icon = 'place.bmp'
Enter()
var/storeloc = locate(usr.x,usr.y,usr.z)
usr.loc=locate(10,2,2)

leaveplace
icon = 'turfs.dmi'
icon_state = "leave"
Enter()
usr.loc = storeloc


but i get an error message saying i havent defined storeloc and i get a warning saying that i have defined storeloc but i havent used it


any help or suggestions?
Oh and it'll be great if u can help me with one more code problem:

obj/Gravitronfour
name = "Gravitron Four"
icon = 'turfs.dmi'
icon_state = "gravity"
density = 1
verb
Gravity()
set category = "Training"
set src in oview(2)
var/howmuch = input("How much Gravity?") as num|null
if(howmuch < 0)
usr << "<b>Thats not possible."
if(howmuch == 1||howmuch == 0)
usr.grav = 0
usr << "<b>You turn off the gravity...."
if(howmuch > 1 && howmuch <= 150000)
if(usr.grav >= 1)
usr << "<b>Please set the gravity to 0."
if(usr.grav == 0||usr.grav == null)
usr << "<b>You hear the machine turn on..."
usr.grav = howmuch
sleep(20)
usr.playergravity()
if(howmuch > 150000)
usr << "<b>the G4 can not take more then 150000X Gravity"

mob
proc
playergravity()
if(usr.grav != 0)
if(usr.move==1)
var/success = rand(1,10)
if(success == 1 || success == 2)
usr << "You feel the gravity pull down on you. You seem stronger."
usr.powerlevel -= usr.grav * (rand(8,20))
if(usr.powerlevel <= 0)
usr.Die()
if(usr.powerlevel >= 1)
usr.maxpowerlevel += usr.grav / (rand(1,50))
usr.maxpowerlevel = round(usr.maxpowerlevel)
spawn(40)
if(usr.grav == 0)
usr.powerlevel += 0
else
usr.playergravity()
if(success == 3 || success == 5)
usr << "You feel yourself getting use to the gravity."
usr.powerlevel -= usr.grav * (rand(8,20))
if(usr.powerlevel <= 0)
usr.Die()
if(usr.powerlevel >= 1)
usr.maxpowerlevel += usr.grav / (rand(1,50))
usr.maxpowerlevel = round(usr.maxpowerlevel)
spawn(40)
if(usr.grav == 0)
usr.powerlevel += 0
else
usr.playergravity()
if(success == 4 || success == 6)
usr << "You feel the full force of the gravity!!"
usr.powerlevel -= usr.grav * (rand(8,20))
if(usr.powerlevel <= 0)
usr.Die()
if(usr.powerlevel >= 1)
usr.maxpowerlevel += usr.grav / (rand(1,50))
usr.maxpowerlevel = round(usr.maxpowerlevel)
spawn(40)
if(usr.grav == 0)
usr.powerlevel += 0
else
usr.playergravity()
if(success == 7 || success == 8 || success == 9 || success == 10 )
usr.playergravity()
else
return
usr.maxpowerlevel += 1
else
return


thats the code i use for gravity from gravitrons. I know this is straight from zeta but i promise i'm not using this for a zeta rip...i just want to learn so i can ake my own original game(non-dbz)...this is just a test project

The problem with that is that u can stand in the same spot and the gravity keeps on working, is there a way to make it so u HAVE to walk around in order for the gravity to work and if u dont then it doesnt have any affect. And it'll be great if u can make it so the effect of the gravitron only works if the gravitron is near u.

Thanks for any help, i need more help with this than the other one btw.
DeathAwaitsU wrote:
i want a code so if u enter a turf u r transported to another place and when u leave that plae thru a turf u appear where u left from.

the problem is that u can enter this place from dif locations on the map so i cant just ask it to transport u to a certain place when u leave coz u wouldnt necessarily appear in the place u went in from.

i thought of using a variable that stores ur location just before u enter the turf...

Ouch...

> turf
> enterplace
> icon = 'place.bmp'
> Enter()
> var/storeloc = locate(usr.x,usr.y,usr.z)
> usr.loc=locate(10,2,2)
>
> leaveplace
> icon = 'turfs.dmi'
> icon_state = "leave"
> Enter()
> usr.loc = storeloc
>

but i get an error message saying i havent defined storeloc and i get a warning saying that i have defined storeloc but i havent used it


As much as it pained me to wade through that, here goes. The reason you are having a problem here, is you are not keeping track of your variables scope. When you declare a variable within a procedure, that variable is only available within that procedure. When you attempt to access the 'storeloc' var within the /turf/leaveplace/Enter() proc, the program can't find a storeloc variable within the current scope, therefore, it gives you the undefined var error.

When you declare the storeloc var within the /turf/enterplace/Enter() proc, but don't use it anywhere within the proc, the compiler gives you the 'defined but didn't use' warning.

You really need to declare this var as a mob var. When a player enters an 'enterplace', set their storeloc var to their current location. When they enter the 'leaveplace', set their loc to the previously saved storeloc.

// Give the mob a 'storeloc' var where you will store
// their previous location.
mob
var
turf/storeloc

// Within the enter/leaveplace's Enter() proc, use the
// provided atom/movable/O var rather than 'usr', to
// prevent Lummox from beating you. :) 'usr' is not
// always going to be what you expect it to be, but
// atom/movable/O will ALWAYS be the atom attempting
// to enter the turf.

// Simply use ismob() to check if the atom entering
// is a mob. If it is, set up a temorary mob var, set
// that var to O, and either set the storeloc var, or
// move them back to storeloc.

turf
enterplace
Enter(atom/movable/O)
if(ismob(O))
var/mob/M = O
M.storeloc = M.loc
M.loc = locate(10,2,2)
..()

leaveplace
Enter(atom/movable/O)
if(ismob(O))
var/mob/M = O
M.loc = M.storeloc
..()
In response to Flick
WOW THX A LOT THAT CODE WORKS LIKE A DREAM

sry bout caps but i'm just sooooo happy...now if only i could get the gravitron done
In response to DeathAwaitsU
DeathAwaitsU wrote:
WOW THX A LOT THAT CODE WORKS LIKE A DREAM

sry bout caps but i'm just sooooo happy...now if only i could get the gravitron done

few words for you, stop ripping zeta code.
In response to XzDoG
"thats the code i use for gravity from gravitrons. I know this is straight from zeta but i promise i'm not using this for a zeta rip...i just want to learn so i can ake my own original game(non-dbz)...this is just a test project"

few wors for you. READ
In response to DeathAwaitsU
how do you rip a game? im a newb coder so plz tell me
In response to LiteSaber09
umm even though you are not supposed to rip... i wanna know too!!
In response to Tabu34
ID:254022 <-- there you go
Your problem is two-fold.

First, you are using usr in a proc. Namely, you're using it in Enter(), which is EXTREMELY wrong.
Second, you are using Enter() when you should be using Entered().