ID:157234
 
I want the code to check whether or not the obj is in the player's inventory, and if it is, to deny them access. Here's what I have so far.

turf
Passages

The_Safezone
Enter
density = 1

Enter(mob/PC)
for(var/obj/X in contents)
if(istype(X, /obj/Dragonballs/)||istype(X, /obj/Namek_Dragonballs)||istype(X, /obj/Black_Star_Dragonballs))
usr << "You may not enter the SZ with a Dragonball!"
return
else
usr.loc = locate(191,42,3)
usr.density = 1
You want to use the locate() proc for this, since it's not completely necessary to loop through the player's contents.

if(locate(/obj/item) in target)
// do stuff


I also noticed in your code that you're not using Enter() properly. You should be returning ..() at the end of it, otherwise nobody will be able to enter that turf.
In response to Unknown Person
I'm rather new to all this honestly: by target you mean the mob that it's searching?
In response to Aurelius6299
Aurelius6299 wrote:
I'm rather new to all this honestly: by target you mean the mob that it's searching?

In my code, target means whatever's contents (or inventory) you're searching through. So in this case:

mob/verb/check()
if(locate(/obj/apple) in src)
src << "You have an apple"
else
src << "You don't have an apple. :("


This will check if you have an apple (an instance of type /obj/apple) in your inventory.

Also would like to add that this:

if(locate(/obj/apple) in src.contents)


is also an equivalent statement (it means the same thing).
In response to Unknown Person
Alright, now how would I apply that to my situation? What I originally wanted to do was this: The mob enters the passage, get's located to the correct location, while that's happening, it' checks to see if it has a Dragonball in their inventory. If it does, it places that Dragonball at a random point on the map. I did this and got 0 errors yet it just didn't work at all. So I moved to this.
In response to Unknown Person
I sometimes catch myself using:
var/found=0
for(/obj/candy in trgt.contents)
found++
if(found) ..()



I really haven't forgotten all of my bad programming habits.
In response to Unknown Person
Unknown Person wrote:
I also noticed in your code that you're not using Enter() properly. You should be returning 1 at the end of it, otherwise nobody will be able to enter that turf.

0 to deny entry, ..() to allow entry, 1 to force entry.
In response to Garthor
Garthor wrote:
Unknown Person wrote:
I also noticed in your code that you're not using Enter() properly. You should be returning 1 at the end of it, otherwise nobody will be able to enter that turf.

0 to deny entry, ..() to allow entry, 1 to force entry.

Um...it works perfectly as it is, I don't see the problem.
In response to Garthor
Garthor wrote:
Unknown Person wrote:
I also noticed in your code that you're not using Enter() properly. You should be returning 1 at the end of it, otherwise nobody will be able to enter that turf.

0 to deny entry, ..() to allow entry, 1 to force entry.

Whoops, sorry. You're totally right on that one. I've edited my post.
In response to Aurelius6299
Aurelius6299 wrote:
Garthor wrote:
Unknown Person wrote:
I also noticed in your code that you're not using Enter() properly. You should be returning 1 at the end of it, otherwise nobody will be able to enter that turf.

0 to deny entry, ..() to allow entry, 1 to force entry.

Um...it works perfectly as it is, I don't see the problem.

If you return 1, entry will be allowed even if there is already a dense object at the location. return ..() will call the default Enter() proc, which will return 0 if that would happen, and 1 otherwise.
In response to Unknown Person
Unknown Person wrote:
Aurelius6299 wrote:
I'm rather new to all this honestly: by target you mean the mob that it's searching?

In my code, target means whatever's contents (or inventory) you're searching through. So in this case:

> mob/verb/check()
> if(locate(/obj/apple) in src)
> src << "You have an apple"
> else
> src << "You don't have an apple. :("
>

This will check if you have an apple (an instance of type /obj/apple) in your inventory.

Also would like to add that this:

> if(locate(/obj/apple) in src.contents)
>

is also an equivalent statement (it means the same thing).

ok...the target in my code is every player that happens to walk through that door. Now, what I want to do is have the code take that item,if it finds it and deny them access (otherwise skip the 'else' statement)to that passage.

As for the Enter not being used 'properly' I said already that it works fine, drop that part.
In response to Aurelius6299
Aurelius6299 wrote:
As for the Enter not being used 'properly' I said already that it works fine, drop that part.

Nope.

To do what you want, you need to use Enter() properly, like so:

turf/whatever/Enter(var/mob/M)
// Only care about mobs:
if(ismob(M))
if(we don't want to let M enter)
return 0
// By default, allow entry using normal rules:
return ..()