ID:168782
 
In my teleport verb i wanted to make sure it doesnt go past the "Void" turfs but i have no idea how i would look for the Highest X Void and Farthest Y Void. I hope that made sense.
What you could do is..
if(!THING.x)
if(!THING.y)
if(!thing.z)


Im 99% sure this also checks for void boundries.
If you want to make sure you're not landing on a dense turf, you can just do:
if(!Thing)

i believe that would work.
In response to Flame Sage
Im trying to make it teleport you to a random spot aslong as its not Dense but its not working.

mob
verb
Teleport()
var/worldmaxx = 250
var/worldmaxy = 250
var/TeleportX = rand(0,worldmaxx)
var/TeleportY = rand(0,worldmaxy)
var/TeleportZ = src.z
if(!TeleportX && !TeleportY && !TeleportZ)
src.loc = locate(TeleportX,TeleportY,TeleportZ)
In response to Turles9000
Turles9000 wrote:
Im trying to make it teleport you to a random spot aslong as its not Dense but its not working.

> mob
> verb
> Teleport()
> var/worldmaxx = 250
> var/worldmaxy = 250
> var/TeleportX = rand(0,worldmaxx)
> var/TeleportY = rand(0,worldmaxy)
> var/TeleportZ = src.z
> if(!TeleportX && !TeleportY && !TeleportZ)
> src.loc = locate(TeleportX,TeleportY,TeleportZ)
>


Well that's hardly a surprise, since nothing in that code functions correctly. Let's go over the works:

  • You don't need worldmaxx/y vars because you have world.maxx/y.
  • The coordinate you want is from 1 to world.maxx/y, not from 0 up.
  • The !TeleportX/Y/Z checks will do nothing for density; in this case they'll only check if all those vars are 0, which src.z should never be if your mob is already on the map.
  • Nothing in this code is actually checking the resulting turf for density or for the presence of dense mobs/objs.
  • There is no loop, so finding another suitable teleport destination will not be possible.

    Lummox JR
In response to Lummox JR
k i fixed some problems but i have 2 new ones. I used goto and i read earlier thats not the best way to solve a problem. And i dont know how to check if the location is dense.

mob
verb
Teleport()
Start
var/TeleportX = rand(1,world.maxx)
var/TeleportY = rand(1,world.maxy)
var/TeleportZ = src.z
if(!TeleportX && !TeleportY && !TeleportZ)
src.loc = locate(TeleportX,TeleportY,TeleportZ)
else
goto Start
In response to Turles9000
Turles9000 wrote:
k i fixed some problems but i have 2 new ones. I used goto and i read earlier thats not the best way to solve a problem.

Indeed, it's not any way you should be solving your problem. Look up while() instead. What you really need here is a do-while loop. Look up do as well. Never ever use goto unless it's a loop so complex as to defy any other option.

And i dont know how to check if the location is dense.

The density variable would likely have something to do with it.

Lummox JR
In response to Lummox JR
but i cant use .density since i guess variables cant have density??

Spells.dm:62:error:TeleportX.density:undefined var
Spells.dm:62:error:TeleportY.density:undefined var
Spells.dm:62:error:TeleportZ.density:undefined var
In response to Turles9000
maybe....TeleportX.turf.density?
In response to Nukes4U
Loop through the atoms in the location using for(), and if you find a dense atom, use a while() loop to go back and reset the random number generators. Otherwise, you could use a do while loop, but I have no clue how to do so. I'm... explaining my example.
mob/verb/Teleport()
var/start=1
var/TeleX
var/TeleY
var/TeleZ=src.z
var/dens
while(start)
TeleX=rand(1,world.maxx)
TeleY=rand(1,world.maxy)
var/turf/T=locate(TeleX,TeleY,TeleZ)
for(var/atom/A in locate(TeleX,TeleY,TeleZ))
if(A.density) {dens=1;break}
else if(!A.density) {dens=null;continue}
if(T.density) dens=1
if(!dens) {src.loc=locate(TeleX,TeleY,TeleZ);start=null}
else if(dens) {sleep(0.1);continue}

In response to Nukes4U
Nukes4U wrote:
maybe....TeleportX.turf.density?

Ouch. Not even anywhere near correct. Don't just spout random stuff.

Lummox JR
In response to Turles9000
Turles9000 wrote:
but i cant use .density since i guess variables cant have density??

Spells.dm:62:error:TeleportX.density:undefined var
Spells.dm:62:error:TeleportY.density:undefined var
Spells.dm:62:error:TeleportZ.density:undefined var

Well it's not as if you're supposed to check the density of those. Those are numbers; of course they don't have density. I said check the density of the turf.

Now let's see, how would you find the turf? Maybe with that little locate() command that was already in there.

It's important to read over these things in detail, because it could not have been more clear. It sounds like you're just trying to add stuff in more or less arbitrary spots and seeing if it works, without even trying to understand. If you'd been thinking through this code at all, the if() you were using with !TeleportX and so on would never have been used, nor would you have tried to check the density of a number. This code is failing because you're not trying to make it work; you're just throwing stuff at it to see what sticks. Programming doesn't work that way. Read through, follow the flow. Know which var is which and what type of value you can expect it to have.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Nukes4U wrote:
maybe....TeleportX.turf.density?

Ouch. Not even anywhere near correct. Don't just spout random stuff.

Lummox JR

Sorreh, i made that post really late =P
In response to Lummox JR
ive honestly been trying really hard to get this to work. Here's how i think this code works but its teleporting me to the wrong spot.I tried looking up while and do but i dont understand how it works. Here's what i have so far and how i think it works. I Thought i understood this code but since its not working i obviously dont.

mob
verb
Teleport()
Start // Makes a node
var/TeleportX = rand(1,world.maxx) // makes a "TeleportX" var that is random 1 to the maximum of the map's x
var/TeleportY = rand(1,world.maxy) //makes a "TeleportY" var that is random 1 to the maximum of the map's Y
var/TeleportZ = src.z//makes a "TeleportZ" var that is equal to the players Z
var/turf/a = locate(TeleportX,TeleportY,TeleportZ)//makes a var for turfs called a and gives it the location of TeleportX,TeleportY,And TeleportZ vars after finding them.
if(!a.density) // Checks if the turf's location i set earlier is dense or not. If its not then this happens
src.loc = a.loc // Sends the players location to the turfs location
else // if it is dense
goto Start // Goes to the node
In response to Turles9000
Turles9000 wrote:
ive honestly been trying really hard to get this to work. Here's how i think this code works but its teleporting me to the wrong spot.I tried looking up while and do but i dont understand how it works.

Well, using goto is not an acceptable substitute for not understanding while(). In fact, there's no acceptable subsitute at all. You need to learn while(). Do not use goto except in loops so complex that, frankly, you will never encounter them.

Lummox JR