ID:143988
 
I'm using the following code for shopping:

Code:
        for(var/mob/I in oview(1))
statpanel("Shop")
stat(I.contents)
canshop=1


While it does work fine, I'm trying to figure out how I would set canshop to 0 if you var/mob/I is not in oview(1). I've tried !oview(1) which doesn't work. Any help would be appreciated.

Whats the canshop var suppose to do?...Also could you post the whole code? xD Lol.
Michael3131 wrote:
I'm using the following code for shopping:

Code:
>       for(var/mob/I in oview(1))
> statpanel("Shop")
> stat(I.contents)
> canshop=1
>

While it does work fine, I'm trying to figure out how I would set canshop to 0 if you var/mob/I is not in oview(1). I've tried !oview(1) which doesn't work. Any help would be appreciated.


        for(var/mob/I in oview(2))
if(I in oview(1)) continue
canshop=0


untested, but you can try it.
In response to Nodvick
I see! I took your code and tweeked it a bit:

        for(var/mob/I in oview(2))
if(I in oview(1))
if(I.isplayer==0)
statpanel("Shop")
// stat("[I.Description]")
stat(I.contents)
canshop=1
else
canshop=0


And it works perfectly now. Thanks!
No no no no NO!

That's a really, really bad way to do things. I mean, if you wanted to be inefficient and all, you could just use locate().

if(locate(/mob/shopkeeper) in oview(1))
//You're next to a shopkeeper


But putting something like that in Stat() is a baaaaaaaaaad idea. Much better to make the shopkeeping panel appear when you click on a shopkeeper, or something like that. And I'd suggest not using a statpanel, too - use a browser windows and Topic(), but that might be a little difficult for you.

This is how I'd handle a statpanel situation with clicking:
mob/shopkeeper/Click()
if(usr in oview(src,1)) //Usr is valid because Click() is a pseudoverb
usr.shopping=src //Set usr's shopping variable to a reference to this mob.

mob
var/mob/shopping //Either null, or a mob that you're shopping at.
var/money //How much money you have
Stat()
//blah blah blah
if(shopping) //If we're shopping with someone
statpanel("Shopping")
stat(shopping.contents) //Give them a statpanel with the shopkeeper's contents

Move()
shopping=null //If the player moves, we want to stop them shopping. I'm assuming shopkeepers don't move.
.=..() //Return the default return value of the procedure.

obj
var/cost //How much the object costs to buy
Click()
if(!(src in usr) && istype(loc, /mob/shopkeeper)) //If we're in a shopkeeper mob and the person clicking on us doesn't have us in our contents
if(usr.shopping==loc) //Sanity check - is usr shopping from our owner?
if(usr.money<cost) return //They don't have enough money. You probably want to inform them of this, but this is a simple example.
usr.money-=cost //Take their money
Move(usr) //And move into their contents


Of course, you'd want to embellish that with messages and confirmation and all that, but it's basically how I'd work it.

DISCLAIMER - I DON'T HAVE A COMPILER ON ME RIGHT NOW. THIS CODE IS NOT TESTED.