ID:178366
 
I'm trying to make a cook verb where you can cook a fish. I want it so you can only cook fish and not something else. I only want fish to show up on the list (and thus, it always cooks the fish). So I have: Cook(obj/Fish/F in usr.contents) . That's the verb for a fire. But that still lets me cook anything in my inventory. If I add a / before the obj, I get 4 errors. How can I get this to work? Also, if it isn't too hard, I want to know how I can make it a verb on the fish itself, that only appears when you're near an obj/Fire . Can I get some help please? I can't figure it out for myself (I learn best from examples, and I can't find any examples of this.)
have you tried giving the fish the cook verb?
the Cook(obj/fish/F in contents) code isn't telling it to only allow types of obj/fish, it simply telling the proc/verb what type of variable it is expecting. If you want to only allow types of obj/fish, try something like this.

Make a new proc, and we'll call it OnlyFish().
<FONT COLOR=silver>
<code>proc/OnlyFish(list/location)</code>

// location is where it's searching for fish, in this case, usr.contents.
<code> var/list/X = list() for(var/obj/fish/F in location) X += F return X</code></FONT>

That proc will only return items in the specified location that are of type obj/fish. Now, what you want to do is tell the Cook verb to only allow options that the OnlyFish proc spits out, which would only be of type obj/fish. You can do that like this:
<FONT COLOR=silver>
<code>obj/fire/Cook(obj/fish/F in OnlyFish(src.contents))</code></FONT>

// now it should only produce a list of fish in usr.contents.

Does that make sense?

[Edit]

Expanding on that, you could avoid having multiple procs to specifically specify certain item types by having one proc with an argument for which type to you want. Here's an example:
<FONT COLOR=silver>
<code>proc/OnlyType(location,type) var/list/X = list() for(var/atom/I in location) if(I.type == type) X += I return X</code></FONT>

Then you could specify say, only items in usr.contents of type obj/torch like this:
<FONT COLOR=silver>
<code>mob/verb/Light(obj/torch/T in OnlyType(src.contents,/obj/torch))</code></FONT>

Or only objects of type obj/herb in the player's location:
<FONT COLOR=silver>
<code>mob/verb/GetHerb(obj/herb/H in OnlyType(src.loc,/obj/herb))</code></FONT>
In response to Redslash
I would, but I don't know how to set it up so that it appears when you're next to a fire. I tried doing set obj/Fire in oview(1) but it apparently has to be src on the left hand side.
In response to Foomer
I tried that and it didn't work =(. I would really like to know how to make a verb appear on the fish when you are next to the fire. I know I can use a proc to check constantly if you're near one, but is there a better way?
In response to Garthor
Garthor wrote:
I would, but I don't know how to set it up so that it appears when you're next to a fire. I tried doing set obj/Fire in oview(1) but it apparently has to be src on the left hand side.


Try this:

set src in oview(1)

If it dont work it's because im dumb
In response to Garthor
I thought you said the verb belonged to the fire, not the fish?
In response to Charlesisdapimp
Uhmn... I want the verb to appear ON THE FISH when you're near a fire object.
In response to Foomer
It does, but I would prefer if it belonged to the fish so that it wouldn't pick a fish at random (since the same fish object can be slightly different)
In response to Garthor
Oh, then why don't you just add it to the fire and have it pick() from the fish in usr.contents instead :oP