ID:149373
 
barrier
Enter() //when entered..
if(istype(src,/mob/Troll))
return 0 // make it stop
else // if its not
..() //continue
Im tyring to make a turf monsters cant pass. I get these
errors:

loading Valors Lore.dme
Valors Lore.dm:4:error:src:duplicate definition
Valors Lore.dm:4:error:/mob/Troll:duplicate definition
Valors Lore.dm:4:error::empty type name (indentation error?)
Valors Lore.dm:5:error:return 0:instruction not allowed here
Valors Lore.dm:5:error::empty type name (indentation error?)
Ok i fixed lots of the bugs and now it looks like this:
barrier
Enter() //when entered..
if(is type(Valors Lore.dm, mob/NPC))
return 0 // make it stop
else // if its not
..() //continue
and now i get an:
loading Valors Lore.dme
Valors Lore.dm:4:error: type: missing comma ',' or right-paren ')'

Valors Lore.dmb - 5 errors, 0 warnings (double-click on an error to jump to it)

now what?
In response to RayOfAsh
RayOfAsh wrote:
barrier
Enter() //when entered..
if(is type(Valors Lore.dm, mob/NPC))
return 0 // make it stop
else // if its not
..() //continue

Change it to this, see what happens

barrier
Enter() //when entered..
if(istype(src, mob/NPC))
return 0 // make it stop
else // if its not
..() //continue
In response to Polatrite
not funny!!!
In response to RayOfAsh
That's actually the fix you are looking for. You had an indentation error in the original code which Polarite fixed. The corrections in your second post are way off target.
In response to Polatrite
Polatrite wrote:
Change it to this, see what happens

barrier
Enter() //when entered..
if(istype(src, mob/NPC))
return 0 // make it stop
else // if its not
..() //continue

Problem is, that only fixes the compile errors, but not the bugs. And it won't fix all the compile errors anyway, because mob/NPC isn't a valid type path syntax: /mob/NPC is. The slash in front is important when using istype().

But this turf isn't going to work as intended, because RayOfAsh seriously botched his call to Enter() and you repeated the mistake. src is the turf, and so the if() check will never be true, and ..() is called. But the return value of ..() is not returned, so Enter() will return null for this turf no matter who tries to enter, which will then be interpreted as 0 by Move(), which will then call mob.Bump(turf) because it's been blocked. None shall pass.

Enter() takes an argument saying what it is that's trying to enter. Inside this proc, src is the turf--not the obj/mob that's checking if it can enter--and usr could be anything at all and should never be used here. Therefore, ALL Enter() procs should be written in this form:
Enter(atom/movable/A)
.... // do something

Never ever ignore the argument in Enter(), unless you plan to return 0 or 1 no matter what.

Now, to rewrite that code properly, it would look like this:
turf/barrier
Enter(atom/movable/A)
if(istype(A,/mob/NPC))
return 0 // make it stop
return ..() // otherwise continue

Lummox JR
In response to Lummox JR
thx it works now =). but now i need to figure out how to make it so they CAN pass if a PC is in their line of site. Which so far is the whole map but ill fix that soon =).
In response to RayOfAsh
RayOfAsh wrote:
thx it works now =). but now i need to figure out how to make it so they CAN pass if a PC is in their line of site. Which so far is the whole map but ill fix that soon =).

I'm not sure why you'd want to do that, but it sounds like you have something interesting in mind.
What you'd basically do is this:
turf/barrier
Enter(atom/movable/A)
if(istype(A,/mob/NPC))
// here's the new code
for(var/mob/watcher in view(A))
if(other.client) return ..() // a player can see me!
return 0 // make it stop
return ..() // otherwise continue

You'll probably want to use viewers() instead of view(), if what you want is for the NPC to move only when players can see it (which isn't necessarily the same thing as it seeing a player).
This code loops through all mobs in view and if it finds one with a client (i.e., a player), it returns the default value that Enter() normally would. If no players are found, 0 is returned to prevent them from moving.

Lummox JR